Rings for MAT 685
Mathematical ring implementation to demonstrate templates and inheritance
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Related Functions | List of all members
Rings::Polynomial< R > Class Template Reference

a dense univariate polynomial, templated according to the coefficient’s type More...

#include <polynomial.hpp>

Inheritance diagram for Rings::Polynomial< R >:
Rings::Commutative_Ring_Element Rings::Ring_Element

Public Member Functions

 Polynomial ()
 generates a zero polynomial
 
 Polynomial (const Polynomial< R > &)
 copies the coefficients of the given polynomial to this one
 
 Polynomial (const initializer_list< R > &)
 initializes coefficients to the ones listed, constant term first
 
 Polynomial (const vector< R > &)
 initializes coefficients to the ones listed, constant term first
 
DEGREE_TYPE degree () const
 indicates the polynomial's degree
 
const R & coeff (DEGREE_TYPE) const
 returns the coefficient at the specified degree
 
const R & operator() (const R &) const
 computes the value of the polynomial at the given point
 
void set_coeff (DEGREE_TYPE, const R &)
 sets the value of the coefficient at the given degree
 
const Polynomial< R > & operator= (const Ring_Element &)
 assignment operator may be needed
 
virtual bool operator== (const Ring_Element &) const override
 comparison: other element has same value
 
virtual bool operator!= (const Ring_Element &) const override
 comparison: other element has different value
 
bool operator== (const R &) const
 returns true if and only if this is constant and has the same value as the given constant/scalar
 
const Polynomial< R > & operator/ (const Polynomial< R > &) const
 quotient from dividing this by the given divisor
 
const Polynomial< R > & operator% (const Polynomial< R > &) const
 remainder from dividing this by the given divisor
 
virtual bool is_one () const override
 should be True iff element is multiplicative identity
 
virtual bool is_zero () const override
 should be True iff element is additive identity
 
virtual bool has_inverse () const override
 should be True iff element has a multiplicative inverse
 
virtual bool is_cancellable () const override
 should be True iff element can cancel across an equation; e.g., \(ax=ay\Rightarrow x=y\).
 
virtual Polynomial< R > & operator+ (const Ring_Element &) const override
 addition: other element should be of same type, use a cast
 
virtual Polynomial< R > & operator- (const Ring_Element &) const override
 subtraction: other element should be of same type, use a cast
 
virtual Polynomial< R > & operator* (const Ring_Element &) const override
 multiplicationL other element should be of same type, use a cast
 
- Public Member Functions inherited from Rings::Commutative_Ring_Element
virtual bool is_commutative () const override
 Duh.
 

Protected Member Functions

void clear_coeffs ()
 sets all coefficients to zero
 
void set_degree (DEGREE_TYPE)
 sets the degree to the specified value and resizes if necessary
 
void verify_degree ()
 verifies that the leading coefficient is zero; if not, decreases degree until either it is or the degree is zero
 
void common_division (const Polynomial< R > &) const
 utility function that obtains both divisor and remainder from division
 

Protected Attributes

DEGREE_TYPE deg
 polynomial’s degree
 
vector< R > coeffs
 polynomial’s coefficients
 

Static Protected Attributes

static Polynomial< R > last_divisor
 storage for previously used divisor
 
static Polynomial< R > last_quotient
 storage for previously computed quotient
 
static Polynomial< R > last_remainder
 storage for previously computed remainder
 

Related Functions

(Note that these are not member functions.)

template<typename R >
ostream & operator<< (ostream &os, const Polynomial< R > &p)
 prints a polynomial in customary fashion
 

Detailed Description

template<typename R>
class Rings::Polynomial< R >

a dense univariate polynomial, templated according to the coefficient’s type

The coefficient should descend from Ring_Element.

Examples:
test_polynomial.cpp.

The documentation for this class was generated from the following file: