F4
Library for Gröebner basis computations over finite fields.
 All Classes Namespaces Files Functions Variables Friends Pages
monomial.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Antoine Joux, Vanessa Vitse and Titouan Coladon
3  *
4  * This file is part of F4.
5  *
6  * F4 is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * F4 is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with F4. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 #ifndef F4_MONOMIAL_H
27 #define F4_MONOMIAL_H
28 
30 #include "global.h"
31 #include <iostream>
32 #include <string>
33 #include <vector>
34 #include <cassert>
40 namespace F4
41 {
46  class Monomial
47  {
48  public:
49 
50  /* Static methods */
51 
56  static void setNbVariable(int nbVariable);
57 
62  static int getNbVariable();
63 
68  static void setVariable(std::string const * vars);
69 
74  static std::string const * getVariable();
75 
80  static void setWeight(int * weight);
81 
86  static int * getWeight();
87 
92  static short getMaxDegree();
93 
99  static void setNbMonomial(short maxDegree);
100 
106  static void increaseNbMonomial(int numMonomial);
107 
112  static int getNbMonomial();
113 
120  static int getNbMonomial(int row, int column);
121 
126  static void freeNbMonomial();
127 
136  static int compareNumMonomial(int numMon1, int numMon2);
137 
143  static int varlistToInt(uint8_t const * varlist);
144 
152  static int varlistToInt(uint8_t const * varlist, short deg);
153 
160  static int varlistToInt(uint8_t const * varlist1, uint8_t const * varlist2);
161 
167  static void initMonomial(int nbVariable, short degree=0);
168 
172  static void freeMonomial();
173 
174  /* Constructor */
175 
179  Monomial();
180 
184  Monomial(Monomial const & toCopy);
185 
186  /* Destructor */
187 
191  ~Monomial();
192 
193 
194  /* Get / Set */
195 
200  short getDegree() const;
201 
206  uint8_t const * getVarlist() const;
207 
212  uint8_t getVarlist(int index) const;
213 
217  void setVarlist(uint8_t * varlist);
218 
219 
220  /* Miscellaneous */
221 
225  void allocate();
226 
230  void erase();
231 
237  void setMonomial(uint8_t const * varlist);
238 
244  void setMonomial(std::string const s);
245 
251  void setMonomial(int numMon);
252 
258  void setMonomial(Monomial const & mon);
259 
266  void setMonomialMultiply(Monomial const & mon1, Monomial const & mon2);
267 
275  void setMonomialDivide(Monomial const & mon1, Monomial const & mon2);
276 
282  void intToMonomial(int numMon);
283 
289  int monomialToInt() const;
290 
295  void printMonomial (std::ostream & stream) const;
296 
305  int compareMonomial(Monomial const & mon) const;
306 
314  bool isDivisible(Monomial const & mon) const;
315 
320  void reset();
321 
322 
323  /* Internal operators */
324 
331  Monomial & operator=(Monomial const & mon);
332 
339  Monomial & operator=(Monomial && mon);
340 
347  Monomial & operator*=(Monomial const & mon);
348 
355  friend int multiplyMonomial(Monomial const & mon1, Monomial const & mon2);
356 
364  Monomial & operator/=(Monomial const & mon);
365 
366  private:
367  short _deg;
368  uint8_t *_varlist;
370  static int NB_VARIABLE;
371  static std::string const * VARS;
372  static int * WEIGHT;
377  static std::vector<int *> NB_MONOMIAL;
378  static short MAX_DEGREE;
380  };
381 
382  /* External operators */
383 
388  std::ostream & operator<<(std::ostream & stream, Monomial const & mon);
389 
397  bool operator==(Monomial const & mon1, Monomial const & mon2);
398 
406  bool operator>(Monomial const & mon1, Monomial const & mon2);
407 
415  bool operator>=(Monomial const & mon1, Monomial const & mon2);
416 
424  bool operator<(Monomial const & mon1, Monomial const & mon2);
425 
433  bool operator<=(Monomial const & mon1, Monomial const & mon2);
434 }
435 
437 #include "../src/monomial.inl"
440 #endif // F4_MONOMIAL_H
bool operator>=(CriticalPair< Element > const &criticalPair1, CriticalPair< Element > const &criticalPair2)
Overload the operator >=.
uint8_t const * getVarlist() const
Get the varlist of this.
short getDegree() const
Get the degree of this.
static int * getWeight()
Get the static variable WEIGHT.
std::ostream & operator<<(std::ostream &stream, AvlCriticalPair< Element > const &avlCriticalPair)
Overload the operator <<.
static int NB_VARIABLE
Definition: monomial.h:370
Represent a monomial.
Definition: monomial.h:46
static void freeNbMonomial()
Free the dynamic 2D array NB_MONOMIAL, and call freeMonomialArray().
void setVarlist(uint8_t *varlist)
Set the varlist of this.
Monomial & operator/=(Monomial const &mon)
Overload the operator /=.
static int getNbVariable()
Get the static variable NB_VARIABLE.
static std::vector< int * > NB_MONOMIAL
NB_MONOMIAL[d][v] = Number of degree d monomials in the v first variables. NB_MONOMIAL[d][NB_VARIABLE...
Definition: monomial.h:377
void intToMonomial(int numMon)
Initialize this with the num-th monomial.
static void setNbMonomial(short maxDegree)
Modify the dynamic 2D array NB_MONOMIAL, and call setMonomialArray().
int monomialToInt() const
Compute the number of this.
static std::string const * getVariable()
Get the static variable VARS.
void setMonomialMultiply(Monomial const &mon1, Monomial const &mon2)
Initialize this with mon1 * mon2.
Monomial()
Constructor. Beware, varlist is not allocated.
int compareMonomial(Monomial const &mon) const
Compare monomials according to the grevlex order.
static void initMonomial(int nbVariable, short degree=0)
Initialise the static parameters of Monomial.
Wrapper for config.h in order to avoid multiple definitions.
static int * WEIGHT
Definition: monomial.h:372
static void setWeight(int *weight)
Modify the static variable WEIGHT.
uint8_t * _varlist
Definition: monomial.h:368
Monomial & operator=(Monomial const &mon)
Overload the operator =.
bool operator<=(CriticalPair< Element > const &criticalPair1, CriticalPair< Element > const &criticalPair2)
Overload the operator <=.
void setMonomialDivide(Monomial const &mon1, Monomial const &mon2)
Initialize this with mon1 / mon2.
void erase()
Delete the varlist of this.
static int getNbMonomial()
Get NB_MONOMIAL[MAX_DEGREE][NB_VARIABLE+1].
static void increaseNbMonomial(int numMonomial)
Modify the dynamic 2D array NB_MONOMIAL.
static int varlistToInt(uint8_t const *varlist)
Compute the number of a monomial from its varlist.
Monomial & operator*=(Monomial const &mon)
Overload the operator *=.
bool isDivisible(Monomial const &mon) const
Test if this is divisible by mon.
bool operator<(CriticalPair< Element > const &criticalPair1, CriticalPair< Element > const &criticalPair2)
Overload the operator <.
static void setVariable(std::string const *vars)
Modify the static variable VARS.
static void freeMonomial()
Free the space allocated by initMonomial.
void allocate()
Allocate the varlist of this.
short _deg
Definition: monomial.h:367
static int compareNumMonomial(int numMon1, int numMon2)
Compare two monomials, using MONOMIAL_ARRAY if possible.
bool operator>(CriticalPair< Element > const &criticalPair1, CriticalPair< Element > const &criticalPair2)
Overload the operator >.
friend int multiplyMonomial(Monomial const &mon1, Monomial const &mon2)
Multiply mon1 and mon2.
bool operator==(CriticalPair< Element > const &criticalPair1, CriticalPair< Element > const &criticalPair2)
Overload the operator ==.
void setMonomial(uint8_t const *varlist)
Initialize this with varlist.
static short MAX_DEGREE
Definition: monomial.h:378
static short getMaxDegree()
Get the static variable MAX_DEGREE.
static void setNbVariable(int nbVariable)
Modify the static variable NB_VARIABLE.
~Monomial()
Destructor.
void printMonomial(std::ostream &stream) const
Print the monomial.
static std::string const * VARS
Definition: monomial.h:371
void reset()
Reset this.