Gröbner basis project
Codebase for research into Gröbner basis computation
particular_orderings.hpp
1 #ifndef __PARTICULAR_ORDERINGS_HPP_
2 #define __PARTICULAR_ORDERINGS_HPP_
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 <exception>
22 
23 #include "system_constants.hpp"
24 
25 #include "monomial.hpp"
26 
44 public:
46 
48  virtual bool first_larger(const Monomial &, const Monomial &) const override;
50  virtual bool first_smaller(const Monomial &, const Monomial &) const override;
55  virtual bool first_larger_than_multiple(
56  const Monomial &, const Monomial &, const Monomial &
57  ) const override;
63  virtual int cmp(const Monomial & t, const Monomial & u) const override {
64  int result = 0;
65  DEG_TYPE a = t.ordering_degree();
66  DEG_TYPE b = u.ordering_degree();
67  if (a > b) result = 1;
68  else if (a < b) result = -1;
69  else if (first_larger(t, u)) result = 1;
70  else if (first_larger(u, t)) result = -1;
71  else result = 0;
72  return result;
73  }
77 
79  virtual void set_data(Monomial & t) const override;
82 };
83 
84 extern Monomial_Ordering * generic_grevlex_ptr;
85 
98 public:
100 
105  Grevlex_Order_Data(const Monomial & t);
109  virtual Grevlex_Order_Data * clone() override;
111 
112 
117 
118 
120  DEG_TYPE operator [] (NVAR_TYPE i) const;
121  virtual DEG_TYPE grading(NVAR_TYPE i) const override { return gradings[i]; }
123 
124 
129  void assign_gradings(const Monomial &);
131 protected:
133  DEG_TYPE *gradings;
135  const NVAR_TYPE number_of_gradings;
136 };
137 
151 public:
153 
157  Grevlex_Ordering(NVAR_TYPE number_of_variables);
159 
160 
164  virtual bool first_larger(const Monomial & t, const Monomial & u) const override;
168  virtual bool first_smaller(const Monomial & t, const Monomial & u) const override;
175  virtual bool first_larger_than_multiple(
176  const Monomial & t, const Monomial & u, const Monomial & v
177  ) const override;
184  DEG_TYPE partial_degree(const Monomial & t, NVAR_TYPE i) const;
190  virtual int cmp(const Monomial & t, const Monomial & u) const override {
191  int result = 0;
192  if (first_larger(t, u)) result = 1;
193  else if (first_larger(u, t)) result = -1;
194  else result = 0;
195  return result;
196  }
198 
199 
203  DEG_TYPE compute_ith_weight(const Monomial & t, NVAR_TYPE i) const;
207  virtual void set_data(Monomial & t) const override;
209 protected:
211  const NVAR_TYPE n;
212 };
213 
226 class WGrevlex : public Weighted_Ordering {
227 public:
229 
235  WGrevlex(NVAR_TYPE, WT_TYPE *, bool=true);
237 
238 
240  virtual const WT_TYPE * order_weights() const override { return weights; }
242 
243 
248  virtual bool first_larger(const Monomial & t, const Monomial & u) const override;
253  virtual bool first_smaller(const Monomial & t, const Monomial & u) const override;
258  virtual bool first_larger_than_multiple(
259  const Monomial & t, const Monomial & u, const Monomial & v
260  ) const override;
267  DEG_TYPE partial_degree(const Monomial & t, NVAR_TYPE i) const;
273  virtual int cmp(const Monomial & t, const Monomial & u) const override {
274  int result = 0;
275  DEG_TYPE a = t.ordering_degree();
276  DEG_TYPE b = u.ordering_degree();
277  if (a > b) result = 1;
278  else if (a < b) result = -1;
279  else if (first_larger(t, u)) result = 1;
280  else if (first_larger(u, t)) result = -1;
281  else result = 0;
282  return result;
283  }
285 
286 
290  DEG_TYPE compute_ith_weight(const Monomial & t, NVAR_TYPE i) const;
294  virtual void set_data(Monomial & t) const override;
296 
297  friend ostream & operator<<(ostream & os, const WGrevlex &word) {
299  os << "WGOrd( ";
300  for (unsigned i = 0; i < word.n; ++i) {
301  os << word.weights[i] << ' ';
302  }
303  os << ")";
304  return os;
305  }
307 protected:
309  const NVAR_TYPE n;
311  WT_TYPE * weights;
314 };
315 
329 public:
331 
336  Lex_Ordering(NVAR_TYPE number_of_variables);
338 
339 
345  virtual bool first_larger(const Monomial & t, const Monomial & u) const override;
351  virtual bool first_smaller(const Monomial & t, const Monomial & u) const override;
358  virtual bool first_larger_than_multiple(
359  const Monomial & t, const Monomial & u, const Monomial & v
360  ) const override;
366  virtual int cmp(const Monomial & t, const Monomial & u) const override {
367  int result = 0;
368  if (first_larger(t, u)) result = 1;
369  else if (first_larger(u, t)) result = -1;
370  else result = 0;
371  return result;
372  }
374 protected:
376  const NVAR_TYPE n;
377 };
378 
391 public:
393 
403  virtual WGrevlex_Order_Data * clone() override;
405 
406 
410 
411 
413  DEG_TYPE operator [] (NVAR_TYPE i) const;
414  inline virtual DEG_TYPE grading(NVAR_TYPE i) const override { return gradings[i]; }
416 
417 
423  void assign_gradings(Monomial &t);
425 
426 
428  void * operator new(size_t);
430  void operator delete(void *);
432 protected:
434  DEG_TYPE *gradings;
436  const NVAR_TYPE number_of_gradings;
437 };
438 
455 public:
457 
469  NVAR_TYPE number_of_variables, WT_TYPE * w, bool thorough=true
470  );
472 
473 
475  virtual const WT_TYPE * order_weights() const override;
477 
478 
480  virtual int cmp(const Monomial &, const Monomial &) const override;
484  virtual bool first_larger(const Monomial & t, const Monomial & u) const override;
488  virtual bool first_smaller(const Monomial & t, const Monomial & u) const override;
492  virtual bool first_larger_than_multiple(
493  const Monomial & t, const Monomial & u, const Monomial & v
494  ) const override;
496 
497 
504  inline DEG_TYPE partial_degree(const Monomial & t, NVAR_TYPE i) const {
505  return t.monomial_ordering_data()->grading(i);
506  }
512  DEG_TYPE compute_ith_weight(const Monomial & t, NVAR_TYPE i) const;
516  virtual void set_data(Monomial & t) const override;
518 
519  friend ostream & operator<<(ostream & os, const CachedWGrevlex_Ordering &word) {
521  os << "WGOrd( ";
522  for (unsigned i = 0; i < word.n; ++i) {
523  os << word.weights[i] << ' ';
524  }
525  os << ")";
526  return os;
527  }
529 protected:
531  const NVAR_TYPE n;
533  const WT_TYPE * weights;
535  const bool fully_apply;
536 };
537 
545 class Nonsingular_Matrix_Ordering_Exception : public std::exception {
546  virtual const char * what() const throw() override;
547 };
548 
557 public:
564  Matrix_Ordering(NVAR_TYPE rows, NVAR_TYPE cols, const WT_TYPE **data);
570  virtual bool first_larger(const Monomial & t, const Monomial & u) const override;
576  virtual bool first_smaller(const Monomial & t, const Monomial & u) const override;
584  virtual bool first_larger_than_multiple(
585  const Monomial & t, const Monomial & u, const Monomial & v
586  ) const override;
592  virtual int cmp(const Monomial & t, const Monomial & u) const override {
593  int result = 0;
594  if (first_larger(t, u)) result = 1;
595  else if (first_larger(u, t)) result = -1;
596  else result = 0;
597  return result;
598  }
599 protected:
601  const NVAR_TYPE m;
603  const NVAR_TYPE n;
605  const WT_TYPE ** W;
606 };
607 
608 #endif
data for the grevlex monomial ordering
const NVAR_TYPE n
the number of variables, which should remain constant
virtual int cmp(const Monomial &t, const Monomial &u) const override
const NVAR_TYPE number_of_gradings
length of gradings
virtual DEG_TYPE grading(NVAR_TYPE i) const override
default value is useless; orderings that supply gradings should redefine
virtual int cmp(const Monomial &t, const Monomial &u) const override
orderings defined by a nonsingular matrix
WT_TYPE * weights
the weights for this ordering
DEG_TYPE ordering_degree() const
returns the ordering degree for this Monomial
Definition: monomial.hpp:177
the grevlex ordering for a specified number of variables
virtual bool first_larger_than_multiple(const Monomial &, const Monomial &, const Monomial &) const override
returns true iff the first Monomial is larger than the product of the second and the third ...
const WT_TYPE ** W
the matrix that defines this ordering
virtual bool first_larger(const Monomial &, const Monomial &) const override
returns true iff the first Monomial is larger than the second
virtual int cmp(const Monomial &t, const Monomial &u) const override
virtual bool first_smaller(const Monomial &, const Monomial &) const override
returns true iff the first Monomial is smaller than the second
data for a monomial ordering: optional, but stored in Monomial
DEG_TYPE partial_degree(const Monomial &t, NVAR_TYPE i) const
const NVAR_TYPE n
the number of columns
const NVAR_TYPE m
the number of rows
const WT_TYPE * weights
the weights that define this ordering
virtual const WT_TYPE * order_weights() const override
this weighted ordering’s weights
virtual DEG_TYPE grading(NVAR_TYPE i) const override
default value is useless; orderings that supply gradings should redefine
Implementation of monomials.
Definition: monomial.hpp:69
const NVAR_TYPE n
the number of variables, which should remain constant
interface to a monomial ordering
virtual void set_data(Monomial &t) const override
sets monomial ordering’s data; default is to do nothing
DEG_TYPE * gradings
list of partial sums of exponents
const NVAR_TYPE n
the number of variables, which should remain constant
generic grevlex ordering, works with any number of variables
Monomial_Order_Data * monomial_ordering_data() const
the Monomial_Order_Data associated with this Monomial
Definition: monomial.hpp:167
interface to a weighted monomial ordering
the lex ordering for a specified number of variables
virtual int cmp(const Monomial &t, const Monomial &u) const override
the grevlex ordering for a specified number of variables
data for the weighted grevlex monomial ordering
the weighted grevlex ordering for a specified number of variables, with cached weights for each monom...
const NVAR_TYPE n
the number of variables, which should remain constant
const bool fully_apply
whether to apply the weights to more than the first sum
const NVAR_TYPE number_of_gradings
length of gradings
virtual DEG_TYPE grading(NVAR_TYPE) const
default value is useless; orderings that supply gradings should redefine
DEG_TYPE * gradings
array of partial weighted sums of exponents
virtual int cmp(const Monomial &t, const Monomial &u) const override
bool thorough_weighting
whether to apply the weights to all the variables