Gröbner basis project
Codebase for research into Gröbner basis computation
monomial.hpp
1 #ifndef __MONOMIAL_H_
2 #define __MONOMIAL_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 <string>
22 #include <cstdlib>
23 #include <iostream>
24 #include <initializer_list>
25 
26 #include "system_constants.hpp"
27 
28 #include "goda.hpp"
29 #include "monomial_ordering.hpp"
30 
31 extern Monomial_Ordering * generic_grevlex_ptr;
32 
33 using std::ostream;
34 using std::cout;
35 using std::initializer_list;
36 using std::endl;
37 using std::string;
38 
39 #define EPACK false
40 #define PACKSIZE uint8_t
41 #define NPACK sizeof(unsigned long long)/sizeof(PACKSIZE)
69 class Monomial {
70 public:
72 
74  inline void common_initialization(const Monomial_Ordering * ord = nullptr) {
75  exponents = nullptr; ordering_data = nullptr; ordering = ord;
76  }
81  void initialize_exponents(NVAR_TYPE number_of_vars);
86  void deinitialize();
88  void set_exponent(NVAR_TYPE i, DEG_TYPE e);
90  Monomial(
91  NVAR_TYPE number_of_vars,
92  const Monomial_Ordering * order = generic_grevlex_ptr
93  );
95  Monomial(const Monomial &other);
102  Monomial(
103  initializer_list<EXP_TYPE> powers,
104  const Monomial_Ordering * order = generic_grevlex_ptr
105  );
114  Monomial(
115  NVAR_TYPE size, const EXP_TYPE *powers,
116  const Monomial_Ordering * order = generic_grevlex_ptr
117  );
119 
120 
122  ~Monomial();
124 
128 
130  inline NVAR_TYPE num_vars() const { return n; }
132  bool is_one() const;
134  DEG_TYPE degree(NVAR_TYPE i) const;
136  DEG_TYPE operator[](NVAR_TYPE i) const;
144  DEG_TYPE total_degree(NVAR_TYPE m=0) const;
155  DEG_TYPE weighted_degree(const WT_TYPE *weights, NVAR_TYPE m=0) const;
157  const EXP_TYPE * log() const { return exponents; }
159 
163 
165  inline const Monomial_Ordering * monomial_ordering() const { return ordering; }
168  return ordering_data;
169  }
171  void set_monomial_ordering(const Monomial_Ordering * mord);
173  void set_ordering_data(Monomial_Order_Data * mordat);
175  inline void set_ordering_degree(DEG_TYPE d) { ord_degree = d; }
177  inline DEG_TYPE ordering_degree() const { return ord_degree; }
179  bool operator ==(const Monomial &other) const;
181  bool operator !=(const Monomial &other) const;
185  bool is_coprime(const Monomial &other) const;
187  int cmp(const Monomial & u) const {
188  return monomial_ordering()->cmp(*this, u);
189  }
191  bool is_like(const Monomial &other) const;
193  bool like_multiple(const Monomial &u, const Monomial &v) const;
198  bool like_multiple(EXP_TYPE * e, const Monomial & v) const;
202  bool larger_than(const Monomial &) const;
206  bool operator >(const Monomial & u) const;
210  bool operator >=(const Monomial & u) const;
214  bool operator <(const Monomial & u) const;
218  bool operator <=(const Monomial & u) const;
222  bool larger_than_multiple(
223  const Monomial & u, const Monomial &v
224  ) const;
226  bool divisible_by(const Monomial &other) const;
228  bool operator |(const Monomial &other) const;
230 
234 
236  Monomial & operator =(const Monomial &other);
238  Monomial & operator *=(const Monomial &other);
240  Monomial operator *(const Monomial &other) const;
249  bool operator /=(const Monomial &other);
251  Monomial lcm(const Monomial & u) const;
253  Monomial gcd(const Monomial & u) const;
257  Monomial colon(const Monomial & u) const;
259 
260 
265  void print(bool=true, ostream & = cout, const string * names = nullptr) const;
269  void printlncout() { print(); }
273  friend ostream & operator << (ostream &, const Monomial & u);
275 
276 
278  void * operator new(size_t);
280  void operator delete(void *);
282 protected:
284  NVAR_TYPE n;
286  EXP_TYPE * exponents;
290  DEG_TYPE ord_degree;
296  uint64_t mask;
297  #if EPACK
298 
299  uint64_t emask;
300  #endif
301 };
302 
303 #endif
NVAR_TYPE n
number of variables
Definition: monomial.hpp:284
void printlncout()
equivalent to print() with default values
Definition: monomial.hpp:269
DEG_TYPE ordering_degree() const
returns the ordering degree for this Monomial
Definition: monomial.hpp:177
const Monomial_Ordering * ordering
Monomial_Ordering associated with this polynomial.
Definition: monomial.hpp:292
int cmp(const Monomial &u) const
Returns 0 if like, negative if smaller.
Definition: monomial.hpp:187
data for a monomial ordering: optional, but stored in Monomial
ray operator*(RAYENT_TYPE a, ray &r)
Multiply every coordinate in the given ray by the given scalar.
Definition: lp_solver.cpp:222
Monomial_Order_Data * ordering_data
optional data for a monomial ordering
Definition: monomial.hpp:294
NVAR_TYPE num_vars() const
number of variables
Definition: monomial.hpp:130
Implementation of monomials.
Definition: monomial.hpp:69
interface to a monomial ordering
EXP_TYPE * exponents
has size n
Definition: monomial.hpp:286
const EXP_TYPE * log() const
Direct access to the exponents, for whatever reason.
Definition: monomial.hpp:157
Monomial_Order_Data * monomial_ordering_data() const
the Monomial_Order_Data associated with this Monomial
Definition: monomial.hpp:167
const Monomial_Ordering * monomial_ordering() const
the Monomial_Ordering associated with this Monomial
Definition: monomial.hpp:165
DEG_TYPE ord_degree
degree associated with monomial ordering (used for faster comparisons)
Definition: monomial.hpp:290
uint64_t mask
divisibility mask (up to 64 variables)
Definition: monomial.hpp:296
void set_ordering_degree(DEG_TYPE d)
sets the ordering degree for this Monomial
Definition: monomial.hpp:175
void common_initialization(const Monomial_Ordering *ord=nullptr)
things all Monomial initializers must do
Definition: monomial.hpp:74