17 template<
typename Polynomial>
27 virtual std::list<std::pair<BitVector, BitVector> >
reduceInput()= 0;
44 template<
typename Polynomial,
template<
typename,
template<
typename>
class >
class Procedure, template<typename> class AddingPolynomialPolicy>
49 std::shared_ptr<Ideal<Polynomial>>
mGb;
60 Procedure<Polynomial, AddingPolynomialPolicy>(),
61 mGb(new
Ideal<Polynomial>),
64 mOrigGeneratorsIndices()
66 Procedure<Polynomial, AddingPolynomialPolicy>::setIdeal(mGb);
71 Procedure<Polynomial, AddingPolynomialPolicy>(old),
72 mGb(new
Ideal<Polynomial>(*old.mGb)),
73 mInputScheduled(old.mInputScheduled),
74 mOrigGenerators(old.mOrigGenerators),
75 mOrigGeneratorsIndices(old.mOrigGeneratorsIndices)
77 Procedure<Polynomial, AddingPolynomialPolicy>::setIdeal(mGb);
84 if(
this == &rhs)
return *
this;
89 Procedure<Polynomial, AddingPolynomialPolicy>::setIdeal(mGb);
90 Procedure<Polynomial, AddingPolynomialPolicy>::setCriticalPairs(rhs.pCritPairs);
100 return mInputScheduled.empty();
109 return mOrigGenerators.size();
118 mInputScheduled.push_back(p);
119 mOrigGenerators.push_back(p);
128 return getIdeal().is_constant();
137 return std::list<Polynomial>(getBasisPolynomials().begin(), getBasisPolynomials().end());
146 return getIdeal().getGenerators();
151 for(
const Polynomial& p : mInputScheduled)
157 p.getReasons().print(os);
179 Procedure<Polynomial, AddingPolynomialPolicy>::setIdeal(mGb);
197 if(mGb->getGenerators().size() + mInputScheduled.size() == 0)
202 Procedure<Polynomial, AddingPolynomialPolicy>::calculate(mInputScheduled);
204 mInputScheduled.clear();
205 mGb->removeEliminated();
206 CARL_LOG_DEBUG(
"carl.gb.gbproc",
"GB, before reduction: " << *mGb);
219 std::vector<Polynomial> toBeReduced;
221 for(
typename std::list<Polynomial>::const_iterator it = mInputScheduled.begin(); it != mInputScheduled.end(); ++it)
223 toBeReduced.push_back(*it);
225 std::sort(toBeReduced.begin(), toBeReduced.end(), Polynomial::compareByLeadingTerm);
228 mInputScheduled.clear();
237 std::list<std::pair<BitVector, BitVector> > result;
239 for(
typename std::vector<Polynomial>::const_iterator index = toBeReduced.begin(); index != toBeReduced.end(); ++index)
245 result.push_back(std::pair<BitVector, BitVector>(index->getReasons(), res.getReasons()));
249 CARL_LOG_TRACE(
"carl.gb.gbproc",
"Add input polynomial " << res.normalize());
253 mInputScheduled.push_back(res.normalize());
263 for(
size_t i = 0; i < mGb->nrGenerators(); ++i)
265 bool divisible =
false;
267 CARL_LOG_TRACE(
"carl.gb.gbproc",
"Check " << mGb->getGenerator(i));
268 for(
size_t j = 0; !divisible && j != mGb->nrGenerators(); ++j)
272 divisible = mGb->getGenerator(i).lmon()->divisible(mGb->getGenerator(j).lmon());
273 CARL_LOG_TRACE(
"carl.gb.gbproc",
"" << (divisible ?
"" :
"not ") <<
"divisible by " << mGb->getGenerator(j));
278 CARL_LOG_TRACE(
"carl.gb.gbproc",
"Eliminate " << mGb->getGenerator(i));
279 mGb->eliminateGenerator(i);
282 mGb->removeEliminated();
283 CARL_LOG_DEBUG(
"carl.gb.gbproc",
"GB Reduction, minimal GB: " << *mGb);
286 std::vector<size_t> toBeReduced(mGb->getOrderedIndices());
289 for(std::vector<size_t>::const_iterator index = toBeReduced.begin(); index != toBeReduced.end(); ++index)
296 CARL_LOG_DEBUG(
"carl.gb.gbproc",
"GB Reduction, reduced " << mGb->getGenerator(*index) <<
" to " << res);
297 reduced->addGenerator(res);
302 Procedure<Polynomial, AddingPolynomialPolicy>::setIdeal(mGb);
A small wrapper that configures logging for carl.
#define CARL_LOG_TRACE(channel, msg)
#define CARL_LOG_DEBUG(channel, msg)
#define CARL_LOG_INFO(channel, msg)
carl is the main namespace for the library.
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
virtual void calculate()=0
virtual void addPolynomial(const Polynomial &p)=0
virtual const Ideal< Polynomial > & getIdeal() const =0
virtual ~AbstractGBProcedure()=default
virtual std::list< std::pair< BitVector, BitVector > > reduceInput()=0
A general class for Groebner Basis calculation.
std::list< std::pair< BitVector, BitVector > > reduceInput()
Reduce the input polynomials using the other input polynomials and the current Groebner basis.
std::shared_ptr< Ideal< Polynomial > > mGb
The ideal represented by the current elements of the Groebner basis.
bool basisis_constant() const
Checks whether the current representants of the GB contain a constant polynomial.
const std::vector< Polynomial > & getBasisPolynomials() const
void calculate()
Calculate the Groebner basis of the current GB union the scheduled polynomials.
size_t nrOrigGenerators() const
The number of polynomials which were originally added to the GB.
GBProcedure(const GBProcedure &old)
std::list< Polynomial > mInputScheduled
The polynomials which are added during the next call for calculate.
virtual ~GBProcedure()=default
std::list< Polynomial > listBasisPolynomials() const
std::vector< size_t > mOrigGeneratorsIndices
Indices of the input polynomials.
void addPolynomial(const Polynomial &p)
Add a polynmomial which is added to the groebner basis during the next calculate call.
bool inputEmpty() const
Check whether a polynomial is scheduled to be added to the Groebner basis.
GBProcedure & operator=(const GBProcedure &rhs)
const Ideal< Polynomial > & getIdeal() const
Get the ideal which encodes the GB.
void reset()
Remove all polynomials from the Groebner basis.
void printScheduledPolynomials(bool breakLines=true, bool printReasons=true, std::ostream &os=std::cout) const
std::vector< Polynomial > mOrigGenerators
The input polynomials.
size_t addGenerator(const Polynomial &f)
A dedicated algorithm for calculating the remainder of a polynomial modulo a set of other polynomials...
InputPolynomial fullReduce()
Uses the ideal to reduce a polynomial as far as possible.