OPENF4
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 openf4.
5  *
6  * openf4 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  * openf4 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 openf4. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 #ifndef OPENF4_MONOMIAL_H
27 #define OPENF4_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=1);
168 
172  static void freeMonomial();
173 
174  /* Constructor */
175 
179  Monomial();
180 
184  Monomial(Monomial const & toCopy);
185 
186 
187  /* Get / Set */
188 
193  short getDegree() const;
194 
199  uint8_t const * getVarlist() const;
200 
205  uint8_t getVarlist(int index) const;
206 
210  void setVarlist(uint8_t * varlist);
211 
212 
213  /* Miscellaneous */
214 
218  void allocate();
219 
223  void erase();
224 
230  void setMonomial(uint8_t const * varlist);
231 
237  void setMonomial(std::string const s);
238 
244  void setMonomial(int numMon);
245 
251  void setMonomial(Monomial const & mon);
252 
259  void setMonomialMultiply(Monomial const & mon1, Monomial const & mon2);
260 
268  void setMonomialDivide(Monomial const & mon1, Monomial const & mon2);
269 
275  void intToMonomial(int numMon);
276 
282  int monomialToInt() const;
283 
288  void printMonomial (std::ostream & stream) const;
289 
298  int compareMonomial(Monomial const & mon) const;
299 
307  bool isDivisible(Monomial const & mon) const;
308 
313  void reset();
314 
315 
316  /* Internal operators */
317 
324  Monomial & operator=(Monomial const & mon);
325 
332  Monomial & operator=(Monomial && mon);
333 
340  Monomial & operator*=(Monomial const & mon);
341 
348  friend int multiplyMonomial(Monomial const & mon1, Monomial const & mon2);
349 
357  Monomial & operator/=(Monomial const & mon);
358 
359  private:
360  short _deg;
361  uint8_t *_varlist;
363  static int NB_VARIABLE;
364  static std::string const * VARS;
365  static int * WEIGHT;
370  static std::vector<int *> NB_MONOMIAL;
371  static short MAX_DEGREE;
373  };
374 
375  /* External operators */
376 
381  std::ostream & operator<<(std::ostream & stream, Monomial const & mon);
382 
390  bool operator==(Monomial const & mon1, Monomial const & mon2);
391 
399  bool operator>(Monomial const & mon1, Monomial const & mon2);
400 
408  bool operator>=(Monomial const & mon1, Monomial const & mon2);
409 
417  bool operator<(Monomial const & mon1, Monomial const & mon2);
418 
426  bool operator<=(Monomial const & mon1, Monomial const & mon2);
427 }
428 
430 #include "../src/monomial.inl"
433 #endif // OPENF4_MONOMIAL_H
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.
bool operator<(Term< Element > const &term1, Term< Element > const &term2)
Overload the operator <.
static int NB_VARIABLE
Definition: monomial.h:363
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:370
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.
static void initMonomial(int nbVariable, short degree=1)
Initialise the static parameters of Monomial.
int compareMonomial(Monomial const &mon) const
Compare monomials according to the grevlex order.
Wrapper for config.h in order to avoid multiple definitions.
static int * WEIGHT
Definition: monomial.h:365
static void setWeight(int *weight)
Modify the static variable WEIGHT.
uint8_t * _varlist
Definition: monomial.h:361
Monomial & operator=(Monomial const &mon)
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.
bool operator==(TaggedPolynomial< Element > const &taggedPolynomial1, TaggedPolynomial< Element > const &taggedPolynomial2)
Overload the operator ==.
Monomial & operator*=(Monomial const &mon)
Overload the operator *=.
bool isDivisible(Monomial const &mon) const
Test if this is divisible by mon.
static void setVariable(std::string const *vars)
Modify the static variable VARS.
bool operator<=(TaggedPolynomial< Element > const &taggedPolynomial1, TaggedPolynomial< Element > const &taggedPolynomial2)
Overload the operator <=.
static void freeMonomial()
Free the space allocated by initMonomial.
void allocate()
Allocate the varlist of this.
short _deg
Definition: monomial.h:360
static int compareNumMonomial(int numMon1, int numMon2)
Compare two monomials, using MONOMIAL_ARRAY if possible.
friend int multiplyMonomial(Monomial const &mon1, Monomial const &mon2)
Multiply mon1 and mon2.
bool operator>=(TaggedPolynomial< Element > const &taggedPolynomial1, TaggedPolynomial< Element > const &taggedPolynomial2)
Overload the operator >=.
void setMonomial(uint8_t const *varlist)
Initialize this with varlist.
static short MAX_DEGREE
Definition: monomial.h:371
static short getMaxDegree()
Get the static variable MAX_DEGREE.
static void setNbVariable(int nbVariable)
Modify the static variable NB_VARIABLE.
void printMonomial(std::ostream &stream) const
Print the monomial.
bool operator>(Term< Element > const &term1, Term< Element > const &term2)
Overload the operator >.
static std::string const * VARS
Definition: monomial.h:364
void reset()
Reset this.
std::ostream & operator<<(std::ostream &stream, Term< Element > const &term)
Overload the operator <<.