1 #ifndef __DENSE_UNIVARIATE_RATIONAL_POLY_CPP_ 2 #define __DENSE_UNIVARIATE_RATIONAL_POLY_CPP_ 4 #include "dense_univariate_rational_poly.hpp" 6 template <
typename T,
typename U>
8 T c = (a < 0) ? -a : a;
25 for (DEG_TYPE i = 0; i < n; ++i) {
41 for (; i <=
deg; ++i) {
45 for (; i <
size; ++i) {
52 DEG_TYPE n, int64_t * nums, uint64_t * denoms
58 for (DEG_TYPE i = 0; i <=
deg; ++i) {
66 COEF_TYPE * new_nums =
new COEF_TYPE [n + 1];
67 UCOEF_TYPE * new_dens =
new UCOEF_TYPE [n + 1];
68 for (DEG_TYPE i = 0; i <
deg + 1; ++i) {
76 for (DEG_TYPE i = deg + 1; i < n + 1; ++i) {
85 for (DEG_TYPE i = 0; i <=
deg; ++i)
91 COEF_TYPE a, UCOEF_TYPE b
93 for (DEG_TYPE i = 0; i <=
deg; ++i)
103 for (DEG_TYPE i =
deg; i > 0; --i) {
116 DEG_TYPE n =
deg + q.
deg + 1;
118 COEF_TYPE * new_nums =
new COEF_TYPE [n];
119 UCOEF_TYPE * new_dens =
new UCOEF_TYPE [n];
120 for (DEG_TYPE i = 0; i < n; ++i) {
124 for (DEG_TYPE i = 0; i <
deg + 1; ++i)
125 for (DEG_TYPE j = 0; j < q.
deg + 1; ++j) {
129 new_nums[i + j] = new_nums[i + j] * new_b + new_dens[i + j] * new_a;
130 new_dens[i + j] *= new_b;
131 divide_by_common_term<COEF_TYPE, UCOEF_TYPE>(new_nums[i + j], new_dens[i + j]);
136 numerators = new_nums;
143 for (DEG_TYPE i = 0; i <=
deg; ++i)
151 DEG_TYPE new_deg = (deg > q.
deg) ? deg : q.
deg;
154 for (DEG_TYPE i = 0; i <= q.
deg; ++i) {
174 DEG_TYPE new_deg = (deg > q.
deg) ? deg : q.
deg;
177 for (DEG_TYPE i = 0; i <= q.
deg; ++i) {
197 DEG_TYPE m = (deg < other.
degree()) ? deg : other.
degree();
198 DEG_TYPE n = (deg > other.
degree()) ? deg : other.
degree();
202 result.set_coefficient(i,
212 while (i < other.
degree()) {
COEF_TYPE * numerators
list of numerators; index 0 is the constant’s
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
DEG_TYPE size
number of slots for coefficients
void multiply_by(const Dense_Univariate_Rational_Polynomial &)
highly inefficient polynomial multiplication ( )
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
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
void divide_by_common_term(COEF_TYPE &, UCOEF_TYPE &)
divides out the common term of the two given numbers
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
UCOEF_TYPE * denominators
list of denominators; index 0 is the constant’s