Gröbner basis project
Codebase for research into Gröbner basis computation
Double_Buffered_Polynomial Class Reference

Polynomials implemented using double buffers.A double-buffered polynomial maintains at all times two arrays to store its terms. (Technically, it retains four arrays: two for the monomials, and two for the coefficients.) Any operation that might change the length of the polynomials reads the data in one buffer and writes the result to the other buffer. The goal of this approach is to avoid the penalties associated with allocating, deallocating, and traversing the nodes of a linked list. More...

#include <polynomial_double_buffered.hpp>

Inheritance diagram for Double_Buffered_Polynomial:
Mutable_Polynomial Abstract_Polynomial

Public Member Functions

Construction
 Double_Buffered_Polynomial (Polynomial_Ring &R, Monomial_Ordering *order=generic_grevlex_ptr)
 
 Double_Buffered_Polynomial (Abstract_Polynomial const &p)
 
Destruction
 ~Double_Buffered_Polynomial ()
 
Basic properties
virtual Monomialleading_monomial () const
 leading monomial – call after sort_by_order()!
 
virtual Prime_Field_Element leading_coefficient () const
 leading coefficient – call after sort_by_order()!
 
virtual unsigned length () const
 number of monomials
 
virtual bool is_zero () const
 is this polynomial zero?
 
virtual bool can_reduce (Abstract_Polynomial &other) const
 can this reduce other?
 
virtual Double_Buffered_Polynomialzero_polynomial () const
 zero polynomial of this type
 
virtual void set_monomial_ordering (Monomial_Ordering *order, bool sort_anew=true)
 set the monomial ordering and sort the polynomials (optionally, but by default) More...
 
Computation
virtual Double_Buffered_Polynomialmonomial_multiple (const Monomial &t) const
 multiple of this and u
 
virtual Double_Buffered_Polynomialscalar_multiple (const Prime_Field_Element &c) const
 multiple of this and c
 
virtual Mutable_Polynomialoperator+= (const Abstract_Polynomial &p)
 add another polynomial
 
virtual Mutable_Polynomialoperator-= (const Abstract_Polynomial &p)
 subtract another polynomial
 
virtual void add_polynomial_multiple (const Prime_Field_Element &a, const Monomial &u, const Abstract_Polynomial &p, bool subtract)
 add monomial multiple of other
 
virtual void sort_by_order ()
 sort according to the leading monomial’s ordering More...
 
Iteration
virtual DB_Polynomial_Iteratornew_iterator () const
 An iterator that poses no risk of modifying the polynomial.
 
virtual DB_Polynomial_Iteratornew_mutable_iterator ()
 An iterator that may modify the current position.
 
virtual Polynomial_Iteratorbegin () const
 
virtual Polynomial_Iteratorend () const
 
Modification
virtual void add_last (const Prime_Field_Element &a, const Monomial &t)
 Attach a new monomial to the tail – check that it belongs at tail!
 
virtual Polynomial_Linked_Listdetach_head ()
 Remove and return the head.
 
- Public Member Functions inherited from Mutable_Polynomial
 Mutable_Polynomial (Polynomial_Ring &R, Monomial_Ordering *ordering=generic_grevlex_ptr)
 constructor
 
virtual ~Mutable_Polynomial ()=0
 destructor
 
virtual void multiply_by_scalar (const Prime_Field_Element &a)
 multiply by scalar
 
virtual void multiply_by_monomial (const Monomial &t)
 multiply by monomial
 
virtual void reduce_by (const Abstract_Polynomial &p)
 reduce by \(p\) until no further reduction possible
 
- Public Member Functions inherited from Abstract_Polynomial
 Abstract_Polynomial (Polynomial_Ring &ring, Monomial_Ordering *ordering)
 
virtual ~Abstract_Polynomial ()
 
Polynomial_Ringbase_ring () const
 ring in which this polynomial resides
 
Prime_Fieldground_field ()
 ground field – all coefficients should be in this field
 
unsigned number_of_variables () const
 number of variables – all monomials should agree with this (though it is never tested by the class)
 
Monomial_Orderingmonomial_ordering () const
 reports leading monomial’s monomial ordering
 
virtual Poly_Strategy_Datastrategy () const
 strategy related information
 
virtual DEG_TYPE standard_degree () const
 maximum sum of exponents for any monomial
 
virtual DEG_TYPE weighted_degree (const WT_TYPE *w=nullptr) const
 weighted sum of exponents for any monomial More...
 
void set_strategy (Poly_Strategy_Data *psd)
 sets the polynomial’s strategy to psd
 
virtual void print (ostream &os=cout) const
 
virtual void println (ostream &os=cout) const
 
virtual void printlncout () const
 

Protected Member Functions

Buffering
bool test_buffer (unsigned b, unsigned n)
 true iff buffer b has space to hold n elements; expand other buffer if not.
 
void expand_buffer (unsigned b, unsigned n)
 Expand buffer b to hold \( 2n \) elements. More...
 

Friends

class DB_Polynomial_Iterator
 

Additional Inherited Members

- Protected Attributes inherited from Abstract_Polynomial
Polynomial_RingR
 data about polynomial ring
 
Poly_Strategy_Datastrat = nullptr
 data for computational strategies
 

Detailed Description

Polynomials implemented using double buffers.

A double-buffered polynomial maintains at all times two arrays to store its terms. (Technically, it retains four arrays: two for the monomials, and two for the coefficients.) Any operation that might change the length of the polynomials reads the data in one buffer and writes the result to the other buffer. The goal of this approach is to avoid the penalties associated with allocating, deallocating, and traversing the nodes of a linked list.

Author
John Perry
Date
2015

Definition at line 93 of file polynomial_double_buffered.hpp.

Member Function Documentation

◆ expand_buffer()

void Double_Buffered_Polynomial::expand_buffer ( unsigned  b,
unsigned  n 
)
inlineprotected

Expand buffer b to hold \( 2n \) elements.

This does not test to see if the space is already available.

Definition at line 196 of file polynomial_double_buffered.hpp.

◆ set_monomial_ordering()

void Double_Buffered_Polynomial::set_monomial_ordering ( Monomial_Ordering order,
bool  sort_anew = true 
)
virtual

set the monomial ordering and sort the polynomials (optionally, but by default)

Warning
In most cases you will want to sort anew immediately after setting the ordering. Otherwise, the monomials may be in the wrong order! That is therefore the default behavior of this function, but in case you don’t want to sort, that option is provided.

Implements Abstract_Polynomial.

Definition at line 128 of file polynomial_double_buffered.cpp.

◆ sort_by_order()

void Double_Buffered_Polynomial::sort_by_order ( )
virtual

sort according to the leading monomial’s ordering

Note that it makes sense to sort even Constant_Polynomial’s, as it is not the polynomial that changes, only the order of its monomials.

Implements Abstract_Polynomial.

Definition at line 329 of file polynomial_double_buffered.cpp.


The documentation for this class was generated from the following files: