almost done: some linking problems

parent b7301ceb
This diff is collapsed.
......@@ -14,3 +14,6 @@ modify memory_report
implement rule of 0/3/5
remove EXTRACT_ALL option from the Doxygen file
do five subprograms: selred selcrit buildmat addcrit tinygb_init
......@@ -9,27 +9,20 @@
namespace tinygb {
// TODO: remove this forward definition
template <class T>
class CriticalPair;
template <class T>
std::ostream& operator<<(std::ostream&, const CriticalPair<T> &);
// This class represents critical pairs, i.e. pairs ((m1,p1),(m2,p2)) such that
// the leading monomial of m1*p1 equals that of m2*p2.
// Polynomials p1 and p2 are assumed to be monic.
template <class T>
class CriticalPair {
public:
CriticalPair(const PolynomialInMatrix<T>& p1,
const PolynomialInMatrix<T>& p2);
CriticalPair(const PolynomialInMatrix& p1,
const PolynomialInMatrix& p2);
const std::pair<Monomial, PolynomialInMatrix<T> >& left() const {
const std::pair<Monomial, PolynomialInMatrix>& left() const {
return left_;
}
const std::pair<Monomial, PolynomialInMatrix<T> >& right() const {
const std::pair<Monomial, PolynomialInMatrix>& right() const {
return right_;
}
......@@ -40,56 +33,51 @@ class CriticalPair {
unsigned Degree() const {
return left_.second.Degree()+left_.first.Degree();}
Polynomial<T> Spolynomial() const;
Polynomial Spolynomial() const;
// Returns the set of monomials that airse with non zero coeff in both sides.
// Unicity in the returned list is not ensured.
std::list<Monomial> GetMonomials() const;
bool operator<(CriticalPair<T> &cp2);
bool operator==(const CriticalPair<T> &cp2) const;
friend std::ostream& operator<< <T>(std::ostream&, const CriticalPair<T>&);
bool operator<(CriticalPair &cp2);
bool operator==(const CriticalPair &cp2) const;
friend std::ostream& operator<<(std::ostream&, const CriticalPair&);
private:
std::pair<Monomial, PolynomialInMatrix<T> > left_;
std::pair<Monomial, PolynomialInMatrix<T> > right_;
std::pair<Monomial, PolynomialInMatrix> left_;
std::pair<Monomial, PolynomialInMatrix> right_;
Monomial LCM_;
};
template <class T>
CriticalPair<T>::CriticalPair(const PolynomialInMatrix<T> &p1,
const PolynomialInMatrix<T> &p2) {
CriticalPair::CriticalPair(const PolynomialInMatrix &p1,
const PolynomialInMatrix &p2) {
std::pair<Monomial, Monomial> c =
p1.LeadingMonomial().Cofactors(p2.LeadingMonomial());
left_ = std::pair<Monomial, PolynomialInMatrix<T> >(c.first, p1);
right_ = std::pair<Monomial, PolynomialInMatrix<T> >(c.second, p2);
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?
template <class T>
bool CriticalPair<T>::operator<(CriticalPair<T> &cp2) {
bool CriticalPair::operator<(CriticalPair &cp2) {
if (Degree() < cp2.Degree()) return true;
return false;
}
template <class T>
std::ostream& operator<<(std::ostream& o,
const std::pair<Monomial, PolynomialInMatrix<T> > P) {
const std::pair<Monomial, PolynomialInMatrix> P) {
o << "(" << P.first << "," << P.second << ")";
return o;
}
template <class T>
std::ostream& operator<<(std::ostream& o, const CriticalPair<T> & cp) {
std::ostream& operator<<(std::ostream& o, const CriticalPair& cp) {
o << cp.left_ << " " << cp.right_;
return o;
}
// TODO(pj): improve by merging both lists
template <class T>
std::list<Monomial> CriticalPair<T>::GetMonomials() const {
std::list<Monomial> CriticalPair::GetMonomials() const {
std::list<Monomial> result;
for (const auto& m : left_.second.GetMonomials())
result.push_back(left_.first * m);
......@@ -98,11 +86,10 @@ std::list<Monomial> CriticalPair<T>::GetMonomials() const {
return result;
}
template <class T>
Polynomial<T> CriticalPair<T>::Spolynomial() const {
Polynomial<T> tmp = left_.second.to_polynomial();
Polynomial CriticalPair::Spolynomial() const {
Polynomial tmp = left_.second.to_polynomial();
tmp = tmp * left_.first;
Polynomial<T> R = right_.second.to_polynomial();
Polynomial R = right_.second.to_polynomial();
R = R * right_.first;
R -= tmp;
R.Normalize();
......
......@@ -13,11 +13,10 @@ class NormalStrategy {
public:
// Selects critical pairs to reduce during a step from the current list of
// critical pairs. Removes the selected pairs from the global list.
template <class T>
static std::list<CriticalPair<T> > SelectCriticalPairs(
std::list<CriticalPair<T> > &global_critical_pairs) {
static std::list<CriticalPair> SelectCriticalPairs(
std::list<CriticalPair> &global_critical_pairs) {
unsigned step_degree;
std::list<CriticalPair<T> > step_critical_pairs;
std::list<CriticalPair> step_critical_pairs;
log(LOG_INFO) << "Normal strategy" << std::endl;
step_degree = global_critical_pairs.front().Degree();
......@@ -49,11 +48,10 @@ class SparseStrategy {
// Selects critical pairs to reduce during a step from the current list of
// critical pairs. Removes the selected pairs from the global list.
// TODO(pj): beware of code duplication!
template <class T>
static std::list<CriticalPair<T> > SelectCriticalPairs(
std::list<CriticalPair<T> > &global_critical_pairs) {
static std::list<CriticalPair> SelectCriticalPairs(
std::list<CriticalPair> &global_critical_pairs) {
unsigned step_degree;
std::list<CriticalPair<T> > step_critical_pairs;
std::list<CriticalPair> step_critical_pairs;
step_degree = SparseDegree(global_critical_pairs.front());
for (const auto& current_critical_pair : global_critical_pairs)
......@@ -72,14 +70,12 @@ class SparseStrategy {
}
private:
template <class T>
static unsigned SparseDegree(const CriticalPair<T>&);
static unsigned SparseDegree(const CriticalPair&);
};
std::vector<std::vector<unsigned> > SparseStrategy::linear_forms;
template <class T>
unsigned SparseStrategy::SparseDegree(const CriticalPair<T>& crit_pair) {
unsigned SparseStrategy::SparseDegree(const CriticalPair& crit_pair) {
std::list<Monomial> list_monomials = crit_pair.GetMonomials();
unsigned sparse_deg = 0;
for (const auto& m : list_monomials)
......
......@@ -23,10 +23,10 @@ void field_clear();
template <class T>
void launchF4(std::istream &in, std::ostream &out) {
log(LOG_INFO) << "begin parsing" << std::endl;
Parser<T> parser(in);
std::vector<Polynomial<T> > sys = parser.parse();
Parser parser(in);
std::vector<Polynomial> sys = parser.parse();
log(LOG_INFO) << "parsing done" << std::endl;
std::vector<Polynomial<T> > gb = F4<T>(sys);
std::vector<Polynomial> gb = F4(sys);
for (const auto& f : gb) {
f.Print(out);
out << std::endl;
......
This diff is collapsed.
......@@ -20,27 +20,27 @@ class MatrixFactory {
// TODO(pj): Check that no zero element is added
// TODO(pj): Is the vector of monomials required?
static SpMat* BuildSparseUpperTriangular(
const std::list<std::pair<Monomial, PolynomialInMatrix<GivaroWrapper> > >&,
const std::list<std::pair<Monomial, PolynomialInMatrix> >&,
const std::vector<Monomial>&);
static RowMajMat* BuildRowMajor(
const std::list<std::pair<Monomial, PolynomialInMatrix<GivaroWrapper> > >&,
const std::list<std::pair<Monomial, PolynomialInMatrix> >&,
const std::vector<Monomial>&);
static std::pair<RowMajMat*, RowMajMat*> BuildRowMajor(
const std::set<std::pair<Monomial, PolynomialInMatrix<GivaroWrapper> > >&,
const std::set<std::pair<Monomial, PolynomialInMatrix> >&,
const std::pair<std::vector<Monomial>, std::vector<Monomial> >&);
static RowMajMat* BuildRowMajor(
const std::vector<Polynomial<GivaroWrapper> >&,
const std::vector<Polynomial>&,
const std::vector<Monomial>&);
static std::shared_ptr<MatrixF4> BuildMatrixF4(const std::vector<Polynomial<GivaroWrapper> >&);
static std::shared_ptr<MatrixF4> BuildMatrixF4(const std::vector<Polynomial>&);
// TODO(pj): Arguments should probably be const.
// TODO(pj): shared_ptr should be unique_ptr.
static std::shared_ptr<MatrixF4> BuildMatrixF4(std::list<std::pair<Monomial, PolynomialInMatrix<GivaroWrapper> > >&,
std::list<CriticalPair<GivaroWrapper> >&);
static std::shared_ptr<MatrixF4> BuildMatrixF4(std::list<std::pair<Monomial, PolynomialInMatrix> >&,
std::list<CriticalPair>&);
// Build a storage matrix from a compressed MatrixF4
static std::unique_ptr<StorageMatrix> BuildStorageMatrix1(const MatrixF4&);
......@@ -48,20 +48,20 @@ class MatrixFactory {
};
SpMat* MatrixFactory::BuildSparseUpperTriangular(
const std::list<std::pair<Monomial, PolynomialInMatrix<GivaroWrapper> > >& list_reductors,
const std::list<std::pair<Monomial, PolynomialInMatrix> >& list_reductors,
const std::vector<Monomial>& list_monomials) {
SpMat* R = new SpMat();
R->nb_nonzero_elts_by_row_.clear();
R->row_size_ = list_reductors.size();
R->column_size_ = list_monomials.size();
R->nb_nonzero_elts_by_row_.assign(R->column_size_, 0);
Polynomial<GivaroWrapper> tmp;
Polynomial tmp;
std::map<Monomial, std::size_t> map_mon;
for (std::size_t i = 0; i < list_monomials.size(); ++i)
map_mon.insert(std::pair<Monomial, std::size_t>(list_monomials[i], i));
R->entries_.clear();
std::size_t num_pol = R->row_size_ - 1;
for (typename std::list<std::pair<Monomial, PolynomialInMatrix<GivaroWrapper> > >
for (typename std::list<std::pair<Monomial, PolynomialInMatrix> >
::const_reverse_iterator it = list_reductors.rbegin();
it != list_reductors.rend(); ++it) {
tmp = it->second.to_polynomial();
......@@ -80,10 +80,10 @@ SpMat* MatrixFactory::BuildSparseUpperTriangular(
}
RowMajMat* MatrixFactory::BuildRowMajor(
const std::list<std::pair<Monomial, PolynomialInMatrix<GivaroWrapper> > > &list_reductors,
const std::list<std::pair<Monomial, PolynomialInMatrix> > &list_reductors,
const std::vector<Monomial> &list_monomials) {
RowMajMat* R = new RowMajMat(list_reductors.size(), list_monomials.size());
Polynomial<GivaroWrapper> tmp;
Polynomial tmp;
std::map<Monomial, std::size_t> map_mon;
for (std::size_t i = 0; i < list_monomials.size(); ++i)
map_mon.insert(std::pair<Monomial, std::size_t>(list_monomials[i], i));
......@@ -100,12 +100,12 @@ RowMajMat* MatrixFactory::BuildRowMajor(
}
std::pair<RowMajMat*,RowMajMat*> MatrixFactory::BuildRowMajor(
const std::set<std::pair<Monomial, PolynomialInMatrix<GivaroWrapper> > >& set_pols,
const std::set<std::pair<Monomial, PolynomialInMatrix> >& set_pols,
const std::pair<std::vector<Monomial>,std::vector<Monomial> >& list_monomials) {
RowMajMat* C = new RowMajMat(set_pols.size(), list_monomials.first.size());
RowMajMat* D = new RowMajMat(set_pols.size(), list_monomials.second.size());
Polynomial<GivaroWrapper> tmp;
Polynomial tmp;
// map which sends a monomial to the corresponding column number of C or D
// (according to the value of the flag).
std::map<Monomial, std::pair<bool, std::size_t> > map_mon;
......@@ -164,7 +164,7 @@ std::pair<RowMajMat*,RowMajMat*> MatrixFactory::BuildRowMajor(
}
RowMajMat* MatrixFactory::BuildRowMajor(
const std::vector<Polynomial<GivaroWrapper> >& list_pols,
const std::vector<Polynomial>& list_pols,
const std::vector<Monomial>& list_monomials) {
RowMajMat* R = new RowMajMat(list_pols.size(), list_monomials.size());
std::map<Monomial, std::size_t> map_mon;
......@@ -177,7 +177,7 @@ RowMajMat* MatrixFactory::BuildRowMajor(
return R;
}
std::shared_ptr<MatrixF4> MatrixFactory::BuildMatrixF4(const std::vector<Polynomial<GivaroWrapper> > &_PP) {
std::shared_ptr<MatrixF4> MatrixFactory::BuildMatrixF4(const std::vector<Polynomial> &_PP) {
std::shared_ptr<MatrixF4> ans(new MatrixF4());
ans->Asize = 0;
ans->row_size_ = _PP.size();
......@@ -203,8 +203,8 @@ std::shared_ptr<MatrixF4> MatrixFactory::BuildMatrixF4(const std::vector<Polynom
return ans;
}
std::shared_ptr<MatrixF4> MatrixFactory::BuildMatrixF4(std::list<std::pair<Monomial, PolynomialInMatrix<GivaroWrapper> > >& _PP,
std::list<CriticalPair<GivaroWrapper> >& critpairP) {
std::shared_ptr<MatrixF4> MatrixFactory::BuildMatrixF4(std::list<std::pair<Monomial, PolynomialInMatrix> >& _PP,
std::list<CriticalPair>& critpairP) {
std::shared_ptr<MatrixF4> ans(new MatrixF4());
ans->Asize = _PP.size();
std::map<Monomial, std::size_t> vvM;
......@@ -266,7 +266,7 @@ std::shared_ptr<MatrixF4> MatrixFactory::BuildMatrixF4(std::list<std::pair<Monom
}
delete ans->A;
ans->A = nullptr;
std::set<std::pair<Monomial, PolynomialInMatrix<GivaroWrapper> > > set_pols;
std::set<std::pair<Monomial, PolynomialInMatrix> > set_pols;
for (const auto& it : critpairP) {
set_pols.insert(it.left());
......
......@@ -12,25 +12,23 @@
namespace tinygb {
template<class T>
class Parser {
std::istream& in_stream;
public:
explicit Parser(std::istream& _s): in_stream(_s) {}
std::vector<Polynomial<T> > parse() const;
std::vector<Polynomial> parse() const;
};
template <class T>
std::vector<Polynomial<T> > Parser<T>::parse() const {
std::vector<Polynomial<T> > res;
std::vector<Polynomial> Parser::parse() const {
std::vector<Polynomial> res;
std::string s;
unsigned c;
expo_int *exp = new expo_int[NB_VARS];
while (in_stream >> s) {
Polynomial<T> p;
Polynomial p;
while (s != ";") {
T e(s);
GivaroWrapper e(s);
for (std::size_t i = 0; i < NB_VARS; ++i) {
in_stream >> s;
c = (expo_int)atoi(s.c_str());
......
......@@ -5,19 +5,13 @@
#include <utility>
#include "./common.h"
#include "./monomial.h"
#include "./givaro_wrapper.h"
namespace tinygb {
template<class T>
class Polynomial;
template<class T>
std::ostream& operator<<(std::ostream &o, const Polynomial<T> &p);
template<class T>
class Polynomial {
public:
typedef std::pair<Monomial, T> Term;
typedef std::pair<Monomial, GivaroWrapper> Term;
Polynomial() {
terms_ = std::list<Term>();
......@@ -38,8 +32,8 @@ class Polynomial {
terms_.clear();
}
void insert(Monomial m, T e) {
terms_.push_back(std::pair<Monomial, T>(m, e));
void insert(Monomial m, GivaroWrapper e) {
terms_.push_back(std::pair<Monomial, GivaroWrapper>(m, e));
}
// Assumes that the polynomial's list of terms is normalized
......@@ -48,7 +42,7 @@ class Polynomial {
return terms_.back().first;
}
const T& LeadingCoefficient() const {
const GivaroWrapper& LeadingCoefficient() const {
return terms_.back().second;
}
......@@ -71,15 +65,15 @@ class Polynomial {
// Assumes that terms_ is normalized.
bool IsTopReducibleBy(const Polynomial &) const;
Polynomial<T> operator*(const Monomial&) const;
void operator+=(const Polynomial<T>&);
void operator-=(const Polynomial<T>&);
void operator*=(const T&);
void operator/=(const T&);
Polynomial operator*(const Monomial&) const;
void operator+=(const Polynomial&);
void operator-=(const Polynomial&);
void operator*=(const GivaroWrapper&);
void operator/=(const GivaroWrapper&);
void Print(std::ostream& out) const;
inline bool operator<(const Polynomial<T>& P) const;
inline bool operator<(const Polynomial& P) const;
friend std::ostream& operator<< <T>(std::ostream&, const Polynomial<T>&);
friend std::ostream& operator<<(std::ostream&, const Polynomial&);
private:
// Adds coefficients of consecutive terms if they share the same monomials.
......@@ -92,20 +86,17 @@ class Polynomial {
void RemoveZeroTerms();
std::list<Term> terms_;
};
template<class T>
void Polynomial<T>::RemoveZeroTerms() {
void Polynomial::RemoveZeroTerms() {
for (auto it = terms_.begin(); it != terms_.end(); ++it) {
while (it != terms_.end() && it->second == T(0))
while (it != terms_.end() && it->second == GivaroWrapper(0))
it = terms_.erase(it);
}
}
template<class T>
void Polynomial<T>::CombineMonomials() {
typename std::list<std::pair<Monomial, T> >::iterator it2;
void Polynomial::CombineMonomials() {
typename std::list<std::pair<Monomial, GivaroWrapper> >::iterator it2;
for (auto it1 = terms_.begin(); it1 != terms_.end();) {
it2 = it1;
++it1;
......@@ -118,25 +109,22 @@ void Polynomial<T>::CombineMonomials() {
}
}
template<class T>
void Polynomial<T>::DivideByLeadingCoefficient() {
T leading_coefficient = terms_.back().second;
assert(leading_coefficient != T(0));
void Polynomial::DivideByLeadingCoefficient() {
GivaroWrapper leading_coefficient = terms_.back().second;
assert(leading_coefficient != GivaroWrapper(0));
leading_coefficient.inv();
if (leading_coefficient == T(1)) return;
if (leading_coefficient == GivaroWrapper(1)) return;
for (auto& it : terms_)
it.second *= leading_coefficient;
}
template<class T>
void Polynomial<T>::Normalize() {
void Polynomial::Normalize() {
terms_.sort();
CombineMonomials();
RemoveZeroTerms();
}
template<class T>
bool Polynomial<T>::TopReductionBy(const Polynomial &g) {
bool Polynomial::TopReductionBy(const Polynomial &g) {
assert(!g.IsEmpty());
if (IsEmpty()) return false;
if (!LeadingMonomial().IsDivisibleBy(g.LeadingMonomial())) return false;
......@@ -147,15 +135,13 @@ bool Polynomial<T>::TopReductionBy(const Polynomial &g) {
return true;
}
template<class T>
bool Polynomial<T>::IsTopReducibleBy(const Polynomial<T> &g) const {
bool Polynomial::IsTopReducibleBy(const Polynomial &g) const {
assert(!g.IsEmpty());
if (IsEmpty()) return false;
return LeadingMonomial().IsDivisibleBy(g.LeadingMonomial());
}
template<class T>
Polynomial<T> Polynomial<T>::operator*(const Monomial &m) const {
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_)
......@@ -163,28 +149,24 @@ Polynomial<T> Polynomial<T>::operator*(const Monomial &m) const {
return R;
}
template<class T>
void Polynomial<T>::operator+=(const Polynomial<T> &P) {
void Polynomial::operator+=(const Polynomial &P) {
std::list<Term> tmp_terms = P.terms_;
terms_.merge(tmp_terms);
CombineMonomials();
RemoveZeroTerms();
}
template<class T>
void Polynomial<T>::operator*=(const T &e) {
void Polynomial::operator*=(const GivaroWrapper &e) {
for (auto& it : terms_)
it.second *= e;
}
template<class T>
void Polynomial<T>::operator/=(const T& e) {
void Polynomial::operator/=(const GivaroWrapper& e) {
for (auto& it : terms_)
it.second /= e;
}
template <class T>
void Polynomial<T>::operator-=(const Polynomial<T>& P) {
void Polynomial::operator-=(const Polynomial& P) {
std::list<Term> tmp_terms = P.terms_;
for (auto& it : tmp_terms)
it.second.neg();
......@@ -193,8 +175,7 @@ void Polynomial<T>::operator-=(const Polynomial<T>& P) {
RemoveZeroTerms();
}
template <class T>
void Polynomial<T>::Print(std::ostream& o) const {
void Polynomial::Print(std::ostream& o) const {
for (const auto& it : terms_) {
o << it.second << " ";
it.first.Print(o);
......@@ -203,27 +184,25 @@ void Polynomial<T>::Print(std::ostream& o) const {
o << ";";
}
template <class T>
std::ostream& operator<<(std::ostream& o, const Polynomial<T>& P) {
std::ostream& operator<<(std::ostream& o, const Polynomial& P) {
if (P.IsEmpty()) {
o << "0";
return o;
}
// TODO(pj) : improve printing of polynomial and monomial
typename std::list<typename Polynomial<T>::Term>::const_iterator it = P.terms_.begin();
typename std::list<typename Polynomial::Term>::const_iterator it = P.terms_.begin();
if (it == P.terms_.end())
return o;
if (it->second != T(0))
if (it->second != GivaroWrapper(0))
o << it->second << " " << it->first;
++it;
for (; it != P.terms_.end() ; ++it)
if (it->second != T(0))
if (it->second != GivaroWrapper(0))
o << "+" << it->second << " " << it->first;
return o;
}
template <class T>
inline bool Polynomial<T>::operator<(const Polynomial<T>& P) const {
inline bool Polynomial::operator<(const Polynomial& P) const {
return LeadingMonomial() < P.LeadingMonomial();
}
} // namespace tinygb
......
......@@ -7,13 +7,12 @@
#include <vector>
#include "./common.h"
#include "./givaro_wrapper.h"
#include "linalg/storage_matrix.h"
#include "./monomial.h"
#include "./polynomial.h"
#include "linalg/storage_matrix.h"
namespace tinygb {
template <class T>
class PolynomialInMatrix {
public:
PolynomialInMatrix() : M_(nullptr), row_(0), nb_monoms_(0) {}
......@@ -26,14 +25,14 @@ class PolynomialInMatrix {
nb_monoms_++;
}
PolynomialInMatrix(const PolynomialInMatrix<T> &p)
PolynomialInMatrix(const PolynomialInMatrix &p)
: M_(p.M_), row_(p.row_), nb_monoms_(p.nb_monoms_) {}
inline Monomial LeadingMonomial() const {
return M_->LeadingMonomial(row_);
}
Polynomial<T> to_polynomial() const;
Polynomial to_polynomial() const;
// FIXME(pj): this only works for degree orderings.
inline unsigned Degree() const {
......@@ -42,11 +41,11 @@ class PolynomialInMatrix {
// Returns true if the object is top reducible by one of the polynomials in
// the argument.
bool IsTopReducible(const std::vector<PolynomialInMatrix<T> >&) const;
bool IsTopReducible(const std::vector<PolynomialInMatrix>&) const;
// Converts a StorageMatrix to the vector of polynomials
// corresponding to the list of rows of the matrix
static std::vector<PolynomialInMatrix<T> >
static std::vector<PolynomialInMatrix>
MakeSystemOfPolynomialsInMatrix(const std::shared_ptr<const StorageMatrix>&);
// Merges the first argument with the set of monomials occuring with nonzero
......@@ -69,18 +68,14 @@ class PolynomialInMatrix {
std::size_t row_;
std::size_t nb_monoms_;
template <class U>
friend std::ostream& operator<<(std::ostream&, const PolynomialInMatrix<U>&);
friend std::ostream& operator<<(std::ostream&, const PolynomialInMatrix&);
template <class U>
friend bool operator<(
const std::pair<Monomial, PolynomialInMatrix<U> >&,
const std::pair<Monomial, PolynomialInMatrix<U> >&);
friend bool operator<(const std::pair<Monomial, PolynomialInMatrix>&,
const std::pair<Monomial, PolynomialInMatrix>&);
};
template<class T>
Polynomial<T> PolynomialInMatrix<T>::to_polynomial() const {
Polynomial<T> P;
Polynomial PolynomialInMatrix::to_polynomial() const {
Polynomial P;
P.SetToZero();
P.insert(M_->LeadingMonomial(row_), 1);
for (unsigned j = 0; j < M_->column_size(); ++j)
......@@ -91,17 +86,15 @@ Polynomial<T> PolynomialInMatrix<T>::to_polynomial() const {
return P;
}
template<class T>
std::ostream& operator<<(std::ostream &o, const PolynomialInMatrix<T> &P) {
Polynomial<T> p = P.to_polynomial();
std::ostream& operator<<(std::ostream &o, const PolynomialInMatrix &P) {
Polynomial p = P.to_polynomial();
return o << p;
}
template<class T>
std::vector<PolynomialInMatrix<T> >
PolynomialInMatrix<T>::MakeSystemOfPolynomialsInMatrix(const std::shared_ptr<const StorageMatrix>& pM) {
std::vector<PolynomialInMatrix<T> > system;
PolynomialInMatrix<T> polynomial;
std::vector<PolynomialInMatrix>
PolynomialInMatrix::MakeSystemOfPolynomialsInMatrix(const std::shared_ptr<const StorageMatrix>& pM) {
std::vector<PolynomialInMatrix> system;
PolynomialInMatrix polynomial;
for (std::size_t i = 0; i < pM->row_size(); ++i) {
polynomial = PolynomialInMatrix(pM, i);
system.push_back(polynomial);
......@@ -109,8 +102,7 @@ PolynomialInMatrix<T>::MakeSystemOfPolynomialsInMatrix(const std::shared_ptr<con
return system;
}
template <class T>
std::list<Monomial> PolynomialInMatrix<T>::GetMonomials() const {
std::list<Monomial> PolynomialInMatrix::GetMonomials() const {
std::list<Monomial> result;
result.push_back(M_->LeadingMonomial(row_));
for (std::size_t j = 0; j < M_->column_size(); ++j)
......@@ -119,8 +111,7 @@ std::list<Monomial> PolynomialInMatrix<T>::GetMonomials() const {
return result;
}
template<class T>
void PolynomialInMatrix<T>::AddMonomialsMultipliedByCofactor(
void PolynomialInMatrix::AddMonomialsMultipliedByCofactor(
std::set<Monomial> &monomial_set,
const Monomial &factor) const {
Monomial current_monomial;
......@@ -132,18 +123,16 @@ void PolynomialInMatrix<T>::AddMonomialsMultipliedByCofactor(
}
}
template<class T>
bool PolynomialInMatrix<T>::IsTopReducible(
const std::vector<PolynomialInMatrix<T> >& system) const {
bool PolynomialInMatrix::IsTopReducible(
const std::vector<PolynomialInMatrix>& system) const {
for (std::size_t i = 0; i < system.size(); ++i)
if (LeadingMonomial().IsDivisibleBy(system[i].LeadingMonomial()))
return true;
return false;
}
template<class T>
bool operator<(const std::pair<Monomial, PolynomialInMatrix<T> >& cp1,
const std::pair<Monomial, PolynomialInMatrix<T> >& cp2) {
bool operator<(const std::pair<Monomial, PolynomialInMatrix>& cp1,
const std::pair<Monomial, PolynomialInMatrix>& cp2) {
if (cp1.first < cp2.first) return true;
if (cp2.first < cp1.first) return false;
if (cp1.second.M_ < cp2.second.M_) return true;
......@@ -156,6 +145,7 @@ bool operator<(const std::pair<Monomial, PolynomialInMatrix<T> >& cp1,
return false;
return false;
}
} // namespace tinygb
#endif // POLYNOMIAL_IN_MATRIX_H_
#include "./utils.h"
#include "./critical_pair.h"
namespace tinygb {
......@@ -21,6 +22,7 @@ void SaveCritPairs(const std::string &filename,
const std::vector<CriticalPair> &vCrit,
bool append)
{
log(LOG_INFO) << "Saving critical pairs" << std::endl;
std::ofstream file;
if (append)