Gröbner basis project
Codebase for research into Gröbner basis computation
particular_orderings_atlas.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 
43 class Generic_Grevlex : public Monomial_Ordering {
44 public:
46 
48  virtual bool first_larger(const Monomial &, const Monomial &) const;
50  virtual bool first_smaller(const Monomial &, const Monomial &) const;
55  virtual bool first_larger_than_multiple(
56  const Monomial &, const Monomial &, const Monomial &
57  ) const;
63  virtual int cmp(const Monomial & t, const Monomial & u) const {
64  int result = 0;
65  if (first_larger(t, u)) result = 1;
66  else if (first_larger(u, t)) result = -1;
67  else result = 0;
68  return result;
69  }
71 };
72 
73 extern Monomial_Ordering * generic_grevlex_ptr;
74 
87 public:
89 
94  Grevlex_Order_Data(const Monomial & t);
98  virtual Grevlex_Order_Data * clone();
100 
101 
106 
107 
109  DEG_TYPE operator [] (NVAR_TYPE i) const;
110  virtual DEG_TYPE grading(NVAR_TYPE i) const { return gradings[i]; }
112 
113 
118  void assign_gradings(const Monomial &);
120 protected:
122  DEG_TYPE *gradings;
124  const NVAR_TYPE number_of_gradings;
125 };
126 
139 class Grevlex_Ordering : public Monomial_Ordering {
140 public:
142 
146  Grevlex_Ordering(NVAR_TYPE number_of_variables);
148 
149 
153  virtual bool first_larger(const Monomial & t, const Monomial & u) const;
157  virtual bool first_smaller(const Monomial & t, const Monomial & u) const;
164  virtual bool first_larger_than_multiple(
165  const Monomial & t, const Monomial & u, const Monomial & v
166  ) const;
173  DEG_TYPE partial_degree(const Monomial & t, NVAR_TYPE i) const;
179  virtual int cmp(const Monomial & t, const Monomial & u) const {
180  int result = 0;
181  if (first_larger(t, u)) result = 1;
182  else if (first_larger(u, t)) result = -1;
183  else result = 0;
184  return result;
185  }
187 
188 
192  DEG_TYPE compute_ith_weight(const Monomial & t, NVAR_TYPE i) const;
196  virtual void set_data(Monomial & t) const;
198 protected:
200  const NVAR_TYPE n;
201 };
202 
215 class WGrevlex : public Weighted_Ordering {
216 public:
218 
224  WGrevlex(NVAR_TYPE, WT_TYPE *, bool=true);
226 
227 
229  virtual const WT_TYPE * order_weights() const { return weights; }
231 
232 
237  virtual bool first_larger(const Monomial & t, const Monomial & u) const;
242  virtual bool first_smaller(const Monomial & t, const Monomial & u) const;
247  virtual bool first_larger_than_multiple(
248  const Monomial & t, const Monomial & u, const Monomial & v
249  ) const;
256  DEG_TYPE partial_degree(const Monomial & t, NVAR_TYPE i) const;
262  virtual int cmp(const Monomial & t, const Monomial & u) const {
263  int result = 0;
264  if (first_larger(t, u)) result = 1;
265  else if (first_larger(u, t)) result = -1;
266  else result = 0;
267  return result;
268  }
270 
271 
275  DEG_TYPE compute_ith_weight(const Monomial & t, NVAR_TYPE i) const;
279  virtual void set_data(Monomial & t) const;
281 
282  friend ostream & operator<<(ostream & os, const WGrevlex &word) {
284  os << "WGOrd( ";
285  for (unsigned i = 0; i < word.n; ++i) {
286  os << word.weights[i] << ' ';
287  }
288  os << ")";
289  return os;
290  }
292 protected:
294  const NVAR_TYPE n;
296  WT_TYPE * weights;
298  bool thorough_weighting;
299 };
300 
313 class Lex_Ordering : public Monomial_Ordering {
314 public:
316 
321  Lex_Ordering(NVAR_TYPE number_of_variables);
323 
324 
330  virtual bool first_larger(const Monomial & t, const Monomial & u) const;
336  virtual bool first_smaller(const Monomial & t, const Monomial & u) const;
343  virtual bool first_larger_than_multiple(
344  const Monomial & t, const Monomial & u, const Monomial & v
345  ) const;
351  virtual int cmp(const Monomial & t, const Monomial & u) const {
352  int result = 0;
353  if (first_larger(t, u)) result = 1;
354  else if (first_larger(u, t)) result = -1;
355  else result = 0;
356  return result;
357  }
359 protected:
361  const NVAR_TYPE n;
362 };
363 
376 public:
378 
384  WGrevlex_Order_Data(const Monomial & t);
388  WGrevlex_Order_Data * clone();
390 
391 
395 
396 
398  DEG_TYPE operator [] (NVAR_TYPE i) const;
399  inline virtual DEG_TYPE grading(NVAR_TYPE i) const { return gradings[i]; }
401 
402 
408  void assign_gradings(const Monomial &t);
410 
411 
413  void * operator new(size_t);
415  void operator delete(void *);
417 protected:
419  DEG_TYPE *gradings;
421  const NVAR_TYPE number_of_gradings;
422 };
423 
440 public:
442 
454  NVAR_TYPE number_of_variables, WT_TYPE * w, bool thorough=true
455  );
457 
458 
460  const WT_TYPE * order_weights() const;
462 
463 
465  virtual int cmp(const Monomial &, const Monomial &) const;
469  virtual bool first_larger(const Monomial & t, const Monomial & u) const;
473  virtual bool first_smaller(const Monomial & t, const Monomial & u) const;
477  virtual bool first_larger_than_multiple(
478  const Monomial & t, const Monomial & u, const Monomial & v
479  ) const;
481 
482 
489  DEG_TYPE partial_degree(const Monomial & t, NVAR_TYPE i) const;
495  DEG_TYPE compute_ith_weight(const Monomial & t, NVAR_TYPE i) const;
499  virtual void set_data(Monomial & t) const;
501 
502  friend ostream & operator<<(ostream & os, const CachedWGrevlex_Ordering &word) {
504  os << "WGOrd( ";
505  for (unsigned i = 0; i < word.n; ++i) {
506  os << word.weights[i] << ' ';
507  }
508  os << ")";
509  return os;
510  }
512 protected:
514  const NVAR_TYPE n;
516  const WT_TYPE * weights;
518  const bool fully_apply;
519 };
520 
528 class Nonsingular_Matrix_Ordering_Exception : public std::exception {
529  virtual const char * what() const throw();
530 };
531 
540 public:
547  Matrix_Ordering(NVAR_TYPE rows, NVAR_TYPE cols, const WT_TYPE **data);
553  virtual bool first_larger(const Monomial & t, const Monomial & u) const;
559  virtual bool first_smaller(const Monomial & t, const Monomial & u) const;
567  virtual bool first_larger_than_multiple(
568  const Monomial & t, const Monomial & u, const Monomial & v
569  ) const;
575  virtual int cmp(const Monomial & t, const Monomial & u) const {
576  int result = 0;
577  if (first_larger(t, u)) result = 1;
578  else if (first_larger(u, t)) result = -1;
579  else result = 0;
580  return result;
581  }
582 protected:
584  const NVAR_TYPE m;
586  const NVAR_TYPE n;
588  const WT_TYPE ** W;
589 };
590 
591 #endif
virtual DEG_TYPE grading(NVAR_TYPE i) const
default value is useless; orderings that supply gradings should redefine
data for the grevlex monomial ordering
virtual const WT_TYPE * order_weights() const
this weighted ordering’s weights
virtual int cmp(const Monomial &t, const Monomial &u) const
orderings defined by a nonsingular matrix
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 ...
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
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
virtual DEG_TYPE grading(NVAR_TYPE i) const
default value is useless; orderings that supply gradings should redefine
virtual int cmp(const Monomial &t, const Monomial &u) const
const WT_TYPE * weights
the weights that define this ordering
Implementation of monomials.
Definition: monomial.hpp:69
const NVAR_TYPE n
the number of variables, which should remain constant
interface to a monomial ordering
WT_TYPE * weights
the weights for this ordering
virtual void set_data(Monomial &t) const override
sets monomial ordering’s data; default is to do nothing
generic grevlex ordering, works with any number of variables
interface to a weighted monomial ordering
the lex ordering for a specified number of variables
the grevlex ordering for a specified number of variables
virtual int cmp(const Monomial &t, const Monomial &u) const
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
virtual int cmp(const Monomial &t, const Monomial &u) const override
virtual int cmp(const Monomial &t, const Monomial &u) const