Class SparsePoly
Polys.-
Nested Class Summary
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateSparsePoly(List<Poly.Term> terms) Initializes this to be the polynomial with given terms and degree. -
Method Summary
Modifier and TypeMethodDescriptionPerforms polynomial addition.private static voidAdds a term to the list.static SparsePolyCopies the polynomial.static SparsePolycopyOf(SparsePoly poly) Copies the sparse polynomial.private static intfindByDegree(List<Poly.Term> terms, int degree) Finds the index of a term of given degree.iterator()minus()Returns the negated polynomial.Performs polynomial multiplication.static PolyofCoefficientDegree(int c, int n) Creates the polynomial \(p = cx^n\).static PolyCreates a polynomial given its terms.static PolyCreates a polynomial given a list of terms.Methods inherited from interface Iterable
forEach, spliteratorMethods inherited from interface Poly
coefficient, sub
-
Field Details
-
terms
-
-
Constructor Details
-
SparsePoly
-
-
Method Details
-
copyOf
Copies the sparse polynomial.- Parameters:
poly- the polynomial to copy.- Returns:
- the copy of the polynomial.
- Throws:
NullPointerException- ifpolyisnull.
-
copyOf
Copies the polynomial.- Parameters:
poly- the polynomial to copy.- Returns:
- the copy of the polynomial.
- Throws:
NullPointerException- ifpolyisnull.
-
ofTerms
Creates a polynomial given a list of terms.The list of terms can be empty, and can contain terms in any order (even with the same degree). Terms with the same degree are added and, if the resulting list is empty, the zero polynomial is returned.
- Parameters:
terms- the list of terms.- Returns:
- the polynomial.
- Throws:
NullPointerException- iftermsis or containsnull.
-
ofTerms
Creates a polynomial given its terms.The array of terms can be empty, and can contain terms in any order (even with the same degree). Terms with the same degree are added and, if the resulting list is empty, the zero polynomial is returned.
- Parameters:
terms- the array of terms.- Returns:
- the polynomial.
- Throws:
NullPointerException- iftermsis or containsnull.
-
ofCoefficientDegree
Creates the polynomial \(p = cx^n\).The coefficient can be zero, resulting in the zero polynomial.
- Parameters:
c- the coefficient.n- the degree.- Returns:
- the polynomial \( p = cx^n \).
- Throws:
IllegalArgumentException- ifn< 0.
-
findByDegree
-
addTerm
Adds a term to the list.The list will remain in increasing degree order, in case a term with the same degree was present, the two will be summed (and removed if the coefficient will become 0).
- Parameters:
terms- a notnulllist of terms in increasing degree order.term- the term.
-
add
Description copied from interface:PolyPerforms polynomial addition.If \( p \) is this polynomial, returns \( p + q \).
- Parameters:
q- the polynomial to add to this one.- Returns:
- the sum among this and the given polynomial.
- Throws:
NullPointerException- ifqisnull.
-
mul
Description copied from interface:PolyPerforms polynomial multiplication.If \( p \) is this polynomial, returns \( p q \).
- Parameters:
q- the polynomial to multiply by this one.- Returns:
- the product among this and the given polynomial.
- Throws:
NullPointerException- ifqisnull.
-
minus
Description copied from interface:PolyReturns the negated polynomial.If \( p \) is this polynomial, returns \( -p \).
- Returns:
- this polynomial multiplied by \( -1 \).
-
iterator
-