[mathicgb] 375/393: Starting clean-up of interface of Poly.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:36 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch upstream
in repository mathicgb.

commit a71ec547a7b9472ed51621921efa35a04355c520
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date:   Wed Sep 18 13:02:08 2013 +0200

    Starting clean-up of interface of Poly.
---
 src/mathicgb.cpp                  |   4 +-
 src/mathicgb/ClassicGBAlg.cpp     |   6 +-
 src/mathicgb/Poly.cpp             | 164 +++++++++++---------------------------
 src/mathicgb/Poly.hpp             |  45 +++++------
 src/mathicgb/PolyBasis.cpp        |   2 +-
 src/mathicgb/ReducerDedup.cpp     |   2 +-
 src/mathicgb/ReducerHash.cpp      |   2 +-
 src/mathicgb/ReducerHashPack.cpp  |   2 +-
 src/mathicgb/ReducerNoDedup.cpp   |   2 +-
 src/mathicgb/ReducerPackDedup.cpp |   2 +-
 src/mathicgb/SigPolyBasis.cpp     |   4 +-
 src/mathicgb/SignatureGB.cpp      |   3 +-
 src/mathicgb/StaticMonoMap.hpp    |  12 +--
 src/test/poly-test.cpp            |  88 --------------------
 14 files changed, 87 insertions(+), 251 deletions(-)

