OPENF4
Library for Gröebner basis computations over finite fields.
 All Classes Namespaces Files Functions Variables Friends Pages
ideal.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_IDEAL_H
27 #define OPENF4_IDEAL_H
28 
30 #include "global.h"
31 #include <iostream>
33 #include "matrix.h"
34 #include "avl-monomial.h"
35 #include "avl-polynomial.h"
36 #include "avl-critical-pair.h"
37 
41 namespace F4
42 {
47  struct Stat
48  {
49  int _nbCp;
50  int _nbCpDeg;
53  clock_t _timePurgeCp;
54  clock_t _timeAddCp;
55  clock_t _timeMajBasis;
58  {
59  }
60  };
61 
66  template <typename Element>
67  class Ideal
68  {
69  public:
70 
71  /* Constructor */
72 
80  Ideal(std::vector<Polynomial<Element>> & polynomialArray, int nbVariable, int capacity=100000, int degree=0);
81 
82 
83  /* Destructor */
84 
88  ~Ideal();
89 
90 
91  /* Miscellaneous */
92 
96  void printInfo() const;
97 
101  void printReducedGroebnerBasis(bool printBasis=false) const;
102 
106  std::vector<std::string> getReducedGroebnerBasis() const;
107 
111  void printReducedGroebnerBasis(string const filename, int64_t modulo) const;
112 
116  void printMonomialAvl();
117 
121  void printTaggedPolynomialAvl() const;
122 
126  void printMatrix (Matrix<Element> & mat, int *tabMon, int *sigma, string const & filename);
127 
128 
129  /* Algorithms */
130 
137  int simplify (Monomial const & u, int numList);
138 
143  void update(int index, bool purge, Stat & stat);
144 
151  void appendMatrixF4 (CriticalPair<Element> & p, int & h, int & nbPiv);
152 
164  double transform(Matrix<Element> & mat, int *tabMon, int nbPiv, int *tau, int *sigma, int *startTail, int *endCol);
165 
174  Polynomial<Element> buildPolynomial (Element * row, int *tabMon, int width, int start, int *tau);
175 
184  void buildPolynomial (Polynomial<Element> & res, Element * row, int *tabMon, int width, int start, int *tau);
185 
192  void preprocessing(int & width, int & height, int & nbPiv);
193 
207  bool postprocessing(Matrix<Element> & matrix, int * tabMon, int * sigma, int * tau, int height, int width, int heightReal, int nbPiv, Stat & stat);
208 
209 
210  /* F4 Algorithm */
211 
216  int f4();
217 
218 
219 
220  private:
221  std::vector<Polynomial<Element>> _polynomialArray;
223  int _numPol;
224  int _numTot;
225  int _numGen;
226  std::vector<int> _total;
227  std::vector<int> _basis;
228  std::vector<TaggedPolynomial<Element>> _taggedPolynomialArray;
231  vector<CriticalPair<Element> *> _cpSet0;
232  vector<CriticalPair<Element> *> _cpSet1;
233  vector<CriticalPair<Element> *> _cpSet2;
234  vector<CriticalPair<Element>> _cpArray;
237  };
238 }
239 
241 #include "../src/ideal.inl"
244 #endif // OPENF4_IDEAL_H
Represent an avl of pair (number of a monomial, is leading monomial).
Definition: avl-monomial.h:79
Represent a monomial.
Definition: monomial.h:46
Represent a matrix.
Definition: matrix.h:80
std::vector< int > _basis
Definition: ideal.h:227
Polynomial< Element > buildPolynomial(Element *row, int *tabMon, int width, int start, int *tau)
Build a polynomial from a row of the F4 matrix.
void update(int index, bool purge, Stat &stat)
Update the set of critical pair and the current basis.
clock_t _timeMajBasis
Definition: ideal.h:55
MonomialArray _monomialArray
Definition: ideal.h:229
std::vector< TaggedPolynomial< Element > > _taggedPolynomialArray
Definition: ideal.h:228
void printMatrix(Matrix< Element > &mat, int *tabMon, int *sigma, string const &filename)
Print mat.
Represent an avl of critical pair.
int _nbCpDeg
Definition: ideal.h:50
AvlPolynomial _matPols
Definition: ideal.h:236
int f4()
Compute a groebner basis of this using the F4 algorithm.
int _cmptGenPurg
Definition: ideal.h:51
int _cmptNewGen
Definition: ideal.h:52
void printMonomialAvl()
Print _matMons.
Represent a critical pair.
Definition: critical-pair.h:44
Represent an ideal.
Definition: ideal.h:67
int _nbCp
Definition: ideal.h:49
Declaration of class AvlPolynomial.
Wrapper for config.h in order to avoid multiple definitions.
int _numPol
Definition: ideal.h:223
Declaration of class AvlMonomial.
Declaration of class AvlCriticalPair.
std::vector< Polynomial< Element > > _polynomialArray
Definition: ideal.h:221
void appendMatrixF4(CriticalPair< Element > &p, int &h, int &nbPiv)
Update _matPols and _matMons with the critical pair p.
int _numGen
Definition: ideal.h:225
clock_t _timeAddCp
Definition: ideal.h:54
Represent a array of monomials.
std::vector< std::string > getReducedGroebnerBasis() const
Get the reduced Groebner basis as a vector of string.
AvlMonomial _matMons
Definition: ideal.h:235
~Ideal()
Destructor.
std::vector< int > _total
Definition: ideal.h:226
Structure used for statistics.
Definition: ideal.h:47
vector< CriticalPair< Element > * > _cpSet0
Definition: ideal.h:231
Represent an avl of triple (number of a polynomial, number of its leading monomial, number of terms).
Declaration of class Matrix.
bool postprocessing(Matrix< Element > &matrix, int *tabMon, int *sigma, int *tau, int height, int width, int heightReal, int nbPiv, Stat &stat)
Rebuild _matPols from mat, update the basis and the set of critical pairs.
Represent a polynomial.
Definition: polynomial.h:47
vector< CriticalPair< Element > > _cpArray
Definition: ideal.h:234
int simplify(Monomial const &u, int numList)
Simplify the product u*(_taggedPolynomialArray[numList].poly) by another polynomial with the same lea...
double transform(Matrix< Element > &mat, int *tabMon, int nbPiv, int *tau, int *sigma, int *startTail, int *endCol)
Transform _matPols and _matMons into an almost tringular matrix.
void preprocessing(int &width, int &height, int &nbPiv)
Add polynomials to _matPols in order to reduced queue of current polynomials.
vector< CriticalPair< Element > * > _cpSet2
Definition: ideal.h:233
void printTaggedPolynomialAvl() const
Print _matPols.
void printInfo() const
Print _taggedPolynomialArray.
Ideal(std::vector< Polynomial< Element >> &polynomialArray, int nbVariable, int capacity=100000, int degree=0)
Constructor.
AvlCriticalPair< Element > _criticalPairSet
Definition: ideal.h:230
void printReducedGroebnerBasis(bool printBasis=false) const
Print the reduced Groebner basis.
int _numTot
Definition: ideal.h:224
int _nbVariable
Definition: ideal.h:222
clock_t _timePurgeCp
Definition: ideal.h:53
vector< CriticalPair< Element > * > _cpSet1
Definition: ideal.h:232