remove annotator, it passes check

parent 489d02b3
......@@ -13,7 +13,7 @@ fi
if [ $? -eq 0 ]
then
LD_LIBRARY_PATH="$(pwd)/lib" scripts/provide_wdir.sh build/tinygb -v WORKING_DIR < $1
LD_LIBRARY_PATH="$(pwd)/lib" scripts/provide_wdir.sh build/tinygb WORKING_DIR < $1
else
echo "Compilation failed."
fi
......@@ -6,6 +6,9 @@ SConscript('rowech/SConscript')
source_files = ['main.cc',
'monomial.cc',
'polynomial.cc',
'polynomial_in_matrix.cc',
'critical_pair.cc',
'matrices/spmat.cc',
'matrices/rowmajmat.cc',
'matrices/io_utils.cc',
......
#include "./critical_pair.h"
namespace tinygb {
CriticalPair::CriticalPair(const PolynomialInMatrix &p1,
const PolynomialInMatrix &p2) {
std::pair<Monomial, Monomial> c =
p1.LeadingMonomial().Cofactors(p2.LeadingMonomial());
left_ = std::pair<Monomial, PolynomialInMatrix>(c.first, p1);
right_ = std::pair<Monomial, PolynomialInMatrix>(c.second, p2);
LCM_ = left_.first*left_.second.LeadingMonomial();
}
// TODO(pj): extends to different strategies.
// TODO(pj): where is this used?
bool CriticalPair::operator<(CriticalPair &cp2) {
if (Degree() < cp2.Degree()) return true;
return false;
}
std::ostream& operator<<(std::ostream& o,
const std::pair<Monomial, PolynomialInMatrix> P) {
o << "(" << P.first << "," << P.second << ")";
return o;
}
std::ostream& operator<<(std::ostream& o, const CriticalPair& cp) {
o << cp.left_ << " " << cp.right_;
return o;
}
// TODO(pj): improve by merging both lists
std::list<Monomial> CriticalPair::GetMonomials() const {
std::list<Monomial> result;
for (const auto& m : left_.second.GetMonomials())
result.push_back(left_.first * m);
for (const auto& m : right_.second.GetMonomials())
result.push_back(right_.first * m);
return result;
}
Polynomial CriticalPair::Spolynomial() const {
Polynomial tmp = left_.second.to_polynomial();
tmp = tmp * left_.first;
Polynomial R = right_.second.to_polynomial();
R = R * right_.first;
R -= tmp;
R.Normalize();
return R;
}
} // namespace tinygb
......@@ -49,52 +49,6 @@ class CriticalPair {
Monomial LCM_;
};
CriticalPair::CriticalPair(const PolynomialInMatrix &p1,
const PolynomialInMatrix &p2) {
std::pair<Monomial, Monomial> c =
p1.LeadingMonomial().Cofactors(p2.LeadingMonomial());
left_ = std::pair<Monomial, PolynomialInMatrix>(c.first, p1);
right_ = std::pair<Monomial, PolynomialInMatrix>(c.second, p2);
LCM_ = left_.first*left_.second.LeadingMonomial();
}
// TODO(pj): extends to different strategies.
// TODO(pj): where is this used?
bool CriticalPair::operator<(CriticalPair &cp2) {
if (Degree() < cp2.Degree()) return true;
return false;
}
std::ostream& operator<<(std::ostream& o,
const std::pair<Monomial, PolynomialInMatrix> P) {
o << "(" << P.first << "," << P.second << ")";
return o;
}
std::ostream& operator<<(std::ostream& o, const CriticalPair& cp) {
o << cp.left_ << " " << cp.right_;
return o;
}
// TODO(pj): improve by merging both lists
std::list<Monomial> CriticalPair::GetMonomials() const {
std::list<Monomial> result;
for (const auto& m : left_.second.GetMonomials())
result.push_back(left_.first * m);
for (const auto& m : right_.second.GetMonomials())
result.push_back(right_.first * m);
return result;
}
Polynomial CriticalPair::Spolynomial() const {
Polynomial tmp = left_.second.to_polynomial();
tmp = tmp * left_.first;
Polynomial R = right_.second.to_polynomial();
R = R * right_.first;
R -= tmp;
R.Normalize();
return R;
}
} // namespace tinygb
#endif // CRITICAL_PAIR_H_
......@@ -18,14 +18,14 @@ class NormalStrategy {
unsigned step_degree;
std::list<CriticalPair> step_critical_pairs;
log(LOG_INFO) << "Normal strategy" << std::endl;
// log(LOG_INFO) << "Normal strategy" << std::endl;
step_degree = global_critical_pairs.front().Degree();
for (const auto& current_critical_pair : global_critical_pairs)
if (current_critical_pair.Degree() < step_degree)
step_degree = current_critical_pair.Degree();
log(LOG_INFO) << "Step degree: " << step_degree << std::endl;
// log(LOG_INFO) << "Step degree: " << step_degree << std::endl;
for (auto it = global_critical_pairs.begin();
it != global_critical_pairs.end(); ++it) {
if (it->Degree() == step_degree) {
......
......@@ -22,10 +22,10 @@ void field_clear();
template <class T>
void launchF4(std::istream &in, std::ostream &out) {
log(LOG_INFO) << "begin parsing" << std::endl;
// log(LOG_INFO) << "begin parsing" << std::endl;
Parser parser(in);
std::vector<Polynomial> sys = parser.parse();
log(LOG_INFO) << "parsing done" << std::endl;
// log(LOG_INFO) << "parsing done" << std::endl;
std::vector<Polynomial> gb = F4(sys);
for (const auto& f : gb) {
f.Print(out);
......@@ -34,7 +34,7 @@ void launchF4(std::istream &in, std::ostream &out) {
}
void initF4(std::string wdir, std::istream &in, std::ostream &out) {
log(LOG_INFO) << "Initialization" << std::endl;
// log(LOG_INFO) << "Initialization" << std::endl;
in >> NB_VARS;
in >> FIELD_CARD;
MONOMIAL_ORDERING = "grevlex";
......@@ -42,7 +42,8 @@ void initF4(std::string wdir, std::istream &in, std::ostream &out) {
save_glob_params(WORKDIR + "global_parameters.txt");
std::system(("mkdir -p " + WORKDIR + "matrices").c_str());
GivaroWrapper::k = GivaroWrapper::ring_t(Givaro::Integer(FIELD_CARD));
GivaroWrapper::k.write(log(LOG_INFO)) << std::endl;
// GivaroWrapper::k.write(log(LOG_INFO)) << std::endl;
// set cardinality of finite field
// at most UINT_MAX at the moment
// TODO(pj): multiprecision
......
......@@ -139,7 +139,7 @@ void InsertPolynomialGebauerMoller(std::list<CriticalPair> &global_critical_pair
std::list<PolynomialInMatrix> Interreduce(
std::vector<std::shared_ptr<const StorageMatrix> >& list_matrices,
const std::vector<Polynomial>& system) {
log(LOG_INFO) << "interreducing --- ";
// log(LOG_INFO) << "interreducing --- ";
// Makes the system monic.
auto system_copy = system;
for (auto& it : system_copy)
......@@ -183,12 +183,12 @@ std::vector<std::pair<Monomial, PolynomialInMatrix> > SelectReductors(
all_monomials.insert(term.first);
}
log(LOG_INFO) << all_monomials.size() << " monomials to reduce" << std::endl;
// log(LOG_INFO) << all_monomials.size() << " monomials to reduce" << std::endl;
bool flag;
while (!all_monomials.empty()) {
if (!(all_monomials.size() % 10000))
log(LOG_INFO) << " " << all_monomials.size() << " remaining" << std::endl;
// if (!(all_monomials.size() % 10000))
// log(LOG_INFO) << " " << all_monomials.size() << " remaining" << std::endl;
// Selects the largest monomial in all_monomials.
Monomial m = *(all_monomials.rbegin());
flag = false;
......@@ -216,11 +216,8 @@ std::vector<std::pair<Monomial, PolynomialInMatrix> > SelectReductors(
}
all_monomials.erase(--all_monomials.end());
}
timer_reductors_selection.Stop();
log(LOG_INFO) << "Time reductors selection: ";
BasicTimer::Print(log(LOG_INFO), timer_reductors_selection);
log(LOG_INFO) << std::endl;
acc_reductors_selection += timer_reductors_selection;
// log(LOG_INFO) << "Time reductors selection: ";
// log(LOG_INFO) << std::endl;
return step_reductors;
}
......@@ -228,8 +225,7 @@ std::vector<std::pair<Monomial, PolynomialInMatrix> > SelectReductors(
// template parameter S is the selection strategy for critical pairs.
template <class S = NormalStrategy>
std::vector<Polynomial> F4(const std::vector<Polynomial>& system) {
log(LOG_INFO) << "Starting F4: " << std::endl;
timer_globalF4.Start();
// log(LOG_INFO) << "Starting F4: " << std::endl;
std::vector<PolynomialInMatrix> gb;
std::list <CriticalPair> global_critical_pairs;
......@@ -246,7 +242,7 @@ std::vector<Polynomial> F4(const std::vector<Polynomial>& system) {
}
global_critical_pairs.sort();
unsigned step_number = 1;
log(LOG_INFO) << "Initialization done" << std::endl;
// log(LOG_INFO) << "Initialization done" << std::endl;
std::vector<PolynomialInMatrix> new_reduced_polynomials1;
std::vector<PolynomialInMatrix> new_reduced_polynomials2;
......@@ -261,23 +257,19 @@ std::vector<Polynomial> F4(const std::vector<Polynomial>& system) {
(!MAXSTEP_FLAG || step_number < MAXSTEP) &&
(!STOP_CRITERION || !stop_crit)) {
timer_step.Start();
log(LOG_INFO) << "------------- Step " << step_number << " ------------ " << std::endl;
log(LOG_INFO) << "total number critpairs: " <<
global_critical_pairs.size() << std::endl;
#ifdef MAGMA_SANITY_CHECK
std::cout << "print \"Step "<< step_number << "\";" << std::endl;
#endif
log(LOG_INFO) << "Start critpairs selection" << std::endl;
// log(LOG_INFO) << "------------- Step " << step_number << " ------------ " << std::endl;
/* log(LOG_INFO) << "total number critpairs: " <<
global_critical_pairs.size() << std::endl;*/
// log(LOG_INFO) << "Start critpairs selection" << std::endl;
step_critical_pairs = S::SelectCriticalPairs(global_critical_pairs);
log(LOG_INFO) << "End critpairs selection" << std::endl;
// log(LOG_INFO) << "End critpairs selection" << std::endl;
if (step_critical_pairs.empty())
continue;
log(LOG_INFO) << "Start reductors selection" << std::endl;
// log(LOG_INFO) << "Start reductors selection" << std::endl;
auto step_reductors =
SelectReductors(step_critical_pairs, global_reductors);
log(LOG_INFO) << "End reductors selection" << std::endl;
// log(LOG_INFO) << "End reductors selection" << std::endl;
// TODO(pj): Bad conversion, see how to make things work better.
std::list<std::pair<Monomial, PolynomialInMatrix> > list_step_reductors;
......@@ -285,10 +277,10 @@ std::vector<Polynomial> F4(const std::vector<Polynomial>& system) {
step_reductors.begin(),
step_reductors.end());
log(LOG_INFO) << "step critpairs: " <<
step_critical_pairs.size() << std::endl;
log(LOG_INFO) << "step reductors: " <<
step_reductors.size() << std::endl;
/* log(LOG_INFO) << "step critpairs: " <<
step_critical_pairs.size() << std::endl;*/
/* log(LOG_INFO) << "step reductors: " <<
step_reductors.size() << std::endl;*/
step_reductors.clear();
step_reductors.shrink_to_fit();
......@@ -297,17 +289,17 @@ std::vector<Polynomial> F4(const std::vector<Polynomial>& system) {
std::shared_ptr<MatrixF4> M = MatrixFactory::BuildMatrixF4(list_step_reductors, step_critical_pairs);
step_critical_pairs.clear();
log(LOG_INFO) << "constructed matrix of size " << M->row_size() << "x";
log(LOG_INFO) << M->column_size() << "; " << "Asize: ";
log(LOG_INFO) << M->get_Asize() << "; " << std::endl;
log(LOG_INFO) << "Computing row echelon" << std::endl;
// log(LOG_INFO) << "constructed matrix of size " << M->row_size() << "x";
// log(LOG_INFO) << M->column_size() << "; " << "Asize: ";
// log(LOG_INFO) << M->get_Asize() << "; " << std::endl;
// log(LOG_INFO) << "Computing row echelon" << std::endl;
M->RowEchelon();
log(LOG_INFO) << "constructed matrix of size " << M->row_size() << "x";
log(LOG_INFO) << M->column_size() << "; " << "Asize: ";
log(LOG_INFO) << M->get_Asize() << "; " << std::endl;
log(LOG_INFO) << std::endl;
log(LOG_INFO) << "reconstructing polynomials: " << std::endl;
// log(LOG_INFO) << "constructed matrix of size " << M->row_size() << "x";
// log(LOG_INFO) << M->column_size() << "; " << "Asize: ";
// log(LOG_INFO) << M->get_Asize() << "; " << std::endl;
// log(LOG_INFO) << std::endl;
// log(LOG_INFO) << "reconstructing polynomials: " << std::endl;
new_polynomials_in_gb.clear();
......@@ -345,10 +337,10 @@ std::vector<Polynomial> F4(const std::vector<Polynomial>& system) {
new_reduced_polynomials1.shrink_to_fit();
new_reduced_polynomials2.clear();
new_reduced_polynomials2.shrink_to_fit();
log(LOG_INFO) << "Number of new polynomials in gb: " <<
new_polynomials_in_gb.size() << std::endl;
// log(LOG_INFO) << "Number of new polynomials in gb: " <<
// new_polynomials_in_gb.size() << std::endl;
log(LOG_INFO) << "Updating critical pairs" << std::endl;
// log(LOG_INFO) << "Updating critical pairs" << std::endl;
for (const auto& f : new_polynomials_in_gb)
InsertPolynomialGebauerMoller(global_critical_pairs, gb, f);
......@@ -357,27 +349,24 @@ std::vector<Polynomial> F4(const std::vector<Polynomial>& system) {
new_polynomials_in_gb.shrink_to_fit();
step_number++;
timer_step.Stop();
log(LOG_INFO) << "Time step: ";
BasicTimer::Print(log(LOG_INFO), timer_step) << std::endl;
// log(LOG_INFO) << "Time step: ";
GB_LeadingMonomials.clear();
for (const auto& g : gb)
GB_LeadingMonomials.insert(g.LeadingMonomial());
stop_crit = HasAllPowersOfVars(GB_LeadingMonomials);
log(LOG_INFO) << "Are leading monomials 0-dim: " << stop_crit << std::endl;
log(LOG_INFO) << "Virtual memory: ";
memory::PrintMem(log(LOG_INFO), memory::getVmSize()) << std::endl;
log(LOG_INFO) << "Virtual memory peak: ";
memory::PrintMem(log(LOG_INFO), memory::getVmPeak()) << std::endl;
log(LOG_INFO) << "Physical memory used: ";
memory::PrintMem(log(LOG_INFO), memory::getVmRSS()) << std::endl;
// log(LOG_INFO) << "Are leading monomials 0-dim: " << stop_crit << std::endl;
// log(LOG_INFO) << "Virtual memory: ";
// memory::PrintMem(log(LOG_INFO), memory::getVmSize()) << std::endl;
// log(LOG_INFO) << "Virtual memory peak: ";
// memory::PrintMem(log(LOG_INFO), memory::getVmPeak()) << std::endl;
// log(LOG_INFO) << "Physical memory used: ";
// memory::PrintMem(log(LOG_INFO), memory::getVmRSS()) << std::endl;
}
log(LOG_INFO) << "Size of GB: " << gb.size() << std::endl;
// log(LOG_INFO) << "Size of GB: " << gb.size() << std::endl;
timer_globalF4.Stop();
log(LOG_INFO) << "Global F4 time: ";
BasicTimer::Print(log(LOG_INFO), timer_globalF4) << std::endl;
// log(LOG_INFO) << "Global F4 time: ";
log(LOG_INFO) << "------------ cleaning reductors -----------" << std::endl;
// log(LOG_INFO) << "------------ cleaning reductors -----------" << std::endl;
global_reductors.clear();
std::vector<Polynomial> final_gb;
for (const auto& f : gb)
......@@ -385,9 +374,9 @@ std::vector<Polynomial> F4(const std::vector<Polynomial>& system) {
std::sort(final_gb.begin(), final_gb.end());
std::reverse(final_gb.begin(), final_gb.end());
log(LOG_DEBUG) << "Is minimal: " << IsMinimalGB(final_gb) << std::endl;
log(LOG_INFO) << "Virtual memory peak: ";
memory::PrintMem(log(LOG_INFO), memory::getVmPeak()) << std::endl;
// log(LOG_DEBUG) << "Is minimal: " << IsMinimalGB(final_gb) << std::endl;
// log(LOG_INFO) << "Virtual memory peak: ";
// memory::PrintMem(log(LOG_INFO), memory::getVmPeak()) << std::endl;
return final_gb;
}
......
......@@ -248,13 +248,13 @@ std::shared_ptr<MatrixF4> MatrixFactory::BuildMatrixF4(std::list<std::pair<Monom
std::size_t nb_reductors = _PP.size();
_PP.clear();
log(LOG_INFO) << "step 1: sparsity A " << "(";
log(LOG_INFO) << \
100*static_cast<double>(ans->A->NumberOfNonzeroEntries())/
static_cast<double>(ans->A->row_size()*ans->A->column_size());
log(LOG_INFO) << "%)" << std::endl;
// log(LOG_INFO) << "step 1: sparsity A " << "(";
/* log(LOG_INFO) << \
100*static_cast<double>(ans->A->NumberOfNonzeroEntries())/
static_cast<double>(ans->A->row_size()*ans->A->column_size()); */
// log(LOG_INFO) << "%)" << std::endl;
if (ans->A != nullptr) {
log(LOG_INFO) << "Start multiplying by inverse" << std::endl;
// log(LOG_INFO) << "Start multiplying by inverse" << std::endl;
WriteSpMat(*(ans->A), "matA");
WriteRowMajMat(*(ans->B), "matB");
......@@ -262,7 +262,7 @@ std::shared_ptr<MatrixF4> MatrixFactory::BuildMatrixF4(std::list<std::pair<Monom
if (ans->B != nullptr)
delete (ans->B);
ReadRowMajMat(&(ans->B), "matR");
log(LOG_INFO) << "End multiplying by inverse" << std::endl;
// log(LOG_INFO) << "End multiplying by inverse" << std::endl;
}
delete ans->A;
ans->A = nullptr;
......@@ -274,10 +274,10 @@ std::shared_ptr<MatrixF4> MatrixFactory::BuildMatrixF4(std::list<std::pair<Monom
}
// TODO(pj): is it useful to have a factory method just for this case?
log(LOG_INFO) << "Start building matrices" << std::endl;
// log(LOG_INFO) << "Start building matrices" << std::endl;
std::pair<RowMajMat*, RowMajMat*> pair_mat =
MatrixFactory::BuildRowMajor(set_pols, std::pair<std::vector<Monomial>, std::vector<Monomial> >(ans->v1, ans->v2));
log(LOG_INFO) << "End building matrices" << std::endl;
// log(LOG_INFO) << "End building matrices" << std::endl;
ans->C = pair_mat.first;
ans->D = pair_mat.second;
ans->row_size_ = nb_reductors + ans->C->row_size();
......@@ -285,7 +285,7 @@ std::shared_ptr<MatrixF4> MatrixFactory::BuildMatrixF4(std::list<std::pair<Monom
if (ans->C != nullptr && ans->B != nullptr && ans->C->row_size() &&
ans->C->column_size() && ans->B->column_size()) {
log(LOG_INFO) << "Start multiply and subtract matrices" << std::endl;
// log(LOG_INFO) << "Start multiply and subtract matrices" << std::endl;
WriteRowMajMat(*(ans->B), "matB");
WriteRowMajMat(*(ans->C), "matC");
WriteRowMajMat(*(ans->D), "matD");
......@@ -293,7 +293,7 @@ std::shared_ptr<MatrixF4> MatrixFactory::BuildMatrixF4(std::list<std::pair<Monom
if (ans->D != nullptr)
delete (ans->D);
ReadRowMajMat(&(ans->D), "matR");
log(LOG_INFO) << "End multiply and subtract matrices" << std::endl;
// log(LOG_INFO) << "End multiply and subtract matrices" << std::endl;
delete ans->C;
ans->C = nullptr;
} else {
......
......@@ -3,9 +3,7 @@
#include <fstream>
#include <unistd.h>
#include "./glob_params.h"
#include "./annotator.h"
#include "./f4_launcher.h"
#include "./timer.h"
void usage() {
std::cerr << "usage: tinygb WORKDIR [OPTIONS]" << std::endl;
......@@ -27,8 +25,8 @@ void usage() {
std::cerr << "of the current basis generate a 0-dim ideal" << std::endl;
std::cerr << " -h" << std::endl;
std::cerr << " print usage" << std::endl;
std::cerr << " -v" << std::endl;
std::cerr << " set verbose mode on" << std::endl;
// std::cerr << " -v" << std::endl;
// std::cerr << " set verbose mode on" << std::endl;
}
int main(int argc, char** argv) {
......@@ -46,9 +44,9 @@ int main(int argc, char** argv) {
usage();
return 0;
break;
case 'v':
tinygb::GLOBAL_LOG_LEVEL = tinygb::LOG_INFO;
break;
// case 'v':
// tinygb::GLOBAL_LOG_LEVEL = tinygb::LOG_INFO;
// break;
case 'i':
input = new std::ifstream(optarg);
flag_input_file = 1;
......
Import('env')
source_files = ['matmulsub.cc',
'#src/monomial.cc',
'#src/polynomial.cc',
'#src/matrices/rowmajmat.cc',
'#src/matrices/io_utils.cc',
'#src/utils.cc',
......
......@@ -7,9 +7,6 @@
namespace tinygb {
// static member definition
Monomial_pool Monomial::m_pool;
// return D - C*B
void matmulsub(
std::string res_file,
......
......@@ -3,7 +3,6 @@
#include "./givaro_wrapper.h"
#include "./monomial.h"
#include "./annotator.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wignored-attributes"
......
#include "./matrices/rowmajmat.h"
#include "./annotator.h"
#include "./matrices/io_utils.h"
#include "./utils.h"
......@@ -100,7 +99,7 @@ void RowMajMat::RowEchelon(
row_size_, 0, rankD,
this->entries_, column_size_, Qlas );
log(LOG_INFO) << "reductions to 0:" << row_size() - rankD << std::endl;
// log(LOG_INFO) << "reductions to 0:" << row_size() - rankD << std::endl;
pivots.sort();
delete Plas;
delete Qlas;
......@@ -225,7 +224,7 @@ void RowMajMat::Print() const {
}
void RowMajMat::Compress() {
log(LOG_INFO) << "matrix compression " << row_size_ << " ";
// log(LOG_INFO) << "matrix compression " << row_size_ << " ";
std::size_t *nbshifts = new std::size_t[row_size_];
std::size_t tmp = 0, counter = 0;
for (std::size_t i = 0; i < row_size_; ++i)
......@@ -244,7 +243,7 @@ void RowMajMat::Compress() {
FFLAS::fassign(GivaroWrapper::k, row_size_ * column_size_, entries_, 1, newvals, 1);
FFLAS::fflas_delete(entries_);
entries_ = newvals;
log(LOG_INFO) << " " << row_size_ << std::endl;
// log(LOG_INFO) << " " << row_size_ << std::endl;
delete nbshifts;
}
......
#include "./polynomial.h"
namespace tinygb {
void Polynomial::CombineMonomials() {
typename std::list<std::pair<Monomial, GivaroWrapper> >::iterator it2;
for (auto it1 = terms_.begin(); it1 != terms_.end();) {
it2 = it1;
++it1;
if (it1 == terms_.end()) {
break;
} else if (it1->first == it2->first) {
it1->second += it2->second;
terms_.erase(it2);
}
}
}
void Polynomial::DivideByLeadingCoefficient() {
GivaroWrapper leading_coefficient = terms_.back().second;
assert(leading_coefficient != GivaroWrapper(0));
leading_coefficient.inv();
if (leading_coefficient == GivaroWrapper(1)) return;
for (auto& it : terms_)
it.second *= leading_coefficient;
}
void Polynomial::Normalize() {
terms_.sort();
CombineMonomials();
RemoveZeroTerms();
}
bool Polynomial::TopReductionBy(const Polynomial &g) {
assert(!g.IsEmpty());
if (IsEmpty()) return false;
if (!LeadingMonomial().IsDivisibleBy(g.LeadingMonomial())) return false;
Polynomial reductor = g*(LeadingMonomial()/g.LeadingMonomial());
reductor.DivideByLeadingCoefficient();
reductor *= LeadingCoefficient();
operator-=(reductor);
return true;
}
void Polynomial::RemoveZeroTerms() {
for (auto it = terms_.begin(); it != terms_.end(); ++it) {
while (it != terms_.end() && it->second == GivaroWrapper(0))
it = terms_.erase(it);
}
}
Polynomial Polynomial::operator*(const Monomial &m) const {
Polynomial R;
R.terms_.insert(R.terms_.begin(), this->terms_.begin(), this->terms_.end());
for (auto& it : R.terms_)
it.first *= m;
return R;
}
void Polynomial::operator+=(const Polynomial &P) {
std::list<Term> tmp_terms = P.terms_;
terms_.merge(tmp_terms);
CombineMonomials();
RemoveZeroTerms();
}
void Polynomial::operator*=(const GivaroWrapper &e) {
for (auto& it : terms_)
it.second *= e;
}
void Polynomial::operator/=(const GivaroWrapper& e) {
for (auto& it : terms_)
it.second /= e;
}
void Polynomial::operator-=(const Polynomial& P) {
std::list<Term> tmp_terms = P.terms_;
for (auto& it : tmp_terms)
it.second.neg();
terms_.merge(tmp_terms);
CombineMonomials();
RemoveZeroTerms();
}
void Polynomial::Print(std::ostream& o) const {