Gröbner basis project
Codebase for research into Gröbner basis computation
polynomial_geobucket.hpp
1 #ifndef __POLYNOMIAL_GEOBUCKET_H_
2 #define __POLYNOMIAL_GEOBUCKET_H_
3 
4 /*****************************************************************************\
5 * This file is part of DynGB. *
6 * *
7 * DynGB is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * Foobar is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with DynGB. If not, see <http://www.gnu.org/licenses/>. *
19 \*****************************************************************************/
20 
21 #include <cstdlib>
22 #include <iostream>
23 #include <stdexcept>
24 
25 using std::cout; using std::endl;
26 using std::runtime_error;
27 
28 #include "fields.hpp"
29 #include "monomial.hpp"
30 #include "polynomial.hpp"
31 #include "polynomial_array.hpp"
32 #include "polynomial_linked_list.hpp"
33 #include "polynomial_ring.hpp"
34 
35 extern Monomial_Ordering * generic_grevlex_ptr;
36 
37 #define NUM_BUCKETS 32
38 #define BUCKET_BASE 4
39 #define BUCKET_SHIFT 2
40 
41 // forward declaration
43 
59 public:
61  Geobucket_Iterator(const Polynomial_Geobucket *, bool at_end = false);
63  Geobucket_Iterator(Polynomial_Geobucket *, bool at_end = false);
65 
69 
70  virtual void restart_iteration() override;
72  virtual void moveRight() override;
73  virtual void moveLeft() override;
74  virtual bool canMoveRight() const override;
75  virtual bool canMoveLeft() const override;
76  virtual bool fellOff() const override;
78 
79  virtual const Monomial & currMonomial() const override;
81  virtual const Prime_Field_Element & currCoeff() const override;
83 
84  virtual void set_currCoeff(const Prime_Field_Element & a) override;
86  virtual void set_currMonomial(const Monomial & t) override;
88 protected:
95  unsigned bucket_number;
98 };
99 
115 public:
117 
123  Monomial_Ordering * order = generic_grevlex_ptr
124  );
130 
131 
137 
138 
143  virtual void sort_by_order() override;
150  virtual void set_monomial_ordering(
151  const Monomial_Ordering * order, bool sort_anew = true
152  ) override;
164  virtual Monomial & leading_monomial() const override;
176  virtual Prime_Field_Element leading_coefficient() const override;
183  virtual unsigned length() const override;
188  virtual Polynomial_Linked_List * zero_polynomial() const override;
194  virtual bool is_zero() const override;
200  virtual bool can_reduce(Abstract_Polynomial & other) const override;
201  virtual Geobucket_Iterator * new_iterator() const override;
202  virtual Polynomial_Iterator * begin() const override;
203  virtual Polynomial_Iterator * end() const override;
204  virtual Geobucket_Iterator * new_mutable_iterator() override;
206 
207  friend class Geobucket_Iterator;
209 
218  void recompute_leading_monomial();
222  virtual Polynomial_Geobucket * monomial_multiple(const Monomial &t) const override;
226  virtual Polynomial_Geobucket * scalar_multiple(const Prime_Field_Element & a)
227  const override;
231  virtual Polynomial_Geobucket & operator +=(const Abstract_Polynomial & g) override;
235  virtual Polynomial_Geobucket & operator -=(const Abstract_Polynomial & g) override;
239  virtual void add_polynomial_multiple(
240  const Prime_Field_Element & b, const Monomial & u,
241  const Abstract_Polynomial & g, bool subtract=false
242  ) override;
246  virtual Polynomial_Linked_List * detach_head() override;
258  virtual void add_last(const Prime_Field_Element & a, const Monomial & t) override;
270  Abstract_Polynomial * canonicalize(bool constant_result=false);
272 
273 
283  void print(unsigned i, ostream & os=cout) const;
292  virtual void print(ostream & os=cout) const override;
293  inline friend ostream & operator << (ostream &, const Polynomial_Geobucket &);
295 protected:
302  inline unsigned lglen(unsigned i) {
303  unsigned result = 1;
304  while ((i >>= BUCKET_SHIFT)) { ++result; }
305  return result;
306  }
311 };
312 
313 #endif
The general class of a polynomial.
Definition: polynomial.hpp:101
Implementation of geobuckets.
virtual bool canMoveLeft() const override
LLPolynomial_Iterator * pi
an iterator for the current bucket
virtual void set_currCoeff(const Prime_Field_Element &a) override
change coefficient in current position
unsigned lglen(unsigned i)
Log-length of , used to select a bucket for a polynomial of length .
Iterator over linked list polynomials.
virtual bool fellOff() const override
const Abstract_Polynomial * p
the polynomial this points to
Definition: polynomial.hpp:272
Polynomial_Linked_List ** buckets
Array of ptrs to linked list polys; most initialized to nullptr.
virtual void restart_iteration() override
This should move the iterator to the leading term.
unsigned bucket_number
the bucket number at which we’re stopped
Polynomials that need arithmetic typically descend from this class.
Definition: polynomial.hpp:305
virtual void moveRight() override
Moves right in the polynomial, to the next smaller monomial.
Implementation of monomials.
Definition: monomial.hpp:69
Element of a field of prime characteristic.
Definition: fields.hpp:137
interface to a monomial ordering
Encapsulates information about a polynomial ring for easy access: ground field, number of indetermina...
virtual void set_currMonomial(const Monomial &t) override
change monomial in current position
A Mutable_Polynomial_Iterator allows one to modify the terms of a polynomial.
Definition: polynomial.hpp:283
virtual const Monomial & currMonomial() const override
Reports the monomial at the current position.
Polynomials represented as a doubly linked list.
Used to iterate through a polynomial.
Definition: polynomial.hpp:224
virtual bool canMoveRight() const override
Can this iterator move right, or would it fall off?
Polynomial_Geobucket * g
to save myself the hassle of static_cast<const Polynomial_Geobucket *>(p) every time I turn around ...
virtual const Prime_Field_Element & currCoeff() const override
Reports the coefficient at the 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.