Interface Poly

All Superinterfaces:
Iterable<Poly.Term>
All Known Implementing Classes:
AbstractPoly, DensePoly, SparsePoly

public interface Poly extends Iterable<Poly.Term>
Polys are immutable polynomials with integer coefficients.

A typical Poly is \( p = c_0 + c_1 x + c_2 x^2 + \cdots + c_n x^n \).

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final record 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    add(Poly q)
    Performs polynomial addition.
    default int
    coeff(int degree)
    Returns the coefficient of the term of given exponent.
    int
    Returns the degree of this polynomial.
    Returns the negated polynomial.
    mul(Poly q)
    Performs polynomial multiplication.
    default Poly
    sub(Poly q)
    Performs polynomial subtraction.

    Methods inherited from interface java.lang.Iterable

    forEach, iterator, spliterator
  • Method Details

    • degree

      int degree()
      Returns the degree of this polynomial.
      Returns:
      the largest exponent with a non-zero coefficient; returns 0 if this is the zero Poly.
    • minus

      Poly minus()
      Returns the negated polynomial.

      If \( p \) is this polynomial, returns \( -p \).

      Returns:
      this polynomial multiplied by \( -1 \).
    • add

      Poly add(Poly q)
      Performs 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 - if q is null.
    • sub

      default Poly sub(Poly q)
      Performs polynomial subtraction.

      If \( p \) is this polynomial, returns \( p - q \).

      Parameters:
      q - the polynomial to subtract from this one.
      Returns:
      the subtraction among this and the given polynomial.
      Throws:
      NullPointerException - if q is null.
    • mul

      Poly mul(Poly q)
      Performs 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 - if q is null.
    • coeff

      default int coeff(int degree)
      Returns the coefficient of the term of given exponent.
      Parameters:
      degree - the exponent of the term to consider.
      Returns:
      the coefficient of the considered term.