Class BigVector


  • public final class BigVector
    extends java.lang.Object
    A vector with BigFraction elements
    • Constructor Summary

      Constructors 
      Constructor Description
      BigVector​(int dimension)
      Constructs the zero vector of the given dimension
      BigVector​(long... numbers)
      Constructs a vector with the given integer elements
      BigVector​(BigFraction... numbers)
      Constructs a vector with the given elements
    • Field Detail

      • LOG_TABLE

        public static final BigVector LOG_TABLE
    • Constructor Detail

      • BigVector

        public BigVector​(int dimension)
        Constructs the zero vector of the given dimension
        Parameters:
        dimension - The dimension of the vector to create
      • BigVector

        public BigVector​(long... numbers)
        Constructs a vector with the given integer elements
        Parameters:
        numbers - The elements of the vector
      • BigVector

        public BigVector​(BigFraction... numbers)
        Constructs a vector with the given elements
        Parameters:
        numbers - The elements of the vector
    • Method Detail

      • getDimension

        public int getDimension()
        Gets the dimension of the vector
        Returns:
        The dimension of the vector
      • get

        public BigFraction get​(int i)
        Gets the element at the given index in the vector
        Parameters:
        i - The index
        Returns:
        The element at the given index
        Throws:
        java.lang.IndexOutOfBoundsException - If i is out of bounds
      • set

        public void set​(int i,
                        BigFraction value)
        Sets the element at the given index in the vector
        Parameters:
        i - The index
        value - The value to put in that index
        Throws:
        java.lang.IndexOutOfBoundsException - If i is out of bounds
      • magnitudeSq

        public BigFraction magnitudeSq()
        Returns the square of the magnitude (norm) of this vector. Note: there is no magnitude() method in BigVector, as that can result in an irrational number. If the un-squared magnitude is desired, the caller should convert the result to a decimal and square root it themselves.
        Returns:
        The square of the magnitude of this vector
      • isZero

        public boolean isZero()
        Returns whether this vector is the zero vector
        Returns:
        Whether this vector is the zero vector
      • add

        public BigVector add​(BigVector a)
        Adds the given vector to this vector, stores the result in a new vector and returns that vector
        Parameters:
        a - The vector to add
        Returns:
        A new vector containing the result
        Throws:
        java.lang.IllegalArgumentException - If the dimension of the given vector is not the same as the dimension of this vector
      • subtract

        public BigVector subtract​(BigVector a)
        Subtracts the given vector from this vector, stores the result in a new vector and returns that vector
        Parameters:
        a - The vector to subtract
        Returns:
        A new vector containing the result
        Throws:
        java.lang.IllegalArgumentException - If the dimension of the given vector is not the same as the dimension of this vector
      • multiply

        public BigVector multiply​(BigFraction scalar)
        Multiplies this vector by the given scalar, stores the result in a new vector and returns that vector
        Parameters:
        scalar - The scalar to multiply by
        Returns:
        A new vector containing the result
      • multiply

        public BigVector multiply​(java.math.BigInteger scalar)
        Multiplies this vector by the given scalar, stores the result in a new vector and returns that vector
        Parameters:
        scalar - The scalar to multiply by
        Returns:
        A new vector containing the result
      • multiply

        public BigVector multiply​(BigMatrix m)
        Computes this * m, interpreting this vector as a row vector, stores the result in a new vector and returns that vector
        Parameters:
        m - The matrix to right-multiply by
        Returns:
        A new vector containing the result
        Throws:
        java.lang.IllegalArgumentException - If the dimension of this vector is not equal to the number of rows in the given matrix
      • divide

        public BigVector divide​(BigFraction scalar)
        Divides this vector by the given scalar, stores the result in a new vector and returns that vector
        Parameters:
        scalar - The scalar to divide by
        Returns:
        A new vector containing the result
      • swapNums

        public BigVector swapNums​(int i,
                                  int j)
        Swaps the two numbers at the given indices, stores the result in a new vector and returns that matrix
        Parameters:
        i - The row to swap with j
        j - The row to swap with i
        Returns:
        A new vector containing the result
        Throws:
        java.lang.IndexOutOfBoundsException - If i or j is out of bounds
      • addAndSet

        public BigVector addAndSet​(BigVector a)
        Adds the given vector to this vector, modifying this vector
        Parameters:
        a - The vector to add to this vector
        Returns:
        This vector
        Throws:
        java.lang.IllegalArgumentException - If the dimension of the given vector is not the same as the dimension of this vector
      • subtractAndSet

        public BigVector subtractAndSet​(BigVector a)
        Subtracts the given vector from this vector, modifying this vector
        Parameters:
        a - The vector to subtract from this vector
        Returns:
        This vector
        Throws:
        java.lang.IllegalArgumentException - If the dimension of the given vector is not the same as the dimension of this vector
      • shiftElements

        public BigVector shiftElements​(int startIndex,
                                       int endIndex)
        Place the element at endIndex before the one at startIndex and shifts all the elements in between
        Parameters:
        startIndex - The starting index to swap
        endIndex - The ending index to swap
        Returns:
        This matrix
        Throws:
        java.lang.IllegalArgumentException - If startIndex is greater than endIndex
      • multiplyAndSet

        public BigVector multiplyAndSet​(BigFraction scalar)
        Multiplies this vector by the given scalar, modifying this vector
        Parameters:
        scalar - The scalar to multiply this vector by
        Returns:
        This vector
      • multiplyAndSet

        public BigVector multiplyAndSet​(java.math.BigInteger scalar)
        Multiplies this vector by the given scalar, modifying this vector
        Parameters:
        scalar - The scalar to multiply this vector by
        Returns:
        This vector
      • divideAndSet

        public BigVector divideAndSet​(BigFraction scalar)
        Divides this vector by the given scalar, modifying this vector
        Parameters:
        scalar - The scalar to divide this vector by
        Returns:
        This vector
      • swapNumsAndSet

        public BigVector swapNumsAndSet​(int i,
                                        int j)
        Swaps the two numbers at the given indices, modifying the vector
        Parameters:
        i - The row to swap with j
        j - The row to swap with i
        Returns:
        This vector
        Throws:
        java.lang.IndexOutOfBoundsException - If i or j is out of bounds
      • dot

        public BigFraction dot​(BigVector v)
        Calculates the dot product of this vector and the given vector
        Parameters:
        v - The vector to find the dot product with
        Returns:
        The dot product of this vector and the given vector
        Throws:
        java.lang.IllegalArgumentException - If the dimension of the given vector is not the same as the dimension of this vector
      • gramSchmidtCoefficient

        public BigFraction gramSchmidtCoefficient​(BigVector v)
        Returns the Gram-Schmidt coefficient when this vector is projected onto the given vector, that is, the ratio of the length of the projection of this vector onto the given vector, to the given vector's length. In other words, multiplying the given vector by the Gram-Schmidt coefficient gives the projection of this vector onto the given vector
        Parameters:
        v - The vector to project onto
        Returns:
        The Gram-Schmidt coefficient when this vector is projected onto the given vector
        Throws:
        java.lang.IllegalArgumentException - If the dimension of the given vector is not the same as the dimension of this vector
      • projectOnto

        public BigVector projectOnto​(BigVector v)
        Calculates the projection of this vector onto the given vector, stores the result in a new vector and returns that vector
        Parameters:
        v - The vector to project onto
        Returns:
        A new vector containing the result
        Throws:
        java.lang.IllegalArgumentException - If the dimension of the given vector is not the same as the dimension of this vector
      • copy

        public BigVector copy()
        Creates a copy of this vector
        Returns:
        A copy of this vector
      • hashCode

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

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toApproximateString

        public java.lang.String toApproximateString()
      • fromString

        public static BigVector fromString​(java.lang.String raw)
        Parses a string in wolfram-style vector notation
        Parameters:
        raw - The string in wolfram-style vector notation
        Returns:
        The parsed vector
        Throws:
        ParseException - If the input is malformed
      • parse

        public static BigVector parse​(StringParser parser)
        Parses a vector from a string parser
        Parameters:
        parser - The parser to parse the vector from
        Returns:
        The parsed vector
        Throws:
        ParseException - If the input is malformed
      • basis

        public static BigVector basis​(int size,
                                      int i)
        Create a basis vector of length 1.
        Parameters:
        size - dimension of the vector
        i - index of the 1
        Returns:
        a basis vector
      • basis

        public static BigVector basis​(int size,
                                      int i,
                                      BigFraction scale)
        Create a basis vector of the specified length.
        Parameters:
        size - dimension of the vector
        i - index of the provided component
        scale - the length of the vector
        Returns:
        a basis vector