1 #ifndef __POLYNOMIAL_GEOBUCKET_CPP_ 2 #define __POLYNOMIAL_GEOBUCKET_CPP_ 21 #include "polynomial_geobucket.hpp" 68 Geobucket_Iterator::Geobucket_Iterator(
74 for (
unsigned i = 0; i < NUM_BUCKETS; ++i)
75 if (poly->
buckets[i] !=
nullptr)
85 for (
unsigned i = 0; i < NUM_BUCKETS; ++i)
86 if (poly->
buckets[i] !=
nullptr)
91 Geobucket_Iterator::~Geobucket_Iterator() {
113 if (bucket_number < NUM_BUCKETS and g->buckets[
bucket_number] !=
nullptr)
142 for (
unsigned i = 1; i < NUM_BUCKETS; ++i)
152 for (
unsigned i = 1; i < NUM_BUCKETS; ++i)
157 buckets[0] = buckets[i]->detach_head();
162 for (
unsigned i = 0; i < NUM_BUCKETS; ++i)
170 for (
unsigned i = 0; i < NUM_BUCKETS; ++i)
177 for (
unsigned i = 0; i < NUM_BUCKETS; ++i)
191 for (
unsigned i = 0; i < NUM_BUCKETS; ++i)
202 unsigned result =
true;
203 for (
unsigned i = 0; result and i < NUM_BUCKETS; ++i)
218 for (
unsigned j = 1; j < NUM_BUCKETS; ++j)
250 for (
unsigned i = 0; i < NUM_BUCKETS; ++i)
259 for (
unsigned i = 0; i < NUM_BUCKETS; ++i)
274 while (not placed and i < NUM_BUCKETS) {
279 if (m < (BUCKET_BASE << BUCKET_SHIFT * i)) {
299 while (not placed and i < NUM_BUCKETS) {
304 if (m < (BUCKET_BASE << BUCKET_SHIFT * i)) {
323 if (i >= NUM_BUCKETS)
throw(
new runtime_error(
"too large for buckets"));
345 if (i < NUM_BUCKETS) {
351 throw(
new runtime_error(
"too large for buckets"));
367 while (i < NUM_BUCKETS and
buckets[i] !=
nullptr 368 and
buckets[i]->
length() + 1 == BUCKET_BASE << BUCKET_SHIFT * i)
370 if (i >= NUM_BUCKETS)
371 throw(
new runtime_error(
"Buckets are full"));
384 for (
unsigned i = 1; i < NUM_BUCKETS; ++i)
390 if (not constant_result)
404 for (
unsigned i = 0; i < NUM_BUCKETS; ++i)
408 os <<
'(' << *(
buckets[i]) <<
')';
418 for (
unsigned i = 0; i < NUM_BUCKETS; ++i)
422 os <<
'(' << *(p.
buckets[i]) <<
')';
virtual unsigned length() const override
Returns the number of polynomials in the list.
The general class of a polynomial.
~Polynomial_Geobucket()
Deallocates buckets, if they exist.
virtual Prime_Field_Element leading_coefficient() const override
returns the leading coefficient
Implementation of geobuckets.
virtual bool canMoveLeft() const override
const Monomial_Ordering * monomial_ordering() const
reports leading monomial’s monomial ordering
Polynomial_Geobucket(Polynomial_Ring &R, Monomial_Ordering *order=generic_grevlex_ptr)
Initializes a polynomial with the given number of variables, over the given field.
void print(unsigned i, ostream &os=cout) const
prints the th bucket
friend ostream & operator<<(ostream &, const Polynomial_Geobucket &)
prints the geobucket in an explicitly geobucket form
virtual Polynomial_Geobucket & operator+=(const Abstract_Polynomial &g) override
Adds to this. Recomputes leading monomial.
virtual unsigned length() const override
how long is this polynomial?
A Constant_Polynomial is a polynomial that should not change.
virtual Geobucket_Iterator * new_mutable_iterator() override
An iterator that may modify the current position.
LLPolynomial_Iterator * pi
an iterator for the current bucket
virtual void set_currCoeff(const Prime_Field_Element &a) override
change coefficient in current position
virtual void add_last(const Prime_Field_Element &a, const Monomial &t) override
Adds as a monomial of this. (Not necessarily the last!)
virtual void moveLeft() override
Moves the iterator left: to the next larger monomial.
void recompute_leading_monomial()
You will need to call this after every operation that might modify the leading term.
unsigned lglen(unsigned i)
Log-length of , used to select a bucket for a polynomial of length .
virtual Polynomial_Geobucket * monomial_multiple(const Monomial &t) const override
Returns .
Iterator over linked list polynomials.
virtual const Prime_Field_Element & currCoeff() const override
Returns the coefficient of the monomial the iterator currently points to.
virtual Monomial & leading_monomial() const override
returns the leading monomial
virtual bool fellOff() const override
virtual Monomial & leading_monomial() const =0
leading monomial – call after sort_by_order()!
virtual Polynomial_Linked_List * zero_polynomial() const override
creates and returns a geobucket initialized to zero
const Abstract_Polynomial * p
the polynomial this points to
virtual bool canMoveLeft() const override
Can this iterator move left, or would it fall off?
virtual void moveRight() override
Returns the monomial the iterator currently points to.
virtual const Monomial & currMonomial() const override
Reports the monomial at the current position.
Polynomial_Linked_List ** buckets
Array of ptrs to linked list polys; most initialized to nullptr.
virtual bool fellOff() const override
true iff the iterator no longer points to a valid monomial.
virtual Polynomial_Linked_List * detach_head() override
Detaches the head and recomputes leading monomial.
virtual Polynomial_Linked_List * scalar_multiple(const Prime_Field_Element &c) const override
Returns a new polynomial whose value is .
virtual void restart_iteration() override
This should move the iterator to the leading term.
virtual bool canMoveRight() const override
Can this iterator move right, or would it fall off?
virtual Polynomial_Geobucket & operator-=(const Abstract_Polynomial &g) override
Subtracts from this. Recomputes leading monomial.
virtual bool is_zero() const override
true iff the first node in the list is nullptr or has zero coeff
virtual void add_polynomial_multiple(const Prime_Field_Element &b, const Monomial &u, const Abstract_Polynomial &g, bool subtract=false) override
Adds to this. Recomputes leading monomial.
unsigned bucket_number
the bucket number at which we’re stopped
virtual Polynomial_Linked_List * detach_head() override
Detach and return leading term.
virtual void sort_by_order() override
sorts each geobucket
Abstract_Polynomial * canonicalize(bool constant_result=false)
returns a copy of this in a simplified linear form
Polynomials that need arithmetic typically descend from this class.
virtual void set_monomial_ordering(const Monomial_Ordering *order, bool sort_anew=true) override
sets the monomial ordering for each bucket
virtual void moveRight() override
Moves right in the polynomial, to the next smaller monomial.
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 Monomial & leading_monomial() const override
Returns the leading monomial — call sort_by_order() first!
virtual void set_currMonomial(const Monomial &t) override
change monomial in current position
virtual Polynomial_Geobucket * scalar_multiple(const Prime_Field_Element &a) const override
Returns .
virtual const Monomial & currMonomial() const override
Reports the monomial at the current position.
virtual void add_last(const Prime_Field_Element &c, const Monomial &t) override
Add this monomial as the last leading term.
virtual Prime_Field_Element leading_coefficient() const override
Returns the leading coefficient — call sort_by_order first!
virtual bool can_reduce(Abstract_Polynomial &other) const override
Whether this can reduce other. A geobucket should not generally be used to reduce other polynomials...
virtual bool is_zero() const override
is this polynomial zero?
Polynomials represented as a doubly linked list.
Used to iterate through a polynomial.
virtual void add_polynomial_multiple(const Prime_Field_Element &a, const Monomial &t, const Abstract_Polynomial &q, bool subtract) override
"Fast" addition of to this.
virtual void set_currMonomial(const Monomial &t) override
change monomial in current position
virtual bool canMoveRight() const override
Can this iterator move right, or would it fall off?
virtual Polynomial_Linked_List * monomial_multiple(const Monomial &u) const override
Returns a new polynomial whose value is .
Polynomial_Geobucket * g
to save myself the hassle of static_cast<const Polynomial_Geobucket *>(p) every time I turn around ...
virtual Geobucket_Iterator * new_iterator() const override
An iterator that poses no risk of modifying the polynomial.
virtual const Prime_Field_Element & currCoeff() const override
Reports the coefficient at the current position.
Polynomial_Ring & R
data about polynomial ring
virtual unsigned length() const =0
number of monomials
Polynomial_Ring & base_ring() const
ring in which this polynomial resides
virtual void set_currCoeff(const Prime_Field_Element &a) override
change coefficient in current position
Iterates through polynomials using a geobucket representation. See Mutable_Polynomial_Iterator for de...
virtual void moveLeft() override
Moves left in the polynomial, to the next larger monomial.