1 #ifndef __DENSE_UNIVARIATE_RATIONAL_POLY_CPP_ 2 #define __DENSE_UNIVARIATE_RATIONAL_POLY_CPP_ 21 #include "dense_univariate_rational_poly.hpp" 23 template <
typename T,
typename U>
25 T c = (a < 0) ? -a : a;
40 coeffs =
new MPQCOEF_TYPE [n];
41 for (DEG_TYPE i = 0; i < n; ++i)
53 for (DEG_TYPE i = 0; i <
size; ++i)
58 DEG_TYPE n, int64_t * nums, uint64_t * denoms
63 for (DEG_TYPE i = 0; i <=
deg; ++i)
64 coeffs[i] =
long(nums[i]) / (
unsigned long)(denoms[i]);
69 MPQCOEF_TYPE * new_coeffs =
new MPQCOEF_TYPE [n + 1];
70 for (DEG_TYPE i = 0; i <
deg + 1; ++i)
74 for (DEG_TYPE i = deg + 1; i < n + 1; ++i)
81 for (DEG_TYPE i = 0; i <=
deg; ++i)
87 for (DEG_TYPE i = 0; i <=
deg; ++i)
93 COEF_TYPE a, UCOEF_TYPE b
95 for (DEG_TYPE i = 0; i <=
deg; ++i)
98 coeffs[i] /= (
unsigned long)b;
106 for (DEG_TYPE i =
deg; i > 0; --i) {
119 DEG_TYPE n =
deg + q.
deg + 1;
121 MPQCOEF_TYPE * new_coeffs =
new MPQCOEF_TYPE [n];
122 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) {
136 for (DEG_TYPE i = 0; i <=
deg; ++i)
147 for (DEG_TYPE i = 0; i <= q.
deg; ++i)
152 while (i > 0 and
coeffs[i] == 0)
164 for (DEG_TYPE i = 0; i <= q.
deg; ++i)
169 while (i > 0 and
coeffs[i] == 0)
189 while (i < other.
degree()) {
MPQCOEF_TYPE * coeffs
list of coefficients; index 0 is the constant’s
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
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