Gröbner basis project
Codebase for research into Gröbner basis computation
polynomial_linked_list.hpp
1 #ifndef __POLYNOMIAL_LINKED_LIST_H_
2 #define __POLYNOMIAL_LINKED_LIST_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 
25 #include "fields.hpp"
26 #include "monomial.hpp"
27 #include "polynomial.hpp"
28 #include "polynomial_ring.hpp"
29 
30 extern Monomial_Ordering * generic_grevlex_ptr;
31 
43 {
44 public:
46 
50  Monomial_Node(const Prime_Field_Element & a, const Monomial & u);
54  Monomial_Node(Prime_Field & F, const Monomial & u);
56 
57 
60 
65  Monomial & monomial();
69 
70  friend class LLPolynomial_Iterator;
72  friend class Polynomial_Linked_List;
74 
75 
77  void * operator new(size_t);
79  void operator delete(void *);
81 protected:
90 };
91 
92 // forward declaration
94 
103 {
104 public:
106 
110  LLPolynomial_Iterator(Polynomial_Linked_List * poly, bool at_end = false);
114  LLPolynomial_Iterator(const Polynomial_Linked_List * poly, bool at_end = false);
116 
117 
121  virtual void restart_iteration() override;
128  virtual void moveRight() override { iter_curr = iter_curr->next; }
132  virtual void moveLeft() override { iter_curr = iter_curr->prev; }
134  virtual bool canMoveLeft() const override;
136  virtual bool canMoveRight() const override;
140  virtual bool fellOff() const override;
142 
143  virtual const Monomial & currMonomial() const override;
148  virtual const Prime_Field_Element & currCoeff() const override;
150 
151 
153  virtual void set_currCoeff(const Prime_Field_Element & a) override;
155  virtual void set_currMonomial(const Monomial & t) override;
157 protected:
162 };
163 
172 {
173 public:
175 
178  Polynomial_Ring & R,
179  const Monomial_Ordering * order = generic_grevlex_ptr
180  );
183  Polynomial_Ring & R,
184  const Monomial & t,
185  const Monomial_Ordering * order = nullptr
186  );
189  Polynomial_Ring & R,
190  const Prime_Field_Element & c, const Monomial & t,
191  const Monomial_Ordering * order = nullptr
192  );
195  Polynomial_Ring & R,
196  Monomial_Node * node,
197  const Monomial_Ordering * order = nullptr
198  );
204 
205 
207  virtual ~Polynomial_Linked_List();
209 
210 
215  virtual bool is_zero() const override;
220  virtual Monomial & leading_monomial() const override;
224  virtual Prime_Field_Element leading_coefficient() const override;
226  virtual unsigned length() const override;
227  virtual void set_monomial_ordering(
228  const Monomial_Ordering * ord, bool sort_anew = true
229  ) override;
231 
232 
237  virtual Polynomial_Linked_List * zero_polynomial() const override;
241  virtual Polynomial_Linked_List * monomial_multiple(const Monomial &u) const override;
245  virtual Polynomial_Linked_List * scalar_multiple(const Prime_Field_Element &c)
246  const override;
250  virtual Polynomial_Linked_List & operator +=(const Abstract_Polynomial &other) override;
254  virtual Polynomial_Linked_List & operator -=(const Abstract_Polynomial &other) override;
263  virtual void add_polynomial_multiple(
264  const Prime_Field_Element &a,
265  const Monomial &t,
266  const Abstract_Polynomial &q,
267  bool subtract
268  ) override;
272  virtual void sort_by_order() override;
274 
275 
277  virtual LLPolynomial_Iterator * new_iterator() const override;
279  virtual Polynomial_Iterator * begin() const override;
281  virtual Polynomial_Iterator * end() const override;
283  virtual LLPolynomial_Iterator * new_mutable_iterator() override;
285 
286 
288  virtual Polynomial_Linked_List * detach_head() override;
290  virtual void add_last(const Prime_Field_Element & c, const Monomial & t) override;
292 
293  friend class LLPolynomial_Iterator;
294 protected:
297 };
298 
299 #endif
The general class of a polynomial.
Definition: polynomial.hpp:101
Monomial_Node * iter_curr
the node at which we have stopped
Monomial_Node(const Prime_Field_Element &a, const Monomial &u)
Monomial u with coefficient a. Both are copied, and can be deleted.
Prime_Field_Element & coefficient()
This term’s coefficient.
Tool for Polynomial_Linked_List.
Monomial t
the monomial in this node
virtual void moveLeft() override
Moves the iterator left: to the next larger monomial.
Iterator over linked list polynomials.
Monomial_Node * next
for linking
Information necessary for a field modulo a prime.
Definition: fields.hpp:49
virtual void moveRight() override
Returns the monomial the iterator currently points to.
Monomial_Node * head
first monomial in the list, returned by leading_monomial()
Polynomial_Linked_List * p
@
Polynomials that need arithmetic typically descend from this class.
Definition: polynomial.hpp:305
Monomial_Node * prev
for linking
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...
A Mutable_Polynomial_Iterator allows one to modify the terms of a polynomial.
Definition: polynomial.hpp:283
Monomial & monomial()
This term’s monomial, or power product. The coefficient is not included.
Polynomials represented as a doubly linked list.
Used to iterate through a polynomial.
Definition: polynomial.hpp:224
Prime_Field_Element c
the monomial’s coefficient