1 #ifndef __DENSE_UNIVARIATE_INTEGER_POLY_CPP_ 2 #define __DENSE_UNIVARIATE_INTEGER_POLY_CPP_ 21 #include "dense_univariate_integer_poly.hpp" 23 using std::cout;
using std::endl;
28 coeffs =
new COEF_TYPE [n];
29 for (DEG_TYPE i = 0; i < n; ++i)
41 for (DEG_TYPE i = 0; i <=
deg; ++i)
46 DEG_TYPE n, int64_t * C
51 for (DEG_TYPE i = 0; i <=
deg; ++i)
57 COEF_TYPE * new_nums =
new COEF_TYPE [n + 1];
58 for (DEG_TYPE i = 0; i <
deg + 1; ++i)
62 for (DEG_TYPE i = deg + 1; i < n + 1; ++i)
69 DEG_TYPE k, COEF_TYPE a
72 if (k >
deg and a != 0) {
deg = k; }
73 else if (k ==
deg and a == 0) {
79 for (DEG_TYPE i = 0; i <=
deg; ++i)
88 for (DEG_TYPE i =
deg; i > 0; --i) {
101 DEG_TYPE n =
deg + q.
deg + 1;
104 COEF_TYPE * new_nums =
new COEF_TYPE [n] { 0 };
108 for (DEG_TYPE i = 0; i <
deg + 1; ++i)
109 for (DEG_TYPE j = 0; j < nq + 1; ++j)
110 if (
coeffs[i] != 0 and b[j] != 0)
111 new_nums[i + j] +=
coeffs[i] * b[j];
119 for (DEG_TYPE i = 0; i <=
deg; ++i)
130 for (DEG_TYPE i = 0; i <= q.
deg; ++i)
void set_coefficient(DEG_TYPE k, COEF_TYPE a)
set the coefficient of to
void negate()
negates the coefficients
void scale_by(COEF_TYPE a)
multiplies every monomial by a constant
void multiply_by_monomial_of_degree(DEG_TYPE)
a hopefully efficient multiplication algorithm
Dense_Univariate_Integer_Polynomial operator-(const Dense_Univariate_Integer_Polynomial &) const
returns the result of subtracting the other from this
Dense_Univariate_Integer_Polynomial(DEG_TYPE)
construct with the number of expected terms
DEG_TYPE deg
degree of the polynomial (largest nonzero exponent)
COEF_TYPE coeff(DEG_TYPE k) const
the th coefficient
void expand_poly(DEG_TYPE)
expand to allow for higher-degree monomials
quick-’n-dirty Dense_Univariate integer polynomial class
void multiply_by(const Dense_Univariate_Integer_Polynomial &)
highly inefficient polynomial multiplication ( )
DEG_TYPE size
number of slots for coefficients
void add(const Dense_Univariate_Integer_Polynomial &q)
reasonably efficient, given our dense representation
DEG_TYPE degree() const
the polynomial’s degree (exponent of largest nonzero term)
COEF_TYPE * coeffs
list of numerators; index 0 is the constant’s