carl  24.04
Computer ARithmetic Library
Buchberger.h
Go to the documentation of this file.
1 
2 
3 /**
4  * @file Buchberger.h
5  * @ingroup gb
6  * @author Sebastian Junges
7  *
8  *
9  */
10 
11 #pragma once
12 //#define BUCHBERGER_STATISTICS
13 
14 
15 #include "../GBUpdateProcedures.h"
16 #include "../Ideal.h"
17 #include "../Reductor.h"
18 #include "CriticalPairs.h"
19 
20 #include <list>
21 #include <unordered_map>
22 
23 namespace carl
24 {
25 
26 
27 /**
28  * @ingroup gb
29  */
30 template<typename BuchbergerProc>
32 {
33 private:
34  BuchbergerProc* procedure;
35 public:
36  explicit UpdateFnct(BuchbergerProc* proc) : procedure(proc) {}
37  ~UpdateFnct() override = default;
38 
39  void operator()(std::size_t index) override
40  {
41  procedure->update(index);
42  }
43 };
44 
45 
46 /**
47  * Standard settings used if the Buchberger object is not instantiated with another template parameter.
48  * @ingroup gb
49  */
51 {
52  static const bool calculateRealRadical = true;
53 };
54 
55 
56 
57 /**
58  * Gebauer and Moeller style implementation of the Buchberger algorithm. For more information about this Algorithm.
59  * More information can be found in the Bachelor Thesis On Groebner Bases in SMT-Compliant Decision Procedures.
60  * @ingroup gb
61  */
62 template<typename Polynomial, template<typename> class AddingPolicy>
63 class Buchberger : private AddingPolicy<Polynomial>
64 {
65 
66 protected:
67  std::shared_ptr<Ideal<Polynomial>> pGb;
68  std::vector<size_t> mGbElementsIndices;
69  std::shared_ptr<CritPairs> pCritPairs;
71 #ifdef BUCHBERGER_STATISTICS
72  BuchbergerStats* mStats;
73 #endif
74 
75 
76 public:
78  pGb(),
80  pCritPairs(new CritPairs()),
81  mUpdateCallBack(this)
82  {
83 
84  }
85 
86  virtual ~Buchberger() = default;
87 
88  Buchberger(const Buchberger& rhs):
89  pGb(new Ideal<Polynomial>(*rhs.pGb)),
91  pCritPairs(new CritPairs(*rhs.pCritPairs)),
92  mUpdateCallBack(this)
93  {
94  }
95 
96  void calculate(const std::list<Polynomial>& scheduledForAdding);
97  void setIdeal(const std::shared_ptr<Ideal<Polynomial>>& ideal)
98  {
99  pGb = ideal;
100  }
101  void setCriticalPairs(const std::shared_ptr<CritPairs>& criticalPairs)
102  {
103  pCritPairs = criticalPairs;
104  }
105 
106  //std::list<std::pair<BitVector, BitVector> > reduceInput();
107 
108  void update(size_t index);
109 protected:
110 
111  bool addToGb(const Polynomial& newPol)
112  {
113  CARL_LOG_DEBUG("carl.gb.buchberger", "Add to gb: " << newPol);
114  return AddingPolicy<Polynomial>::addToGb( newPol, pGb, &mUpdateCallBack);
115  }
116  void removeBuchbergerTriples(std::unordered_map<size_t, SPolPair>& spairs, std::vector<size_t>& primelist);
117 
118  void reduce();
119 };
120 
121 }
122 
123 #include "Buchberger.tpp"
#define CARL_LOG_DEBUG(channel, msg)
Definition: carl-logging.h:43
carl is the main namespace for the library.
~UpdateFnct() override=default
BuchbergerProc * procedure
Definition: Buchberger.h:34
void operator()(std::size_t index) override
Definition: Buchberger.h:39
UpdateFnct(BuchbergerProc *proc)
Definition: Buchberger.h:36
Standard settings used if the Buchberger object is not instantiated with another template parameter.
Definition: Buchberger.h:51
static const bool calculateRealRadical
Definition: Buchberger.h:52
Gebauer and Moeller style implementation of the Buchberger algorithm.
Definition: Buchberger.h:64
bool addToGb(const Polynomial &newPol)
Definition: Buchberger.h:111
void calculate(const std::list< Polynomial > &scheduledForAdding)
std::vector< size_t > mGbElementsIndices
Definition: Buchberger.h:68
void removeBuchbergerTriples(std::unordered_map< size_t, SPolPair > &spairs, std::vector< size_t > &primelist)
void setIdeal(const std::shared_ptr< Ideal< Polynomial >> &ideal)
Definition: Buchberger.h:97
UpdateFnct< Buchberger< Polynomial, AddingPolicy > > mUpdateCallBack
Definition: Buchberger.h:70
std::shared_ptr< Ideal< Polynomial > > pGb
Definition: Buchberger.h:67
void update(size_t index)
Buchberger(const Buchberger &rhs)
Definition: Buchberger.h:88
std::shared_ptr< CritPairs > pCritPairs
Definition: Buchberger.h:69
void setCriticalPairs(const std::shared_ptr< CritPairs > &criticalPairs)
Definition: Buchberger.h:101
virtual ~Buchberger()=default
A little class for gathering statistics about the Buchberger algorithm calls.
A data structure to store all the SPolynomial pairs which have to be checked.
Definition: CriticalPairs.h:54