Gröbner basis project
Codebase for research into Gröbner basis computation
dense_univariate_integer_poly.hpp
1 #ifndef __DENSE_UNIVARIATE_INTEGER_POLY_HPP_
2 #define __DENSE_UNIVARIATE_INTEGER_POLY_HPP_
3 
4 /*****************************************************************************\
5 * This file is part of DynGB. *
6 * *
7 * DynGB is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * Foobar is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with DynGB. If not, see <http://www.gnu.org/licenses/>. *
19 \*****************************************************************************/
20 
21 #include <iostream>
22 
23 #include "system_constants.hpp"
24 
25 using std::ostream;
26 
38 public:
40 
46  );
48  Dense_Univariate_Integer_Polynomial(DEG_TYPE, int64_t *);
50 
54 
55 
61  void expand_poly(DEG_TYPE);
63  void set_coefficient(DEG_TYPE k, COEF_TYPE a);
67  void scale_by(COEF_TYPE a);
73  void multiply_by_monomial_of_degree(DEG_TYPE);
79  void negate();
92  ) {
93  add(q);
94  return *this;
95  }
97 
98 
102  ) const;
104 
105 
107  COEF_TYPE coeff(DEG_TYPE k) const { return coeffs[k]; }
109  COEF_TYPE operator[](DEG_TYPE k) const { return coeffs[k]; }
111  DEG_TYPE degree() const { return deg; }
113  bool is_zero() const {
114  bool result = true;
115  for (DEG_TYPE i = 0; result and i <= deg; ++i)
116  result = (coeffs[i] == 0);
117  return result;
118  }
120  const COEF_TYPE * coefficient_array() { return coeffs; }
122 
123  friend ostream & operator<<(
125  ostream & os, const Dense_Univariate_Integer_Polynomial & p
126  ) {
127  if (p.coeffs[p.deg] < 0) { os << '-'; }
128  for (DEG_TYPE i = p.deg; i > 0; --i) {
129  if (p.coeffs[i] != 0) {
130  if (p.coeffs[i] != 1 and p.coeffs[i] != -1) {
131  if (p.coeffs[i] > 0) { os << p.coeffs[i]; }
132  else { os << -p.coeffs[i]; }
133  }
134  if (i != 1) { os << "t^" << i; }
135  else { os << "t"; }
136  }
137  if (p.coeffs[i - 1] < 0) { os << " - "; }
138  else if (p.coeffs[i - 1] > 0) { os << " + "; }
139  }
140  if (p.coeffs[0] != 0) {
141  if (p.coeffs[0] > 0) { os << p.coeffs[0]; }
142  else if (p.coeffs[0] < 0) { os << -p.coeffs[0]; }
143  }
144  return os;
145  }
147 protected:
149  COEF_TYPE * coeffs;
151  DEG_TYPE deg;
153  DEG_TYPE size;
154 };
155 
156 #endif
void set_coefficient(DEG_TYPE k, COEF_TYPE a)
set the coefficient of to
COEF_TYPE operator[](DEG_TYPE k) const
synonym for coeff(k)
void scale_by(COEF_TYPE a)
multiplies every monomial by a constant
const COEF_TYPE * coefficient_array()
all the coefficients
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
Dense_Univariate_Integer_Polynomial & operator+=(const Dense_Univariate_Integer_Polynomial &q)
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
bool is_zero() const
returns True if and only if every valid coefficient is zero