1 #ifndef __DENSE_UNIVARIATE_RATIONAL_POLY_HPP_ 2 #define __DENSE_UNIVARIATE_RATIONAL_POLY_HPP_ 23 #include "system_constants.hpp" 25 using std::ostream;
using std::cout;
using std::endl;
71 if (k >
deg and a != 0) {
deg = k; }
72 else if (k ==
deg and a == 0) {
85 void scale_by(COEF_TYPE a, UCOEF_TYPE b);
124 for (DEG_TYPE i = 0; nonzero and i <=
deg; ++i)
125 nonzero = (
coeffs[i] == 0);
136 friend ostream & operator<<(
141 for (DEG_TYPE i = p.
deg; i > 0; --i) {
142 if (p.
coeffs[i].get_num() != 0) {
143 if (p.
coeffs[i].get_num() == 1) {
144 if (p.
coeffs[i].get_den() != 1) {
145 os <<
"1 / " << p.
coeffs[i].get_den();
147 }
else if (p.
coeffs[i].get_num() == -1) {
148 if (p.
coeffs[i].get_den() != 1) {
149 os <<
"1 / " << p.
coeffs[i].get_den();
152 if (p.
coeffs[i].get_num() > 0) { os << p.
coeffs[i].get_num(); }
153 else { os << -p.
coeffs[i].get_num(); }
154 if (p.
coeffs[i].get_den() != 1) { os <<
" / " << p.
coeffs[i].get_den(); }
156 if (i != 1) { os <<
"t^" << i; }
159 if (p.
coeffs[i - 1].get_num() < 0) { os <<
" - "; }
160 else if (p.
coeffs[i - 1].get_num() > 0) { os <<
" + "; }
162 if (p.
coeffs[0].get_num() != 0) {
163 if (p.
coeffs[0].get_num() > 0) { os << p.
coeffs[0].get_num(); }
164 else if (p.
coeffs[0].get_num() < 0) { os << -p.
coeffs[0].get_num(); }
165 if (p.
coeffs[0].get_den() != 1) { os <<
" / " << p.
coeffs[0].get_den(); }
MPZCOEF_TYPE numerator(DEG_TYPE k) const
returns the th numerator
void set_coefficient(DEG_TYPE k, long a, unsigned long b)
set the coefficient of to
MPQCOEF_TYPE * coeffs
list of coefficients; index 0 is the constant’s
DEG_TYPE size
number of slots for coefficients
bool is_zero() const
indicates whether the polynomial is zero
void multiply_by(const Dense_Univariate_Rational_Polynomial &)
highly inefficient polynomial multiplication ( )
void operator-=(const Dense_Univariate_Rational_Polynomial &other)
alias for subtract()
void negate()
negates the numerators
void add(const Dense_Univariate_Rational_Polynomial &)
adds other to this
void expand_poly(DEG_TYPE)
expand to allow for higher-degree monomials
void subtract(const Dense_Univariate_Rational_Polynomial &)
subtracts other from this
void multiply_by_monomial_of_degree(DEG_TYPE)
a hopefully efficient multiplication algorithm
void operator+=(const Dense_Univariate_Rational_Polynomial &other)
alias for add()
DEG_TYPE deg
degree of the polynomial (largest nonzero exponent)
void scale_by(COEF_TYPE a)
multiplies every monomial by a constant integer
quick-’n-dirty Dense_Univariate rational polynomial class
MPZCOEF_TYPE denominator(DEG_TYPE k) const
returns the th denominator
DEG_TYPE degree() const
returns the polynomial’s degree
Dense_Univariate_Rational_Polynomial(DEG_TYPE)
construct with the number of expected terms
Dense_Univariate_Rational_Polynomial operator-(const Dense_Univariate_Rational_Polynomial &) const
returns the difference between this and the other