diff --git a/src/mathicgb.cpp b/src/mathicgb.cpp
index a56a8ea..e32993d 100755
--- a/src/mathicgb.cpp
+++ b/src/mathicgb.cpp
@@ -800,7 +800,7 @@ namespace mgbi {
   size_t IdealAdapter::termCount(PolyIndex poly) const {
     MATHICGB_ASSERT(mPimpl->basis.get() != 0);
     MATHICGB_ASSERT(poly < mPimpl->basis->size());
-    return mPimpl->basis->getPoly(poly)->nTerms();
+    return mPimpl->basis->getPoly(poly)->termCount();
   }
 
   auto IdealAdapter::term(
@@ -812,7 +812,7 @@ namespace mgbi {
 
     const auto& monoid = mPimpl->basis->ring().monoid();
     const auto& p = *mPimpl->basis->getPoly(poly);
-    MATHICGB_ASSERT(term < p.nTerms());
+    MATHICGB_ASSERT(term < p.termCount());
     MATHICGB_ASSERT(p.ring().monoid() == monoid);
 
     const auto& from = p.monomialAt(term);
diff --git a/src/mathicgb/ClassicGBAlg.cpp b/src/mathicgb/ClassicGBAlg.cpp
index f93efaa..b30b0d0 100755
--- a/src/mathicgb/ClassicGBAlg.cpp
+++ b/src/mathicgb/ClassicGBAlg.cpp
@@ -137,7 +137,7 @@ void ClassicGBAlg::insertReducedPoly(
     } else {
       mRing.printMonomialFrobbyM2Format
         (std::cerr, polyToInsert->getLeadMonomial());
-      if (polyToInsert->nTerms() > 1)
+      if (polyToInsert->termCount() > 1)
         std::cerr << " + [...]";
       std::cerr << std::endl;
     }
@@ -281,8 +281,8 @@ void ClassicGBAlg::step() {
     const std::unique_ptr<Poly>& a,
     const std::unique_ptr<Poly>& b
   ) {
-    const auto aTermCount = a->nTerms();
-    const auto bTermCount = b->nTerms();
+    const auto aTermCount = a->termCount();
+    const auto bTermCount = b->termCount();
     if (aTermCount < bTermCount)
       return true;
     if (aTermCount > bTermCount)
diff --git a/src/mathicgb/Poly.cpp b/src/mathicgb/Poly.cpp
index 80939b3..264a1a8 100755
--- a/src/mathicgb/Poly.cpp
+++ b/src/mathicgb/Poly.cpp
@@ -17,13 +17,11 @@ MATHICGB_NAMESPACE_BEGIN
 //   where len = r
 // MAJOR ASSUMPTION: the monomials are ordered in descending order!!
 
-void Poly::copy(Poly &result) const
-{
-  result.R = R;
-  result.coeffs.resize(coeffs.size());
-  result.monoms.resize(monoms.size());
-  std::copy(coeffs.begin(), coeffs.end(), result.coeffs.begin());
-  std::copy(monoms.begin(), monoms.end(), result.monoms.begin());
+Poly& Poly::operator=(Poly&& poly) {
+  MATHICGB_ASSERT(&ring() == &poly.ring());
+  coeffs = std::move(poly.coeffs);
+  monoms = std::move(poly.monoms);
+  return *this;
 }
 
 void Poly::sortTermsDescending() {
@@ -32,23 +30,23 @@ void Poly::sortTermsDescending() {
     Cmp(const Poly& poly): mPoly(poly) {}
 
     bool operator()(size_t a, size_t b) {
-      MATHICGB_ASSERT(a < mPoly.nTerms());
-      MATHICGB_ASSERT(b < mPoly.nTerms());
-      return mPoly.R->monomialLT(mPoly.monomialAt(b), mPoly.monomialAt(a));
+      MATHICGB_ASSERT(a < mPoly.termCount());
+      MATHICGB_ASSERT(b < mPoly.termCount());
+      return mPoly.ring().monomialLT(mPoly.monomialAt(b), mPoly.monomialAt(a));
     }
 
   private:
     const Poly& mPoly;
   };
 
-  const size_t count = nTerms();
+  const size_t count = termCount();
   std::vector<size_t> ordered(count);
   for (size_t i = 0; i < count; ++i)
     ordered[i] = i;
 
   std::sort(ordered.begin(), ordered.end(), Cmp(*this));
 
-  Poly poly(*R);
+  Poly poly(ring());
   for (size_t i = 0; i < count; ++i)
     poly.appendTerm(coefficientAt(ordered[i]), monomialAt(ordered[i]));
   *this = std::move(poly);
@@ -57,22 +55,22 @@ void Poly::sortTermsDescending() {
 }
 
 monomial Poly::monomialAt(size_t index) {
-  MATHICGB_ASSERT(index < nTerms());
-  return &monoms[index * R->maxMonomialSize()];
+  MATHICGB_ASSERT(index < termCount());
+  return &monoms[index * ring().maxMonomialSize()];
 }
 
 const_monomial Poly::monomialAt(size_t index) const {
-  MATHICGB_ASSERT(index < nTerms());
-  return &monoms[index * R->maxMonomialSize()];
+  MATHICGB_ASSERT(index < termCount());
+  return &monoms[index * ring().maxMonomialSize()];
 }
 
 coefficient& Poly::coefficientAt(size_t index) {
-  MATHICGB_ASSERT(index < nTerms());
+  MATHICGB_ASSERT(index < termCount());
   return coeffs[index];
 }
 
 const coefficient Poly::coefficientAt(size_t index) const {
-  MATHICGB_ASSERT(index < nTerms());
+  MATHICGB_ASSERT(index < termCount());
   return coeffs[index];
 }
 
@@ -82,7 +80,7 @@ void Poly::append(iterator &first, iterator &last)
     appendTerm(first.getCoefficient(), first.getMonomial());
 }
 
-Poly *Poly::copy() const
+/*Poly *Poly::copy() const
 {
   Poly *const_this = const_cast<Poly *>(this);
   Poly *result = new Poly(*R);
@@ -90,36 +88,36 @@ Poly *Poly::copy() const
   iterator b = const_this->end();
   result->append(a,b);
   return result;
-}
+}*/
 
 void Poly::multByCoefficient(coefficient c)
 {
   for (std::vector<coefficient>::iterator i = coeffs.begin(); i != coeffs.end(); i++)
-    R->coefficientMultTo(*i, c);
+    ring().coefficientMultTo(*i, c);
 }
 
 bool Poly::isMonic() const {
-  return !isZero() && R->coefficientIsOne(getLeadCoefficient());
+  return !isZero() && ring().coefficientIsOne(getLeadCoefficient());
 }
 
 void Poly::makeMonic() {
   if (isZero())
     return;
   coefficient c = getLeadCoefficient();
-  if (R->coefficientIsOne(c))
+  if (ring().coefficientIsOne(c))
     return;
-  R->coefficientReciprocalTo(c);
+  ring().coefficientReciprocalTo(c);
   for (auto i = coeffs.begin(); i != coeffs.end(); i++)
-    R->coefficientMultTo(*i, c);
-  MATHICGB_ASSERT(R->coefficientIsOne(getLeadCoefficient()));
+    ring().coefficientMultTo(*i, c);
+  MATHICGB_ASSERT(ring().coefficientIsOne(getLeadCoefficient()));
 }
 
 bool operator==(const Poly &a, const Poly &b)
 {
-  const PolyRing* R = a.getRing();
-  if (R != b.getRing())
+  const auto& ring = a.ring();
+  if (&a.ring() != &b.ring())
     return false;
-  if (a.nTerms() != b.nTerms())
+  if (a.termCount() != b.termCount())
     return false;
   Poly::const_iterator a1 = a.begin();
   Poly::const_iterator b1 = b.begin();
@@ -127,82 +125,15 @@ bool operator==(const Poly &a, const Poly &b)
     {
       if (a1.getCoefficient() != b1.getCoefficient())
         return false;
-      if (!R->monomialEQ(a1.getMonomial(), b1.getMonomial()))
+      if (!ring.monomialEQ(a1.getMonomial(), b1.getMonomial()))
         return false;
     }
   return true;
 }
 
-Poly * Poly::add(const PolyRing *R,
-                 iterator i,
-                 iterator iend,
-                 iterator j,
-                 iterator jend,
-                 size_t &n_compares)
-{
-  coefficient c;
-  n_compares = 0;
-  Poly *result = new Poly(*R);
-
-  if (i == iend)
-    result->append(j, jend);
-  else if (j == jend)
-    result->append(i, iend);
-  else {
-    bool done = false;
-    while (!done)
-    {
-      int cmp = R->monomialCompare(i.getMonomial(), j.getMonomial());
-      n_compares++;
-      switch (cmp) {
-      case LT:
-        result->appendTerm(j.getCoefficient(), j.getMonomial());
-        ++j;
-        if (j == jend)
-          {
-            result->append(i, iend);
-            done = true;
-          }
-        break;
-      case GT:
-        result->appendTerm(i.getCoefficient(), i.getMonomial());
-        ++i;
-        if (i == iend)
-          {
-            result->append(j, jend);
-            done = true;
-          }
-        break;
-      case EQ:
-        R->coefficientSet(c, i.getCoefficient());
-        R->coefficientAddTo(c, j.getCoefficient());
-        if (!R->coefficientIsZero(c))
-          result->appendTerm(c, i.getMonomial());
-        ++j;
-        ++i;
-        if (j == jend)
-          {
-            result->append(i, iend);
-            done = true;
-          }
-        else
-          {
-            if (i == iend)
-              {
-                result->append(j, jend);
-                done = true;
-              }
-          }
-        break;
-      }
-    }
-  }
-  return result;
-}
-
 const_monomial Poly::backMonomial() const {
   MATHICGB_ASSERT(begin() != end());
-  return &(monoms.front()) + R->maxMonomialSize() * (nTerms() - 1);
+  return &(monoms.front()) + ring().maxMonomialSize() * (termCount() - 1);
 }
 
 void Poly::multByTerm(coefficient a, const_monomial m)
@@ -211,11 +142,11 @@ void Poly::multByTerm(coefficient a, const_monomial m)
   exponent * n = &monoms[0];
   iterator j = end();
 
-  for (iterator i = begin(); i != j; ++i, ++p, n += R->maxMonomialSize())
+  for (iterator i = begin(); i != j; ++i, ++p, n += ring().maxMonomialSize())
     {
       monomial nmon = n;
-      R->coefficientMultTo(coeffs[p], a);
-      R->monomialMultTo(nmon, m); // changes the monomial pointed to by n.
+      ring().coefficientMultTo(coeffs[p], a);
+      ring().monomialMultTo(nmon, m); // changes the monomial pointed to by n.
     }
 }
 
@@ -225,14 +156,14 @@ void Poly::multByMonomial(const_monomial m)
   exponent * n = &monoms[0];
   iterator j = end();
 
-  for (iterator i = begin(); i != j; ++i, ++p, n += R->maxMonomialSize())
+  for (iterator i = begin(); i != j; ++i, ++p, n += ring().maxMonomialSize())
     {
       monomial nmon = n;
-      R->monomialMultTo(nmon, m); // changes the monomial pointed to by n.
+      ring().monomialMultTo(nmon, m); // changes the monomial pointed to by n.
     }
 }
 
-void Poly::dump() const
+/*void Poly::dump() const
 {
   std::cout << "coeffs: ";
   for (unsigned i=0; i<coeffs.size(); i++)
@@ -242,7 +173,7 @@ void Poly::dump() const
   for (unsigned int i=0; i<monoms.size(); i++)
     std::cout << " " << monoms[i];
   std::cout << std::endl;
-}
+}*/
 
 void Poly::parseDoNotOrder(std::istream& i)
 {
@@ -274,17 +205,17 @@ void Poly::parseDoNotOrder(std::istream& i)
       }
       if (preceededByMinus)
         bigCoef = -bigCoef;
-      coeffs.push_back(R->toCoefficient(bigCoef));
+      coeffs.push_back(ring().toCoefficient(bigCoef));
     }
 
     // read monic monomial
     const size_t firstLocation = monoms.size();
-    monoms.resize(firstLocation + R->maxMonomialSize());
+    monoms.resize(firstLocation + ring().maxMonomialSize());
     monomial m = &monoms[firstLocation];
     if (isalpha(next) || next == '<')
-      R->monomialParse(i, m);
+      ring().monomialParse(i, m);
     else
-      R->monomialSetIdentity(m); // have to do this to set hash value
+      ring().monomialSetIdentity(m); // have to do this to set hash value
     next = i.peek();
     if (next == '>')
       i.get();
@@ -298,7 +229,7 @@ void Poly::parse(std::istream& in) {
 
 void Poly::display(std::ostream& out, const bool printComponent) const
 {
-  const coefficient p = R->charac();
+  const coefficient p = ring().charac();
   const coefficient maxPositive = (p + 1) / 2; // half rounded up
   if (isZero()) {
     out << "0";
@@ -309,12 +240,12 @@ void Poly::display(std::ostream& out, const bool printComponent) const
     coefficient coef = i.getCoefficient();
     if (coef > maxPositive) {
       out << "-";
-      R->coefficientNegateTo(coef);
+      ring().coefficientNegateTo(coef);
     } else if (i != begin())
       out << '+';
     if (coef != 1)
       out << coef;
-    R->monomialDisplay(out, i.getMonomial(), printComponent, coef == 1);
+    ring().monomialDisplay(out, i.getMonomial(), printComponent, coef == 1);
   }
 }
 
@@ -325,7 +256,7 @@ void Poly::display(FILE* file, bool printComponent) const
     return;
   }
 
-  const auto characteristic = R->charac();
+  const auto characteristic = ring().charac();
   const coefficient maxPositiveCoefficient = (characteristic + 1) / 2;
   bool firstTerm = true;
   for (auto it = begin(); it != end(); ++it) {
@@ -340,7 +271,7 @@ void Poly::display(FILE* file, bool printComponent) const
         printOne = false;
         fprintf(file, "%li", (long)coef);
       }
-      R->monomialDisplay(file, it.getMonomial(), printComponent, printOne);
+      ring().monomialDisplay(file, it.getMonomial(), printComponent, printOne);
       firstTerm = false;
     }
 }
