Gröbner basis project
Codebase for research into Gröbner basis computation
dense_univariate_rational_poly_old.hpp
1 #ifndef __DENSE_UNIVARIATE_RATIONAL_POLY_HPP_
2 #define __DENSE_UNIVARIATE_RATIONAL_POLY_HPP_
3 
4 #include <iostream>
5 
6 #include "system_constants.hpp"
7 
8 using std::ostream; using std::cout; using std::endl;
9 
21 public:
23 
29  );
31  Dense_Univariate_Rational_Polynomial(DEG_TYPE, int64_t *, uint64_t *);
33 
36  delete [] numerators;
37  delete [] denominators;
38  }
40 
41 
47  void expand_poly(DEG_TYPE);
49  void set_coefficient(DEG_TYPE k, COEF_TYPE a, UCOEF_TYPE b) {
50  expand_poly(k);
51  numerators[k] = a;
52  denominators[k] = b;
53  if (k > deg and a != 0) { deg = k; }
54  else if (k == deg and a == 0) {
55  while (deg > 0 and numerators[deg] == 0) { --deg; }
56  }
57  }
61  void scale_by(COEF_TYPE a);
67  void scale_by(COEF_TYPE a, UCOEF_TYPE b);
73  void multiply_by_monomial_of_degree(DEG_TYPE);
79  void negate();
83  void operator +=(const Dense_Univariate_Rational_Polynomial & other) { add(other); }
91 
92 
97 
98 
100  bool is_zero() const {
101  bool nonzero = true;
102  for (DEG_TYPE i = 0; nonzero and i <= deg; ++i)
103  nonzero = (numerators[i] == 0);
104  return nonzero;
105  }
107  COEF_TYPE numerator(DEG_TYPE k) const { return numerators[k]; }
109  UCOEF_TYPE denominator(DEG_TYPE k) const { return denominators[k]; }
111  DEG_TYPE degree() const { return deg; }
113  const COEF_TYPE * numerator_array() { return numerators; }
115  const UCOEF_TYPE * denominator_array() { return denominators; }
117 
118  friend ostream & operator<<(
120  ostream & os, Dense_Univariate_Rational_Polynomial & p
121  ) {
122  if (p.numerators[p.deg] < 0) { os << '-'; }
123  for (DEG_TYPE i = p.deg; i > 0; --i) {
124  if (p.numerators[i] != 0) {
125  if (p.numerators[i] == 1) {
126  if (p.denominators[i] != 1) {
127  os << "1 / " << p.denominators[i];
128  }
129  } else if (p.numerators[i] == -1) {
130  if (p.denominators[i] != 1) {
131  os << "1 / " << p.denominators[i];
132  }
133  } else {
134  if (p.numerators[i] > 0) { os << p.numerators[i]; }
135  else { os << -p.numerators[i]; }
136  if (p.denominators[i] != 1) { os << " / " << p.denominators[i]; }
137  }
138  if (i != 1) { os << "t^" << i; }
139  else { os << "t"; }
140  }
141  if (p.numerators[i - 1] < 0) { os << " - "; }
142  else if (p.numerators[i - 1] > 0) { os << " + "; }
143  }
144  if (p.numerators[0] != 0) {
145  if (p.numerators[0] > 0) { os << p.numerators[0]; }
146  else if (p.numerators[0] < 0) { os << -p.numerators[0]; }
147  if (p.denominators[0] != 1) { os << " / " << p.denominators[0]; }
148  }
149  return os;
150  }
152 protected:
154  COEF_TYPE * numerators;
156  UCOEF_TYPE * denominators;
158  DEG_TYPE deg;
160  DEG_TYPE size;
161 };
162 
163 #endif
UCOEF_TYPE denominator(DEG_TYPE k) const
returns the th denominator
COEF_TYPE * numerators
list of numerators; 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 add(const Dense_Univariate_Rational_Polynomial &)
adds other to this
void set_coefficient(DEG_TYPE k, COEF_TYPE a, UCOEF_TYPE b)
set the coefficient of to
COEF_TYPE numerator(DEG_TYPE k) const
returns the th numerator
const COEF_TYPE * numerator_array()
all the numerators
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
DEG_TYPE degree() const
returns the polynomial’s degree
const UCOEF_TYPE * denominator_array()
all the denominators
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