1 #ifndef __POLYNOMIAL_H_ 2 #define __POLYNOMIAL_H_ 4 #include <initializer_list> 5 using std::initializer_list;
16 typedef int32_t DEGREE_TYPE;
69 DEGREE_TYPE
degree()
const;
71 const R &
coeff(DEGREE_TYPE)
const;
96 virtual bool is_one()
const override;
97 virtual bool is_zero()
const override;
117 for (
unsigned i = 0; i <=
deg; ++i)
123 : deg(list.size() - 1), coeffs(deg + 1)
126 for (
auto c : list) {
138 for (
auto c : list) {
148 for (i =
deg; i > 0 and
coeffs[i].is_zero(); --i) { }
162 for (DEGREE_TYPE i = 0; i <=
deg; ++i)
175 for (DEGREE_TYPE i = 0; i <=
deg; ++i) {
178 for (DEGREE_TYPE j = 0; j <=
deg; ++j)
181 result = result + term;
198 for (DEGREE_TYPE i = 0; i <
deg; ++i)
207 bool result =
deg == other.deg;
208 for (DEGREE_TYPE i = 0; result and i <
deg; ++i)
209 result =
coeffs[i] == other.coeffs[i];
216 bool result =
deg == other.deg;
217 for (DEGREE_TYPE i = 0; result and i <
deg; ++i)
218 result =
coeffs[i] == other.coeffs[i];
245 for (DEGREE_TYPE i = 0; i <
deg and not result; ++i)
263 for ( ; i <=
degree(); ++i)
265 for ( ; i <= other.
degree(); ++i)
284 for ( ; i <=
degree(); ++i)
286 for ( ; i <= other.
degree(); ++i)
301 for (DEGREE_TYPE i = 0; i <=
degree(); ++i)
302 for (DEGREE_TYPE j = 0; j <= other.
degree(); ++j)
318 for (
unsigned i = 0; i <= other.
deg; ++i)
358 ostream & operator << (ostream & os, const Polynomial<R> & p) {
360 for (DEGREE_TYPE d = p.degree(); d > 0; --d) {
361 if (not p.coeff(d).is_zero()) {
362 if (first) first =
false;
366 if (not p.coeff(d).is_one()) os << p.
coeff(d) <<
" ";
372 if (p.degree() == 0 or not p.coeff(0).is_zero()) {
373 if (not first) os <<
" + ";
379 template <
typename R>
381 template <
typename R>
383 template <
typename R>
vector< R > coeffs
polynomial’s coefficients
Definition: polynomial.hpp:29
const R & coeff(DEGREE_TYPE) const
returns the coefficient at the specified degree
Definition: polynomial.hpp:170
elements of this type should have commutative multiplication
Definition: rings.hpp:39
void set_coeff(DEGREE_TYPE, const R &)
sets the value of the coefficient at the given degree
Definition: polynomial.hpp:188
virtual bool is_cancellable() const override
should be True iff element can cancel across an equation; e.g., .
Definition: polynomial.hpp:243
void verify_degree()
verifies that the leading coefficient is zero; if not, decreases degree until either it is or the deg...
Definition: polynomial.hpp:146
Polynomial()
generates a zero polynomial
Definition: polynomial.hpp:108
static Polynomial< R > last_divisor
storage for previously used divisor
Definition: polynomial.hpp:32
const R & operator()(const R &) const
computes the value of the polynomial at the given point
Definition: polynomial.hpp:173
void set_degree(DEGREE_TYPE)
sets the degree to the specified value and resizes if necessary
Definition: polynomial.hpp:153
Definition: integer.hpp:6
virtual Polynomial< R > & operator*(const Ring_Element &) const override
multiplicationL other element should be of same type, use a cast
Definition: polynomial.hpp:293
virtual bool is_zero() const override
should be True iff element is additive identity
Definition: polynomial.hpp:233
virtual bool operator==(const Ring_Element &) const override
comparison: other element has same value
Definition: polynomial.hpp:205
static Polynomial< R > last_remainder
storage for previously computed remainder
Definition: polynomial.hpp:36
void clear_coeffs()
sets all coefficients to zero
Definition: polynomial.hpp:160
virtual bool operator!=(const Ring_Element &) const override
comparison: other element has different value
Definition: polynomial.hpp:214
DEGREE_TYPE degree() const
indicates the polynomial's degree
Definition: polynomial.hpp:167
virtual bool has_inverse() const override
should be True iff element has a multiplicative inverse
Definition: polynomial.hpp:238
const Polynomial< R > & operator=(const Ring_Element &)
assignment operator may be needed
Definition: polynomial.hpp:193
a class for elements with the capabilities of ring arithmetic
Definition: rings.hpp:9
static Polynomial< R > last_quotient
storage for previously computed quotient
Definition: polynomial.hpp:34
const Polynomial< R > & operator/(const Polynomial< R > &) const
quotient from dividing this by the given divisor
Definition: polynomial.hpp:326
virtual Polynomial< R > & operator+(const Ring_Element &) const override
addition: other element should be of same type, use a cast
Definition: polynomial.hpp:251
virtual bool is_one() const override
should be True iff element is multiplicative identity
Definition: polynomial.hpp:228
virtual Polynomial< R > & operator-(const Ring_Element &) const override
subtraction: other element should be of same type, use a cast
Definition: polynomial.hpp:272
const Polynomial< R > & operator%(const Polynomial< R > &) const
remainder from dividing this by the given divisor
Definition: polynomial.hpp:340
void common_division(const Polynomial< R > &) const
utility function that obtains both divisor and remainder from division
Definition: polynomial.hpp:309
a dense univariate polynomial, templated according to the coefficient’s type
Definition: polynomial.hpp:24
DEGREE_TYPE deg
polynomial’s degree
Definition: polynomial.hpp:28