1 #ifndef __POLYNOMIAL_LINKED_LIST_ 2 #define __POLYNOMIAL_LINKED_LIST_ 21 #include "polynomial_linked_list.hpp" 31 void * Monomial_Node::operator
new(
size_t size) {
37 void Monomial_Node::operator
delete(
void *t) {
54 return iter_curr !=
nullptr and iter_curr->next !=
nullptr;
58 return iter_curr !=
nullptr and iter_curr->prev !=
nullptr;
72 if (!
fellOff()) iter_curr->c = a;
85 if (at_end and iter_curr !=
nullptr)
86 while (iter_curr->next !=
nullptr)
87 iter_curr = iter_curr->next;
95 if (at_end and iter_curr !=
nullptr)
96 while (iter_curr->next !=
nullptr)
97 iter_curr = iter_curr->next;
118 if (order ==
nullptr) {
120 order = generic_grevlex_ptr;
136 if (order ==
nullptr) {
138 order = generic_grevlex_ptr;
153 if (order ==
nullptr) {
155 order = generic_grevlex_ptr;
160 if (node !=
nullptr) {
173 while (other_curr !=
nullptr) {
175 if (
head ==
nullptr)
head = curr = next;
182 other_curr = other_curr->
next;
184 curr->
next =
nullptr;
193 if (curr ==
nullptr) {
195 curr->
prev =
nullptr;
205 curr->
next =
nullptr;
209 while (
head !=
nullptr) {
236 curr->t.set_monomial_ordering(ord);
273 and (
p !=
nullptr and !(
p->c.
is_zero()));
276 DEG_TYPE a =
p->t.ordering_degree();
280 if (
p->prev !=
nullptr)
p->prev->next = r;
294 if (
p->prev !=
nullptr)
p->prev->next = r;
295 if (r !=
nullptr) r->prev =
p->prev;
305 if (
p->prev !=
nullptr)
p->prev->next = r;
314 if (!oi->fellOff() and !(oi->currCoeff().is_zero())) {
315 if (
head ==
nullptr) {
321 while (p->
next !=
nullptr) p = p->
next;
322 while (!oi->fellOff() and !(oi->currCoeff().is_zero())) {
342 and (
p !=
nullptr and !(
p->c.
is_zero()));
349 if (
p->prev !=
nullptr)
p->prev->next = r;
350 if (r !=
nullptr) r->
prev =
p->prev;
361 if (
p->prev !=
nullptr)
p->prev->next = r;
369 if (!oi->fellOff() and !(oi->currCoeff().is_zero())) {
370 if (
head ==
nullptr) {
376 while (p->
next !=
nullptr) p = p->
next;
377 while (!oi->fellOff() and !(oi->currCoeff().is_zero())) {
400 curr !=
nullptr and !(curr->c.is_zero()) and
405 if (subtract) curr->c -= a * oi->
currCoeff();
407 if ((curr->c).is_zero()) {
408 if (curr->prev !=
nullptr) curr->prev->next = curr->next;
409 if (curr->next !=
nullptr) curr->next->prev = curr->prev;
418 }
else if (curr->t.larger_than_multiple(oi->
currMonomial(), t)) {
422 if (subtract) c = -c;
430 if (curr->prev !=
nullptr) curr->
prev->
next = new_node;
432 curr->
prev = new_node;
433 new_node->
next = curr;
440 if (
head ==
nullptr) {
448 while (curr->
next !=
nullptr) curr = curr->
next;
460 curr->
next =
nullptr;
470 while (curr->t > curr->prev->t) {
473 if (tmp !=
nullptr) tmp->
prev = curr->
prev;
500 if (
head !=
nullptr) {
512 if (
head ==
nullptr) {
517 while (tail !=
nullptr and tail->
next !=
nullptr) { tail = tail->
next; }
virtual unsigned length() const override
Returns the number of polynomials in the list.
The general class of a polynomial.
virtual LLPolynomial_Iterator * new_mutable_iterator() override
An iterator that may modify the current position.
virtual bool is_zero() const =0
is this polynomial zero?
special memory pool allocator for Grevlex_Order_Data and WGrevlex_Order_Data
const Monomial_Ordering * monomial_ordering() const
reports leading monomial’s monomial ordering
virtual Prime_Field & ground_field() const
ground field
virtual Polynomial_Iterator * new_iterator() const =0
An iterator that poses no risk of modifying the polynomial.
Monomial_Node(const Prime_Field_Element &a, const Monomial &u)
Monomial u with coefficient a. Both are copied, and can be deleted.
virtual void moveRight()=0
Moves right in the polynomial, to the next smaller monomial.
Prime_Field_Element & coefficient()
This term’s coefficient.
virtual void restart_iteration() override
Initializes at the leading monomial.
LLPolynomial_Iterator * pi
an iterator for the current bucket
Tool for Polynomial_Linked_List.
Monomial t
the monomial in this node
virtual ~Polynomial_Linked_List()
deletes all monomial nodes
bool is_zero() const
Is this the additive identity?
virtual const Prime_Field_Element & currCoeff() const =0
Reports the coefficient at the current position.
virtual Polynomial_Linked_List & operator-=(const Abstract_Polynomial &other) override
Subtracts other from this, and returns the result.
Iterator over linked list polynomials.
virtual const Prime_Field_Element & currCoeff() const override
Returns the coefficient of the monomial the iterator currently points to.
DEG_TYPE ordering_degree() const
returns the ordering degree for this Monomial
Monomial_Node * next
for linking
TYPE * get_new_block()
allocates and returns a block of memory
Information necessary for a field modulo a prime.
virtual bool fellOff() const override
void set_monomial_ordering(const Monomial_Ordering *mord)
sets the Monomial_Ordering associated with this Monomial
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 const Monomial & currMonomial() const override
Reports the monomial at the current position.
virtual void set_monomial_ordering(const Monomial_Ordering *ord, bool sort_anew=true) override
set the monomial ordering and sort the polynomials (optionally, but by default)
virtual bool fellOff() const override
true iff the iterator no longer points to a valid monomial.
virtual Polynomial_Linked_List * scalar_multiple(const Prime_Field_Element &c) const override
Returns a new polynomial whose value is .
virtual bool canMoveRight() const override
Can this iterator move right, or would it fall off?
Monomial_Node * head
first monomial in the list, returned by leading_monomial()
virtual bool is_zero() const override
true iff the first node in the list is nullptr or has zero coeff
virtual Polynomial_Iterator * begin() const override
an iterator that poses no risk of modifying the polynomial
virtual Polynomial_Linked_List * detach_head() override
Detach and return leading term.
virtual bool fellOff() const =0
Polynomials that need arithmetic typically descend from this class.
Monomial_Node * prev
for linking
Implementation of monomials.
Element of a field of prime characteristic.
interface to a monomial ordering
friend class LLPolynomial_Iterator
to iterate over this and possibly change it
virtual Polynomial_Linked_List & operator+=(const Abstract_Polynomial &other) override
Adds other to this, and returns the result.
Polynomial_Linked_List(Polynomial_Ring &R, const Monomial_Ordering *order=generic_grevlex_ptr)
initialize to zero
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 Polynomial_Iterator * end() const override
an iterator that poses no risk of modifying the polynomial
virtual void add_last(const Prime_Field_Element &c, const Monomial &t) override
Add this monomial as the last leading term.
Monomial & monomial()
This term’s monomial, or power product. The coefficient is not included.
virtual Prime_Field_Element leading_coefficient() const override
Returns the leading coefficient — call sort_by_order first!
const Monomial_Ordering * monomial_ordering() const
the Monomial_Ordering associated with this Monomial
virtual Polynomial_Linked_List * zero_polynomial() const override
Returns as simple a zero polynomial as I can muster, short of this being nullptr. ...
Polynomials represented as a doubly linked list.
Used to iterate through a polynomial.
void return_used_block(TYPE *freed_block)
returns a block of memory that is no longer needed to the pool
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 const Monomial & currMonomial() const =0
Reports the monomial at the current position.
virtual Polynomial_Linked_List * monomial_multiple(const Monomial &u) const override
Returns a new polynomial whose value is .
virtual LLPolynomial_Iterator * new_iterator() const override
an iterator that poses no risk of modifying the polynomial
Grading_Order_Data_Allocator< Monomial_Node > * monododa
memory manager for Monomial_Node
Prime_Field_Element c
the monomial’s coefficient
Polynomial_Ring & R
data about polynomial ring
Polynomial_Ring & base_ring() const
ring in which this polynomial resides
LLPolynomial_Iterator(Polynomial_Linked_List *poly, bool at_end=false)
Initializes at the leading monomial.
virtual void set_currCoeff(const Prime_Field_Element &a) override
change coefficient in current position
virtual void sort_by_order() override
Sort by specified weight order.