Class BigVector
- java.lang.Object
-
- com.seedfinding.latticg.math.component.BigVector
-
public final class BigVector extends java.lang.Object
A vector withBigFraction
elements
-
-
Constructor Summary
Constructors Constructor Description BigVector(int dimension)
Constructs the zero vector of the given dimensionBigVector(long... numbers)
Constructs a vector with the given integer elementsBigVector(BigFraction... numbers)
Constructs a vector with the given elements
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BigVector
add(BigVector a)
Adds the given vector to this vector, stores the result in a new vector and returns that vectorBigVector
addAndSet(BigVector a)
Adds the given vector to this vector, modifying this vectorstatic BigVector
basis(int size, int i)
Create a basis vector of length 1.static BigVector
basis(int size, int i, BigFraction scale)
Create a basis vector of the specified length.BigVector
copy()
Creates a copy of this vectorBigVector
divide(BigFraction scalar)
Divides this vector by the given scalar, stores the result in a new vector and returns that vectorBigVector
divideAndSet(BigFraction scalar)
Divides this vector by the given scalar, modifying this vectorBigFraction
dot(BigVector v)
Calculates the dot product of this vector and the given vectorboolean
equals(java.lang.Object other)
static BigVector
fromString(java.lang.String raw)
Parses a string in wolfram-style vector notationBigFraction
get(int i)
Gets the element at the given index in the vectorint
getDimension()
Gets the dimension of the vectorBigFraction
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.int
hashCode()
boolean
isZero()
Returns whether this vector is the zero vectorBigFraction
magnitudeSq()
Returns the square of the magnitude (norm) of this vector.BigVector
multiply(BigFraction scalar)
Multiplies this vector by the given scalar, stores the result in a new vector and returns that vectorBigVector
multiply(BigMatrix m)
Computesthis * m
, interpreting this vector as a row vector, stores the result in a new vector and returns that vectorBigVector
multiply(java.math.BigInteger scalar)
Multiplies this vector by the given scalar, stores the result in a new vector and returns that vectorBigVector
multiplyAndSet(BigFraction scalar)
Multiplies this vector by the given scalar, modifying this vectorBigVector
multiplyAndSet(java.math.BigInteger scalar)
Multiplies this vector by the given scalar, modifying this vectorstatic BigVector
parse(StringParser parser)
Parses a vector from a string parserBigVector
projectOnto(BigVector v)
Calculates the projection of this vector onto the given vector, stores the result in a new vector and returns that vectorvoid
set(int i, BigFraction value)
Sets the element at the given index in the vectorBigVector
shiftElements(int startIndex, int endIndex)
Place the element at endIndex before the one at startIndex and shifts all the elements in betweenBigVector
subtract(BigVector a)
Subtracts the given vector from this vector, stores the result in a new vector and returns that vectorBigVector
subtractAndSet(BigVector a)
Subtracts the given vector from this vector, modifying this vectorBigVector
swapNums(int i, int j)
Swaps the two numbers at the given indices, stores the result in a new vector and returns that matrixBigVector
swapNumsAndSet(int i, int j)
Swaps the two numbers at the given indices, modifying the vectorjava.lang.String
toApproximateString()
java.lang.String
toString()
-
-
-
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
- Ifi
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 indexvalue
- The value to put in that index- Throws:
java.lang.IndexOutOfBoundsException
- Ifi
is out of bounds
-
magnitudeSq
public BigFraction magnitudeSq()
Returns the square of the magnitude (norm) of this vector. Note: there is nomagnitude()
method inBigVector
, 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)
Computesthis * 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 withj
j
- The row to swap withi
- Returns:
- A new vector containing the result
- Throws:
java.lang.IndexOutOfBoundsException
- Ifi
orj
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 swapendIndex
- The ending index to swap- Returns:
- This matrix
- Throws:
java.lang.IllegalArgumentException
- IfstartIndex
is greater thanendIndex
-
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 withj
j
- The row to swap withi
- Returns:
- This vector
- Throws:
java.lang.IndexOutOfBoundsException
- Ifi
orj
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 classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.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 vectori
- 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 vectori
- index of the provided componentscale
- the length of the vector- Returns:
- a basis vector
-
-