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;
......
......@@ -50,8 +50,7 @@ bool HasAllPowersOfVars(const std::set<Monomial>& S) {
}
// Tests whether a GB is minimal.
template <class T>
bool IsMinimalGB(const std::vector<Polynomial<T> > &gb) {
bool IsMinimalGB(const std::vector<Polynomial> &gb) {
for (auto i = gb.begin(); i != gb.end(); ++i)
for (auto j = gb.begin(); j != gb.end(); ++j)
if (i != j && i->LeadingMonomial().IsDivisibleBy(j->LeadingMonomial()))
......@@ -60,8 +59,7 @@ bool IsMinimalGB(const std::vector<Polynomial<T> > &gb) {
}
// Removes polynomials in G such that their leading monomial is a multiple of m.
template <class T>
void RemoveRedundantPolynomials(std::vector<PolynomialInMatrix<T> > &gb,
void RemoveRedundantPolynomials(std::vector<PolynomialInMatrix> &gb,
const Monomial& m) {
for (auto it = gb.begin(); it != gb.end(); ++it) {
if (it->LeadingMonomial().IsDivisibleBy(m)) {
......@@ -75,10 +73,9 @@ void RemoveRedundantPolynomials(std::vector<PolynomialInMatrix<T> > &gb,
// in Vanessa Vitse's thesis).
// Inserts a polynomial f in the Grobner basis G and updates the list of
// critical pairs using Gebauer/Moller algorithm.
template <class T>
void InsertPolynomialGebauerMoller(std::list<CriticalPair<T> > &global_critical_pairs,
std::vector<PolynomialInMatrix<T> > &gb,
const PolynomialInMatrix<T> &f) {
void InsertPolynomialGebauerMoller(std::list<CriticalPair> &global_critical_pairs,
std::vector<PolynomialInMatrix> &gb,
const PolynomialInMatrix &f) {
for (auto it = global_critical_pairs.begin(); it != global_critical_pairs.end(); ++it) {
// TODO(pj): unclear, simplify.
if (it->LCM() != Monomial::LCM(it->left().second.LeadingMonomial(), f.LeadingMonomial()) &&
......@@ -89,17 +86,17 @@ void InsertPolynomialGebauerMoller(std::list<CriticalPair<T> > &global_critical_
it--;
}
}
std::vector<CriticalPair<T> > S0, S1, S2;
std::vector<CriticalPair> S0, S1, S2;
for (const auto& g : gb) {
if (Monomial::LCM(g.LeadingMonomial(), f.LeadingMonomial()) ==
g.LeadingMonomial() * f.LeadingMonomial())
S0.push_back(CriticalPair<T>(f, g));
S0.push_back(CriticalPair(f, g));
else
S1.push_back(CriticalPair<T>(f, g));
S1.push_back(CriticalPair(f, g));
}
while (!S1.empty()) {
// TODO(pj): why selecting last critpair in S1?
CriticalPair<T> cp1 = S1[S1.size() - 1];
CriticalPair cp1 = S1[S1.size() - 1];
S1.erase(S1.end()-1);
bool flag = false;
Monomial tmp_lcm = cp1.LCM();
......@@ -139,10 +136,9 @@ void InsertPolynomialGebauerMoller(std::list<CriticalPair<T> > &global_critical_
// Interreduces a list of polynomials (given via the variable system) using
// linear algebra. The result is stored in an F4 matrix which is added to list_matrices and
// a list of pointers to the corresponding polynomials are returned.
template <class T>
std::list<PolynomialInMatrix<T> > Interreduce(
std::list<PolynomialInMatrix> Interreduce(
std::vector<std::shared_ptr<const StorageMatrix> >& list_matrices,
const std::vector<Polynomial<T> >& system) {
const std::vector<Polynomial>& system) {
log(LOG_INFO) << "interreducing --- ";
// Makes the system monic.
auto system_copy = system;
......@@ -152,10 +148,10 @@ std::list<PolynomialInMatrix<T> > Interreduce(
M->RowEchelon();
std::shared_ptr<const StorageMatrix> p_current_storage_matrix = MatrixFactory::BuildStorageMatrix2(*M);
p_current_storage_matrix->Store("matrices/gb_" + p_current_storage_matrix->id() + ".mat");
auto result = PolynomialInMatrix<T>::MakeSystemOfPolynomialsInMatrix(p_current_storage_matrix);
auto result = PolynomialInMatrix::MakeSystemOfPolynomialsInMatrix(p_current_storage_matrix);
list_matrices.push_back(std::move(p_current_storage_matrix));
// Converts from a vector to a list.
return std::list<PolynomialInMatrix<T> >(result.begin(), result.end());
return std::list<PolynomialInMatrix>(result.begin(), result.end());
}
// Selects reductors to reduce a list of critical pairs. step_critical_pairs
......@@ -163,22 +159,21 @@ std::list<PolynomialInMatrix<T> > Interreduce(
// algorithm. step_reductors contains the output, i.e. a list of pairs of
// monomials and polynomials which are global reductors.
// TODO(pj): simplify and decompose.
template <class T>
std::vector<std::pair<Monomial, PolynomialInMatrix<T> > > SelectReductors(
const std::list<CriticalPair<T> >& step_critical_pairs,
const std::list<PolynomialInMatrix<T> >& global_reductors) {
std::vector<std::pair<Monomial, PolynomialInMatrix> > SelectReductors(
const std::list<CriticalPair>& step_critical_pairs,
const std::list<PolynomialInMatrix>& global_reductors) {
// Vector of selected reductors for this step.
timer_reductors_selection.Start();
std::vector<std::pair<Monomial, PolynomialInMatrix<T> > > step_reductors;
std::vector<std::pair<Monomial, PolynomialInMatrix> > step_reductors;
// Current reductor to be inserted in step_reductors.
PolynomialInMatrix<T> reductor;
PolynomialInMatrix reductor;
// Pointer to the best reductor found so far.
typename std::list<PolynomialInMatrix<T> >::const_iterator p_best_reductor;
typename std::list<PolynomialInMatrix>::const_iterator p_best_reductor;
// All the monomials that need to be reduced
std::set<Monomial> all_monomials;
for (const auto& current_critical_pair : step_critical_pairs) {
Polynomial<T> tmp = current_critical_pair.left().second.to_polynomial();
Polynomial tmp = current_critical_pair.left().second.to_polynomial();
tmp = tmp * current_critical_pair.left().first;
for (const auto& term : tmp.terms())
all_monomials.insert(term.first);
......@@ -211,9 +206,9 @@ std::vector<std::pair<Monomial, PolynomialInMatrix<T> > > SelectReductors(
}
}
if (flag) {
reductor = PolynomialInMatrix<T>(*p_best_reductor);
reductor = PolynomialInMatrix(*p_best_reductor);
auto current_step_reductor =
std::pair<Monomial, PolynomialInMatrix<T> >(m/reductor.LeadingMonomial(),
std::pair<Monomial, PolynomialInMatrix>(m/reductor.LeadingMonomial(),
reductor);
step_reductors.push_back(current_step_reductor);
reductor.AddMonomialsMultipliedByCofactor(all_monomials,
......@@ -230,20 +225,19 @@ std::vector<std::pair<Monomial, PolynomialInMatrix<T> > > SelectReductors(
}
// Toplevel F4.
// template parameter T is the base field.
// template parameter S is the selection strategy for critical pairs.
template <class T, class S = NormalStrategy>
std::vector<Polynomial<T> > F4(const std::vector<Polynomial<T> >& system) {
template <class S = NormalStrategy>
std::vector<Polynomial> F4(const std::vector<Polynomial>& system) {
log(LOG_INFO) << "Starting F4: " << std::endl;
timer_globalF4.Start();
std::vector<PolynomialInMatrix<T> > gb;
std::list <CriticalPair<T> > global_critical_pairs;
std::list <CriticalPair<T> > step_critical_pairs;
std::list <PolynomialInMatrix<T> > global_reductors;
std::vector<PolynomialInMatrix> gb;
std::list <CriticalPair> global_critical_pairs;
std::list <CriticalPair> step_critical_pairs;
std::list <PolynomialInMatrix> global_reductors;
std::vector<std::shared_ptr<const StorageMatrix> > list_F4_matrices;
std::list<PolynomialInMatrix<T> > gb_init =
std::list<PolynomialInMatrix> gb_init =
Interreduce(list_F4_matrices, system);
for (const auto& it : gb_init) {
......@@ -254,9 +248,9 @@ std::vector<Polynomial<T> > F4(const std::vector<Polynomial<T> >& system) {
unsigned step_number = 1;
log(LOG_INFO) << "Initialization done" << std::endl;
std::vector<PolynomialInMatrix<T> > new_reduced_polynomials1;
std::vector<PolynomialInMatrix<T> > new_reduced_polynomials2;
std::vector<PolynomialInMatrix<T> > new_polynomials_in_gb;
std::vector<PolynomialInMatrix> new_reduced_polynomials1;
std::vector<PolynomialInMatrix> new_reduced_polynomials2;
std::vector<PolynomialInMatrix> new_polynomials_in_gb;
std::set<Monomial> GB_LeadingMonomials;
for (const auto& g : gb)
......@@ -286,7 +280,7 @@ std::vector<Polynomial<T> > F4(const std::vector<Polynomial<T> >& system) {
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<T> > > list_step_reductors;
std::list<std::pair<Monomial, PolynomialInMatrix> > list_step_reductors;
list_step_reductors.insert(list_step_reductors.begin(),
step_reductors.begin(),
step_reductors.end());
......@@ -322,7 +316,7 @@ std::vector<Polynomial<T> > F4(const std::vector<Polynomial<T> >& system) {
p_current_storage_matrix1->Store("matrices/red_" + p_current_storage_matrix1->id() + ".mat");
new_reduced_polynomials1 =
PolynomialInMatrix<T>::MakeSystemOfPolynomialsInMatrix(p_current_storage_matrix1);
PolynomialInMatrix::MakeSystemOfPolynomialsInMatrix(p_current_storage_matrix1);
list_F4_matrices.push_back(p_current_storage_matrix1);
global_reductors.insert(global_reductors.begin(),
......@@ -334,7 +328,7 @@ std::vector<Polynomial<T> > F4(const std::vector<Polynomial<T> >& system) {
p_current_storage_matrix1->Store("matrices/gb_" + p_current_storage_matrix1->id() + ".mat");
new_reduced_polynomials2 =
PolynomialInMatrix<T>::MakeSystemOfPolynomialsInMatrix(p_current_storage_matrix2);
PolynomialInMatrix::MakeSystemOfPolynomialsInMatrix(p_current_storage_matrix2);
list_F4_matrices.push_back(p_current_storage_matrix2);
global_reductors.insert(global_reductors.begin(),
new_reduced_polynomials2.begin(),
......@@ -385,13 +379,13 @@ std::vector<Polynomial<T> > F4(const std::vector<Polynomial<T> >& system) {
log(LOG_INFO) << "------------ cleaning reductors -----------" << std::endl;
global_reductors.clear();
std::vector<Polynomial<T> > final_gb;
std::vector<Polynomial> final_gb;
for (const auto& f : gb)
final_gb.push_back(f.to_polynomial());
std::sort(final_gb.begin(), final_gb.end());
std::reverse(final_gb.begin(), final_gb.end());
log(LOG_DEBUG) << "Is minimal: " << IsMinimalGB<T>(final_gb) << 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;
......
......@@ -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&