1 #ifndef __POLYNOMIAL_ARRAY_CPP_ 2 #define __POLYNOMIAL_ARRAY_CPP_ 21 #include "polynomial_array.hpp" 27 if (at_end)
i =
p->
m - 1;
31 Constant_Polynomial_Iterator::~Constant_Polynomial_Iterator() { }
62 if (order ==
nullptr) {
64 order = generic_grevlex_ptr;
71 for (
unsigned i = 0; i <
m; ++i) {
84 const list<Monomial> & mons,
85 const list<Prime_Field_Element> & coeffs,
89 if (order ==
nullptr) {
90 if (mons.front().monomial_ordering() ==
nullptr)
91 order = generic_grevlex_ptr;
93 order = mons.front().monomial_ordering();
98 auto Mi = mons.begin();
99 auto Ai = coeffs.begin();
101 while (Mi != mons.end()) {
105 if (order != Mi->monomial_ordering())
122 for (
unsigned i = 0; i <
m; ++i) {
141 for (
unsigned i = 0; i <
m; ++i) {
146 M[i].set_exponent(k, AM[j++]);
157 uint64_t * result =
new uint64_t[
m*(n+1)];
159 for (
unsigned i = 0; i <
m; ++i) {
160 result[j++] =
A[i].
value();
161 for (NVAR_TYPE k = 0; k < n; ++k)
162 result[j++] =
M[i][k];
168 Constant_Polynomial::~Constant_Polynomial() {
169 for (
unsigned i =
head; i <
m; ++i)
171 free(
M); free(
A);
M =
nullptr;
A =
nullptr;
177 for (
int i =
head; i <
m; ++i)
186 for (
int i =
head + 1; i <
m; ++i) {
190 for (; j >
head and t >
M[j-1]; --j) {
224 for (
unsigned i =
head; i <
m + 1; ++i)
233 for (
unsigned i =
head; i <
m; ++i)
274 Mutable_Constant_Polynomial_Iterator::~Mutable_Constant_Polynomial_Iterator() { }
283 return i < p->head or i >= p->m;
The general class of a polynomial.
virtual void restart_iteration() override
This should move the iterator to the leading term.
virtual bool canMoveLeft() const override
virtual bool fellOff() const override
Monomial * M
array of monomials, in one-to-one correspondence with A
const Monomial_Ordering * monomial_ordering() const
reports leading monomial’s monomial ordering
virtual void moveLeft() override
Moves left in the polynomial, to the next larger monomial.
virtual Prime_Field & ground_field() const
ground field
Constant_Polynomial_Iterator(const Constant_Polynomial *q, bool at_end=false)
Creates an iterator for poly and starts at the leading term.
A Constant_Polynomial is a polynomial that should not change.
virtual const Monomial & currMonomial() const override
Reports the monomial at the current position.
virtual Polynomial_Iterator * new_iterator() const =0
An iterator that poses no risk of modifying the polynomial.
virtual void moveRight()=0
Moves right in the polynomial, to the next smaller monomial.
bool is_zero() const
Is this the additive identity?
virtual Prime_Field_Element leading_coefficient() const override
Constant_Polynomial(unsigned length, Polynomial_Ring &R, const Monomial *mons, const Prime_Field_Element *coeffs, const Monomial_Ordering *order=nullptr)
virtual void set_currCoeff(const Prime_Field_Element &a) override
change coefficient in current position
virtual const Prime_Field_Element & currCoeff() const =0
Reports the coefficient at the current position.
virtual void moveRight() override
Moves right in the polynomial, to the next smaller monomial.
virtual bool fellOff() const override
Information necessary for a field modulo a prime.
virtual Polynomial_Iterator * begin() const override
iterator to the first element
void set_monomial_ordering(const Monomial_Ordering *mord)
sets the Monomial_Ordering associated with this Monomial
virtual const Monomial & currMonomial() const override
Reports the monomial at the current position.
const Constant_Polynomial * p
the polynomial we iterate on
virtual Constant_Polynomial * zero_polynomial() const override
uint64_t * serialized(uint64_t &size)
Prime_Field_Element * A
array of coefficients, in one-to-one correspondence with M
virtual Polynomial_Iterator * end() const override
iterator to the last element
virtual Constant_Polynomial * monomial_multiple(const Monomial &t) const override
friend class Constant_Polynomial_Iterator
to iterate without changing this
virtual void moveRight() override
Moves right in the polynomial, to the next smaller monomial.
virtual const Prime_Field_Element & currCoeff() const override
Reports the coefficient at the current position.
virtual const Prime_Field_Element & currCoeff() const override
Reports the coefficient at the current position.
NVAR_TYPE num_vars() const
number of variables
virtual void set_currMonomial(const Monomial &t) override
change monomial in current position
virtual bool fellOff() const =0
virtual Monomial & leading_monomial() const override
virtual void sort_by_order() override
sort by order
Implementation of monomials.
Element of a field of prime characteristic.
interface to a monomial ordering
unsigned number_of_variables() const
number of variables – all monomials should agree with this (though it is never tested by the class) ...
Encapsulates information about a polynomial ring for easy access: ground field, number of indetermina...
virtual bool canMoveRight() const override
Can this iterator move right, or would it fall off?
void initialize_exponents(NVAR_TYPE number_of_vars)
allocates memory for exponents This is useful when you want to allocate an array of monomials...
Iterates through a Constant_Polynomial.
virtual Constant_Polynomial_Iterator * new_iterator() const override
an iterator that poses no risk of modifying the polynomial
virtual void set_monomial_ordering(const Monomial_Ordering *order, bool sort_anew=true) override
sets the ordering of monomials in this polynomial
const Monomial_Ordering * monomial_ordering() const
the Monomial_Ordering associated with this Monomial
long i
current position in p’s array
Used to iterate through a polynomial.
virtual void restart_iteration() override
This should move the iterator to the leading term.
virtual const Monomial & currMonomial() const =0
Reports the monomial at the current position.
virtual Constant_Polynomial * scalar_multiple(const Prime_Field_Element &c) const override
virtual void moveLeft() override
Moves left in the polynomial, to the next larger monomial.
virtual unsigned length() const override
COEF_TYPE value() const
The value of the element. This always satisfies .
Polynomial_Ring & R
data about polynomial ring
Mutable_Constant_Polynomial_Iterator(Constant_Polynomial *poly)
Creates an iterator for poly and starts at its leading term.
unsigned m
position after last monomial
virtual unsigned length() const =0
number of monomials
void assign(COEF_TYPE val, Prime_Field *K)
for initializing arrays of Prime_Field_Element
Polynomial_Ring & base_ring() const
ring in which this polynomial resides
virtual bool is_zero() const override
unsigned head
location of leading term in array (always farther left)
void common_initialization(const Monomial_Ordering *ord=nullptr)
things all Monomial initializers must do