@@ -354,7 +285,6 @@ size_t Poly::getMemoryUse() const
 }
 
 void Poly::setToZero() {
-  MATHICGB_ASSERT(R != 0);
   coeffs.clear();
   monoms.clear();
 }
@@ -371,7 +301,7 @@ std::ostream& operator<<(std::ostream& out, const Poly& p) {
 }
 
 void Poly::reserve(size_t spaceForThisManyTerms) {
-  monoms.reserve(spaceForThisManyTerms * R->maxMonomialSize());
+  monoms.reserve(spaceForThisManyTerms * ring().maxMonomialSize());
 }
 
 bool Poly::termsAreInDescendingOrder() const {
@@ -383,7 +313,7 @@ bool Poly::termsAreInDescendingOrder() const {
   auto previous = it;
   ++it;
   while (it != stop) {
-    if (R->monomialCompare(previous.getMonomial(), it.getMonomial()) == LT)
+    if (ring().monomialCompare(previous.getMonomial(), it.getMonomial()) == LT)
       return false;
     previous = it;
     ++it;
diff --git a/src/mathicgb/Poly.hpp b/src/mathicgb/Poly.hpp
index 5041499..663134a 100755
--- a/src/mathicgb/Poly.hpp
+++ b/src/mathicgb/Poly.hpp
@@ -15,10 +15,13 @@ MATHICGB_NAMESPACE_BEGIN
 class Poly {
 public:
   typedef PolyRing::Monoid Monoid;
-  typedef Monoid::ConstMonoRef ConstMonoRef;
+  typedef Monoid::Mono Mono;
   typedef Monoid::MonoRef MonoRef;
+  typedef Monoid::ConstMonoRef ConstMonoRef;
+  typedef Monoid::MonoPtr MonoPtr;
+  typedef Monoid::ConstMonoPtr ConstMonoPtr;
 
-  Poly(const PolyRing& ring) : R(&ring) {MATHICGB_ASSERT(R != 0);}
+  Poly(const PolyRing& ring) : mRing(ring) {}
 
   void parse(std::istream &i); // reads into this, sorts terms
   void parseDoNotOrder(std::istream &i); // reads into this, does not sort terms
@@ -33,7 +36,7 @@ public:
     std::vector<exponent>::iterator im;
     friend class Poly;
 
-    iterator(Poly& f) : monsize(f.getRing()->maxMonomialSize()), ic(f.coeffs.begin()), im(f.monoms.begin()) {}
+    iterator(Poly& f) : monsize(f.ring().maxMonomialSize()), ic(f.coeffs.begin()), im(f.monoms.begin()) {}
     iterator(Poly& f,int) : ic(f.coeffs.end()), im() {}
   public:
     typedef std::random_access_iterator_tag iterator_category;
@@ -68,7 +71,7 @@ public:
     std::vector<exponent>::const_iterator im;
     friend class Poly;
 
-    const_iterator(const Poly& f) : monsize(f.getRing()->maxMonomialSize()), ic(f.coeffs.begin()), im(f.monoms.begin()) {}
+    const_iterator(const Poly& f) : monsize(f.ring().maxMonomialSize()), ic(f.coeffs.begin()), im(f.monoms.begin()) {}
     const_iterator(const Poly& f,int) : ic(f.coeffs.end()), im() {}
   public:
     typedef std::random_access_iterator_tag iterator_category;
@@ -103,7 +106,7 @@ public:
   // Insert [first, last) onto the end of this.
   // This invalidates iterators on this.
 
-  Poly *copy() const;
+  //Poly *copy() const;
 
   // Cannot call this monomial() since that is already a type :-(
   monomial monomialAt(size_t index);
@@ -128,14 +131,6 @@ public:
 
   const coefficient* coefficientBegin() const {return coeffs.data();}
 
-
-  static Poly * add(const PolyRing *R,
-                    iterator first1,
-                    iterator last1,
-                    iterator first2,
-                    iterator last2,
-                    size_t &n_compares);
-
   void multByTerm(coefficient a, const_monomial m);
   void multByMonomial(const_monomial m);
   void multByCoefficient(coefficient a);
@@ -145,31 +140,31 @@ public:
 
   const_monomial getLeadMonomial() const { return &(monoms[0]); }
   const_coefficient getLeadCoefficient() const  { return coeffs[0]; }
-  exponent getLeadComponent() const  { return R->monomialGetComponent(&(monoms[0])); }
+  exponent getLeadComponent() const  { return ring().monomialGetComponent(&(monoms[0])); }
   bool isZero() const { return coeffs.empty(); }
 
-  size_t nTerms() const { return coeffs.size(); } /// @todo: deprecated
+  //size_t nTerms() const { return coeffs.size(); } /// @todo: deprecated
   size_t termCount() const {return coeffs.size();}
 
   size_t getMemoryUse() const;
 
   void setToZero();
 
-  void copy(Poly &result) const;
-  friend bool operator==(const Poly &a, const Poly &b);
+  //void copy(Poly &result) const;
+  Poly& operator=(const Poly& poly) {return *this = Poly(poly);}
+  Poly& operator=(Poly&& poly);
 
-  // deprecated
-  const PolyRing *getRing() const { return R; }
+  friend bool operator==(const Poly &a, const Poly &b);
 
-  // use this instead of getRing()
-  const PolyRing& ring() const {return *R;}
+  const PolyRing& ring() const {return mRing;}
+  const Monoid& monoid() const {return ring().monoid();}
 
-  void dump() const; // used for debugging
+  //void dump() const; // used for debugging
 
   bool termsAreInDescendingOrder() const;
 
 private:
-  const PolyRing *R;
+  const PolyRing& mRing;
   std::vector<coefficient> coeffs;
   std::vector<exponent> monoms;
 };
@@ -198,14 +193,14 @@ inline void Poly::appendTerm(coefficient a, const_monomial m)
 {
   // the monomial will be copied on.
   coeffs.push_back(a);
-  size_t len = R->maxMonomialSize();
+  size_t len = ring().maxMonomialSize();
   exponent const * e = m.unsafeGetRepresentation();
   monoms.insert(monoms.end(), e, e + len);
 }
 
 inline void Poly::appendTerm(coefficient a, PolyRing::Monoid::ConstMonoRef m) {
   coeffs.push_back(a);
-  size_t len = R->maxMonomialSize();
+  size_t len = ring().maxMonomialSize();
   auto& monoid = ring().monoid();
   const auto offset = monoms.size();
   monoms.resize(offset + monoid.entryCount());
diff --git a/src/mathicgb/PolyBasis.cpp b/src/mathicgb/PolyBasis.cpp
index feda5fd..6a579b7 100755
--- a/src/mathicgb/PolyBasis.cpp
+++ b/src/mathicgb/PolyBasis.cpp
@@ -170,7 +170,7 @@ size_t PolyBasis::monomialCount() const {
   EntryCIter const stop = mEntries.end();
   for (EntryCIter it = mEntries.begin(); it != stop; ++it)
     if (!it->retired)
-      sum += it->poly->nTerms();
+      sum += it->poly->termCount();
   return sum;
 }
 
diff --git a/src/mathicgb/ReducerDedup.cpp b/src/mathicgb/ReducerDedup.cpp
index f02110d..6ba8060 100644
--- a/src/mathicgb/ReducerDedup.cpp
+++ b/src/mathicgb/ReducerDedup.cpp
@@ -76,7 +76,7 @@ ReducerDedup<Q>::~ReducerDedup() {
 
 template<template<typename> class Q>
 void ReducerDedup<Q>::insertTail(NewConstTerm multiple, const Poly& poly) {
-  if (poly.nTerms() <= 1)
+  if (poly.termCount() <= 1)
     return;
   mLeadTermKnown = false;
 
diff --git a/src/mathicgb/ReducerHash.cpp b/src/mathicgb/ReducerHash.cpp
index e0f4028..1159de2 100644
--- a/src/mathicgb/ReducerHash.cpp
+++ b/src/mathicgb/ReducerHash.cpp
@@ -64,7 +64,7 @@ ReducerHash<Q>::ReducerHash(const PolyRing &ring):
 
 template<template<typename> class Q>
 void ReducerHash<Q>::insertTail(NewConstTerm multiplier, const Poly& f) {
-  if (f.nTerms() <= 1)
+  if (f.termCount() <= 1)
     return;
 
   mNodesTmp.clear();
diff --git a/src/mathicgb/ReducerHashPack.cpp b/src/mathicgb/ReducerHashPack.cpp
index c71d879..8497d75 100644
--- a/src/mathicgb/ReducerHashPack.cpp
+++ b/src/mathicgb/ReducerHashPack.cpp
@@ -95,7 +95,7 @@ ReducerHashPack<Q>::~ReducerHashPack() {
 template<template<typename> class Q>
 void ReducerHashPack<Q>::insertTail(NewConstTerm multiple, const Poly& poly) {
   MATHICGB_ASSERT(&poly.ring() == &mRing);
-  if (poly.nTerms() <= 1)
+  if (poly.termCount() <= 1)
     return;
   auto entry = new (mPool.alloc()) MultipleWithPos(poly, multiple);
   ++entry->pos;
diff --git a/src/mathicgb/ReducerNoDedup.cpp b/src/mathicgb/ReducerNoDedup.cpp
index 067e438..14637cf 100644
--- a/src/mathicgb/ReducerNoDedup.cpp
+++ b/src/mathicgb/ReducerNoDedup.cpp
@@ -72,7 +72,7 @@ ReducerNoDedup<Q>::~ReducerNoDedup() {
 
 template<template<typename> class Q>
 void ReducerNoDedup<Q>::insertTail(NewConstTerm multiple, const Poly& poly) {
-  if (poly.nTerms() <= 1)
+  if (poly.termCount() <= 1)
     return;
   mLeadTermKnown = false;
 
diff --git a/src/mathicgb/ReducerPackDedup.cpp b/src/mathicgb/ReducerPackDedup.cpp
index 5ef4d2e..17d4db7 100644
--- a/src/mathicgb/ReducerPackDedup.cpp
+++ b/src/mathicgb/ReducerPackDedup.cpp
@@ -117,7 +117,7 @@ ReducerPackDedup<Q>::~ReducerPackDedup() {
 
 template<template<typename> class Q>
 void ReducerPackDedup<Q>::insertTail(NewConstTerm multiple, const Poly& poly) {
-  if (poly.nTerms() <= 1)
+  if (poly.termCount() <= 1)
     return;
   mLeadTermKnown = false;
 
diff --git a/src/mathicgb/SigPolyBasis.cpp b/src/mathicgb/SigPolyBasis.cpp
index af1b538..1349446 100755
--- a/src/mathicgb/SigPolyBasis.cpp
+++ b/src/mathicgb/SigPolyBasis.cpp
@@ -324,8 +324,8 @@ size_t SigPolyBasis::minimalLeadInSigSlow(ConstMonoRef sig) const {
       if (leadCmp == Monoid::EqualTo) {
         // If same lead monomial in signature, pick the one with fewer terms
         // as that one might be less effort to reduce.
-        const size_t minTerms = poly(minLeadGen).nTerms();
-        const size_t terms = poly(gen).nTerms();
+        const size_t minTerms = poly(minLeadGen).termCount();
+        const size_t terms = poly(gen).termCount();
         if (minTerms > terms)
           continue;
         if (minTerms == terms) {
diff --git a/src/mathicgb/SignatureGB.cpp b/src/mathicgb/SignatureGB.cpp
index f1cc259..fb22a24 100755
--- a/src/mathicgb/SignatureGB.cpp
+++ b/src/mathicgb/SignatureGB.cpp
@@ -67,8 +67,7 @@ SignatureGB::SignatureGB(
     GB->addComponent();
 
   for (Component i = 0; i < componentCount; i++) {
-    auto g = make_unique<Poly>(*R);
-    basis.getPoly(i)->copy(*g);
+    auto g = make_unique<Poly>(*basis.getPoly(i));
     g->makeMonic();
 
     auto sig = monoid().alloc();
diff --git a/src/mathicgb/StaticMonoMap.hpp b/src/mathicgb/StaticMonoMap.hpp
index 92b3b9d..cb89a83 100755
--- a/src/mathicgb/StaticMonoMap.hpp
+++ b/src/mathicgb/StaticMonoMap.hpp
@@ -178,8 +178,8 @@ public:
 
       if (reducer != size_t(-1)) {
         if (preferSparseReducers) {
-          const auto newTermCount = basis.poly(e.data()).nTerms();
-          const auto oldTermCount = basis.poly(reducer).nTerms();
+          const auto newTermCount = basis.poly(e.data()).termCount();
+          const auto oldTermCount = basis.poly(reducer).termCount();
           if (newTermCount > oldTermCount)
             return true; // what we already have is sparser
           // resolve ties by picking oldest
@@ -280,8 +280,8 @@ public:
         if (ratioCmp == EQ) {
           // If same lead monomial in signature, pick the one with fewer terms
           // as that one might be less effort to reduce.
-          const size_t minTerms = basis.poly(minLeadGen).nTerms();
-          const size_t terms = basis.poly(entry.data()).nTerms();
+          const size_t minTerms = basis.poly(minLeadGen).termCount();
+          const size_t terms = basis.poly(entry.data()).termCount();
           if (minTerms > terms)
             return true;
           if (minTerms == terms) {
@@ -320,8 +320,8 @@ public:
         return true;
       }
       if (preferSparseReducers) {
-        const auto oldTermCount = basis.poly(reducer).nTerms();
-        const auto newTermCount = basis.poly(entry.data()).nTerms();
+        const auto oldTermCount = basis.poly(reducer).termCount();
+        const auto newTermCount = basis.poly(entry.data()).termCount();
         if (oldTermCount > newTermCount) {
           reducer = entry.data(); // prefer sparser
           return true;
diff --git a/src/test/poly-test.cpp b/src/test/poly-test.cpp
index d7118db..6f44966 100755
--- a/src/test/poly-test.cpp
+++ b/src/test/poly-test.cpp
@@ -642,91 +642,3 @@ TEST(Poly,lead) {
   EXPECT_EQ(0, I->getPoly(0)->getLeadComponent());
   R->freeMonomial(lm);
 }
-
-//////////////////////////////
-// Test reducer code /////////
-//////////////////////////////
-
-std::unique_ptr<Poly> multIdealByPolyReducer(int typ, const Basis& basis, const Poly& g)
-{
-  const PolyRing& R = basis.ring();
-  auto poly = make_unique<Poly>(R);
-  std::unique_ptr<Reducer> H = Reducer::makeReducer(static_cast<Reducer::ReducerType>(typ), R);
-  for (Poly::const_iterator i = g.begin(); i != g.end(); ++i) {
-    monomial mon = R.allocMonomial();
-    R.monomialCopy(i.getMonomial(), mon);
-    int x = R.monomialGetComponent(mon);
-    R.monomialChangeComponent(mon, 0);
-    std::unique_ptr<Poly> h(basis.getPoly(x)->copy());
-    h->multByTerm(i.getCoefficient(), mon);
-    R.monomialSetIdentity(mon);
-
-    size_t ncmps;
-    Poly* sum =
-      Poly::add(&R, h->begin(), h->end(), poly->begin(), poly->end(), ncmps); 
-    poly.reset(sum);
-  }
-  return poly;
-}
-
-void testPolyReducer(
-  Reducer::ReducerType reducerType,
-  const Basis& basis,
-  const std::string& f,
-  const std::string& ans
-) {
-  const PolyRing& ring = *basis.getPolyRing();
-  std::unique_ptr<Poly> g = polyParseFromString(&ring, f);
-  std::unique_ptr<Poly> h = multIdealByPolyReducer(reducerType, basis, *g);
-  if (!h->isZero()) {
-    Poly::iterator prev = h->begin();
-    Poly::iterator it = prev;
-    for (++it; it != h->end(); ++it, ++prev) {
-      EXPECT_TRUE(ring.monomialLT(it.getMonomial(), prev.getMonomial()))
-        << "Reduced result not in sorted order: " << toString(h.get());
-    }
-  }
-
-  EXPECT_EQ(ans, toString(h.get())) << "Reducer type " << reducerType;
-}
-
-/// @todo: this is no longer a test of a reducer. What to do this this test?
-TEST(Reducer, insert) {
-  // plan: read an ideal, and another poly
-  //  use this last poly to determine what to add to the heap
-  // at the end, take the value of the heap, compare to answer
-
-  std::unique_ptr<Basis> I = basisParseFromString(ideal2); // charac is 32003
-  for (int typ = 0; typ <= 30; ++typ) {
-    Reducer::ReducerType red = Reducer::ReducerType(typ);
-    if (static_cast<int>(red) != typ ||
-      Reducer::makeReducerNullOnUnknown(red, I->ring()).get() == 0)
-      continue;
-
-    testPolyReducer(red, *I, "c2d<0>", "bc4d<0>-ac2d3<0>");
-    testPolyReducer(red, *I, "c2d<0>-3abc<1>", "-3a2b2c2<0>+bc4d<0>+3abcd3<0>-ac2d3<0>");
-    testPolyReducer(red, *I, "c2d<0>-3abc<1>+a2<3>", "-3a2b2c2<0>+bc4d<0>+a4d2<0>-a2cd3<0>+3abcd3<0>-ac2d3<0>");
-    testPolyReducer(red, *I, "c2d<0>-3abc<1>+a2<3>+3ab<4>", "3a2bc3d<0>-3a2b3d2<0>-3a2b2c2<0>+bc4d<0>+a4d2<0>-a2cd3<0>+3abcd3<0>-ac2d3<0>");
-    testPolyReducer(red, *I, "bc4d<0>+3bc4d<0>-2bc4d<0>", "2b2c6d<0>-2abc4d3<0>");
-    testPolyReducer(red, *I, "a<0>+32002c<1>+<3>", "0");
-  }
-}
-
-std::string somePolys =
-"  bc+bd+af+ef\n\
-  ac+cd+bf+ef\n\
-  ad+bd+cf+ef\n\
-  ab+ac+df+ef\n\
-  bd2+cd2+c2f+adf+bdf+cef\n\
-  b2d+acd+bcf+d2f+bef+def\n\
-  c2d+bd2+b2f+bcf+adf+cdf+bef+def\n\
-  a2f+b2f+c2f+d2f+aef+bef+cef+def\n\
-  cd2f+d3f+adef+bdef+cdef+d2ef+b2f2+acf2+c2f2+bdf2+cdf2+aef2+cef2+def2\n\
-  c3f+b2df+acdf+cd2f+c2ef+bdef\n\
-  b3f+b2cf+bc2f+b2df+acdf+bcdf+b2ef+bcef+bdef+cdef\n\
-  b2ef2+bcef2+adef2+d2ef2+be2f2+de2f2+abf3+b2f3+bcf3+adf3+cdf3+d2f3\n\
-  bde2f2+cde2f2+abdf3+b2df3+bcdf3+ad2f3+cd2f3+d3f3+b2ef3+acef3+bcef3+c2ef3+adef3+d2ef3+ae2f3+be2f3+de2f3+e3f3\n\
-  c2e2f3+ade2f3+bde2f3+d2e2f3+ce3f3+de3f3+b2df4+acdf4+bcdf4+c2df4+ad2f4+bd2f4+b2ef4+c2ef4+de2f4+e3f4\n\
-  cde2f4+d2e2f4+ae3f4+be3f4+ce3f4+e4f4+bc2f5+b2df5+c2df5+ad2f5+cd2f5+d3f5+acef5+adef5+bdef5+d2ef5+ce2f5+e3f5\n\
-  d2e3f4+de4f4+bc2df5+abd2f5+bcd2f5+c2d2f5+bc2ef5+abdef5+bd2ef5+d3ef5+b2e2f5+ace2f5+bce2f5+cde2f5+ae3f5+de3f5\n\
-";

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mathicgb.git



More information about the debian-science-commits mailing list