[mathicgb] 46/393: Added support for reducing a set of polynomials in addition to the support for reducing a set of S-pairs. BuchbergerAlg uses this features now. This made the F4 reducer faster even though it is still just doing inter-reductions one at a time using the fall-back (non-matrix) reducer, presumably because collecting all the reductions and updating the basis fully allows a fuller reduction which could imply fewer rounds of interreduction.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:58:31 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 dce4e88a62576c19aa11a9c402b6201e6cc6341a
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date:   Thu Oct 4 22:54:42 2012 +0200

    Added support for reducing a set of polynomials in addition to the support for reducing a set of S-pairs. BuchbergerAlg uses this features now. This made the F4 reducer faster even though it is still just doing inter-reductions one at a time using the fall-back (non-matrix) reducer, presumably because collecting all the reductions and updating the basis fully allows a fuller reduction which could imply fewer rounds of interreduction.
---
 src/mathicgb/BuchbergerAlg.cpp  | 70 ++++++++++++++++++++++++++++++++++++++++-
 src/mathicgb/BuchbergerAlg.hpp  |  4 +++
 src/mathicgb/F4Reducer.cpp      | 14 ++++++++-
 src/mathicgb/F4Reducer.hpp      |  7 ++++-
 src/mathicgb/Poly.cpp           |  8 +++--
 src/mathicgb/PolyBasis.cpp      |  4 ++-
 src/mathicgb/Reducer.hpp        | 10 +++++-
 src/mathicgb/SPairs.cpp         |  5 ++-
 src/mathicgb/TypicalReducer.cpp | 14 ++++++++-
 src/mathicgb/TypicalReducer.hpp |  7 ++++-
 10 files changed, 131 insertions(+), 12 deletions(-)

diff --git a/src/mathicgb/BuchbergerAlg.cpp b/src/mathicgb/BuchbergerAlg.cpp
index e9a3125..98a7329 100755
--- a/src/mathicgb/BuchbergerAlg.cpp
+++ b/src/mathicgb/BuchbergerAlg.cpp
@@ -36,6 +36,70 @@ BuchbergerAlg::BuchbergerAlg(
     insertReducedPoly(mReducer->classicReduce(*ideal.getPoly(gen), mBasis));
 }
 
+void BuchbergerAlg::insertPolys
+(std::vector<std::unique_ptr<Poly> >& polynomials)
+{
+  if (!mUseAutoTopReduction) {
+    for (auto it = polynomials.begin(); it != polynomials.end(); ++it) {
+      MATHICGB_ASSERT(it->get() != 0);
+      if ((*it)->isZero())
+        continue;
+      if (mBasis.divisor((*it)->getLeadMonomial()) != static_cast<size_t>(-1)) {
+        *it = mReducer->classicReduce(**it, mBasis);
+        if ((*it)->isZero())
+          continue;
+      }
+
+      mBasis.insert(std::move(*it));
+      mSPairs.addPairs(mBasis.size() - 1);
+    }
+    polynomials.clear();
+    return;
+  }
+
+  std::vector<size_t> toRetire;
+  std::vector<std::unique_ptr<Poly> > toReduce;
+  std::vector<std::unique_ptr<Poly> > toInsert;
+  std::swap(toInsert, polynomials);
+
+  while (!toInsert.empty()) {
+    // todo: sort by lead term to avoid insert followed by immediate
+    // removal.
+
+    // insert polynomials from toInsert with minimal lead term and
+    // extract those from the basis that become non-minimal.
+    for (auto it = toInsert.begin(); it != toInsert.end(); ++it) {
+      MATHICGB_ASSERT(it->get() != 0);
+      if ((*it)->isZero())
+        continue;
+
+      // We check for a divisor from mBasis because a new reducer
+      // might have been added since we did the reduction or perhaps a
+      // non-reduced polynomial was passed in.
+      if (mBasis.divisor((*it)->getLeadMonomial()) != static_cast<size_t>(-1))
+        toReduce.push_back(std::move(*it));
+      else {
+        mBasis.insert(std::move(*it));
+        MATHICGB_ASSERT(toRetire.empty());
+        mSPairs.addPairsAssumeAutoReduce(mBasis.size() - 1, toRetire);
+        for (auto r = toRetire.begin(); r != toRetire.end(); ++r)
+          toReduce.push_back(mBasis.retire(*r));
+        toRetire.clear();
+      }
+    }
+    toInsert.clear();
+    MATHICGB_ASSERT(toRetire.empty());
+
+    // reduce everything in toReduce
+    mReducer->classicReducePolySet(toReduce, mBasis, toInsert);
+    toReduce.clear();
+  }
+
+  MATHICGB_ASSERT(toRetire.empty());
+  MATHICGB_ASSERT(toInsert.empty());
+  MATHICGB_ASSERT(toReduce.empty());
+}
+
 void BuchbergerAlg::insertReducedPoly(
   std::unique_ptr<Poly> polyToInsert
 ) {
@@ -103,6 +167,7 @@ void BuchbergerAlg::insertReducedPoly(
 
       // form S-pairs and retire basis elements that become top reducible.
       const size_t newGen = mBasis.size() - 1;
+      MATHICGB_ASSERT(toRetireAndReduce.empty());
       mSPairs.addPairsAssumeAutoReduce(newGen, toRetireAndReduce);
       for (std::vector<size_t>::const_iterator it = toRetireAndReduce.begin();
         it != toRetireAndReduce.end(); ++it) {
@@ -197,8 +262,10 @@ void BuchbergerAlg::step() {
     if (spairGroup.empty())
       return; // no more s-pairs
     std::vector<std::unique_ptr<Poly> > reduced;
-    mReducer->classicReduceSPolyGroup(spairGroup, mBasis, reduced);
+    mReducer->classicReduceSPolySet(spairGroup, mBasis, reduced);
     
+    insertPolys(reduced);
+    /*
     for (auto it = reduced.begin(); it != reduced.end(); ++it) {
       auto p = std::move(*it);
       MATHICGB_ASSERT(!p->isZero());
@@ -207,6 +274,7 @@ void BuchbergerAlg::step() {
       if (!p->isZero())
         insertReducedPoly(std::move(p));
     }
+    */
     if (mUseAutoTailReduction)
       autoTailReduce();
   }
diff --git a/src/mathicgb/BuchbergerAlg.hpp b/src/mathicgb/BuchbergerAlg.hpp
index 47c4e60..f4d79e8 100755
--- a/src/mathicgb/BuchbergerAlg.hpp
+++ b/src/mathicgb/BuchbergerAlg.hpp
@@ -8,6 +8,7 @@
 #include <mathic.h>
 #include <memory>
 #include <ostream>
+#include <vector>
 
 /// Calculates a classic Grobner basis using Buchberger's algorithm.
 class BuchbergerAlg {
@@ -76,6 +77,9 @@ private:
 
   void insertReducedPoly(std::unique_ptr<Poly> poly);
 
+  // clears polynomials.
+  void insertPolys(std::vector<std::unique_ptr<Poly> >& polynomials);
+
   const PolyRing& mRing;
   std::unique_ptr<FreeModuleOrder> mOrder;
   std::unique_ptr<Reducer> mReducer;
diff --git a/src/mathicgb/F4Reducer.cpp b/src/mathicgb/F4Reducer.cpp
index fe5b7cc..e03c21c 100755
--- a/src/mathicgb/F4Reducer.cpp
+++ b/src/mathicgb/F4Reducer.cpp
@@ -70,7 +70,7 @@ std::unique_ptr<Poly> F4Reducer::classicReduceSPoly
   return p;
 }
 
-void F4Reducer::classicReduceSPolyGroup
+void F4Reducer::classicReduceSPolySet
 (std::vector<std::pair<size_t, size_t> >& spairs,
  const PolyBasis& basis,
  std::vector<std::unique_ptr<Poly> >& reducedOut)
@@ -113,6 +113,18 @@ void F4Reducer::classicReduceSPolyGroup
   }
 }
 
+void F4Reducer::classicReducePolySet
+(const std::vector<std::unique_ptr<Poly> >& polys,
+ const PolyBasis& basis,
+ std::vector<std::unique_ptr<Poly> >& reducedOut)
+{
+  for (auto it = polys.begin(); it != polys.end(); ++it) {
+    auto reducedPoly = classicReduce(**it, basis);
+    if (!reducedPoly->isZero())
+      reducedOut.push_back(std::move(reducedPoly));
+  }
+}
+
 Poly* F4Reducer::regularReduce
 (const_monomial sig,
  const_monomial multiple,
diff --git a/src/mathicgb/F4Reducer.hpp b/src/mathicgb/F4Reducer.hpp
index 83b9878..bbbb3d2 100755
--- a/src/mathicgb/F4Reducer.hpp
+++ b/src/mathicgb/F4Reducer.hpp
@@ -18,11 +18,16 @@ public:
   virtual std::unique_ptr<Poly> classicReduceSPoly
   (const Poly& a, const Poly& b, const PolyBasis& basis);
 
-  virtual void classicReduceSPolyGroup
+  virtual void classicReduceSPolySet
   (std::vector<std::pair<size_t, size_t> >& spairs,
    const PolyBasis& basis,
    std::vector<std::unique_ptr<Poly> >& reducedOut);
 
+  virtual void classicReducePolySet
+  (const std::vector<std::unique_ptr<Poly> >& polys,
+   const PolyBasis& basis,
+   std::vector<std::unique_ptr<Poly> >& reducedOut);
+
   virtual Poly* regularReduce(
     const_monomial sig,
     const_monomial multiple,
diff --git a/src/mathicgb/Poly.cpp b/src/mathicgb/Poly.cpp
index c3cb019..c187cd6 100755
--- a/src/mathicgb/Poly.cpp
+++ b/src/mathicgb/Poly.cpp
@@ -106,11 +106,15 @@ void Poly::multByCoefficient(coefficient c)
 
 void Poly::makeMonic()
 {
-  if (isZero()) return;
+  if (isZero())
+    return;
   coefficient c = getLeadCoefficient();
+  if (R->coefficientIsOne(c))
+    return;
   R->coefficientReciprocalTo(c);
-  for (std::vector<coefficient>::iterator i = coeffs.begin(); i != coeffs.end(); i++)
+  for (auto i = coeffs.begin(); i != coeffs.end(); i++)
     R->coefficientMultTo(*i, c);
+  MATHICGB_ASSERT(R->coefficientIsOne(getLeadCoefficient()))
 }
 
 bool operator==(const Poly &a, const Poly &b)
diff --git a/src/mathicgb/PolyBasis.cpp b/src/mathicgb/PolyBasis.cpp
index aee8c5e..64d76f7 100755
--- a/src/mathicgb/PolyBasis.cpp
+++ b/src/mathicgb/PolyBasis.cpp
@@ -42,7 +42,9 @@ std::unique_ptr<Ideal> PolyBasis::initialIdeal() const {
 }
 
 void PolyBasis::insert(std::unique_ptr<Poly> poly) {
-  ASSERT(poly.get() != 0);
+  MATHICGB_ASSERT(poly.get() != 0);
+  MATHICGB_ASSERT(!poly->isZero());
+  poly->makeMonic();
   const size_t index = size();
   EntryIter const stop = mEntries.end();
   const_monomial const lead = poly->getLeadMonomial();
diff --git a/src/mathicgb/Reducer.hpp b/src/mathicgb/Reducer.hpp
index d693a88..f17fdc3 100755
--- a/src/mathicgb/Reducer.hpp
+++ b/src/mathicgb/Reducer.hpp
@@ -39,11 +39,19 @@ public:
   /** Clasically reduces the S-polynomial of these pairs. May or may
       not also interreduce these to some extent. Polynomials that are
       reduced to zero are not put into reducedOut. */
-  virtual void classicReduceSPolyGroup
+  virtual void classicReduceSPolySet
   (std::vector<std::pair<size_t, size_t> >& spairs,
    const PolyBasis& basis,
    std::vector<std::unique_ptr<Poly> >& reducedOut) = 0;
 
+  /** Clasically reduces the passed-in polynomials of these pairs. May
+      or may not also interreduce these to some extent. Polynomials
+      that are reduced to zero are not put into reducedOut. */
+  virtual void classicReducePolySet
+  (const std::vector<std::unique_ptr<Poly> >& polys,
+   const PolyBasis& basis,
+   std::vector<std::unique_ptr<Poly> >& reducedOut) = 0;
+
   /** Regular reduce multiple*basisElement in signature sig by the
     basis elements in basis. Returns null (0) if multiple*basisElement
     is not regular top reducible -- this indicates a singular
diff --git a/src/mathicgb/SPairs.cpp b/src/mathicgb/SPairs.cpp
index aafe98c..99edbc6 100755
--- a/src/mathicgb/SPairs.cpp
+++ b/src/mathicgb/SPairs.cpp
@@ -48,9 +48,8 @@ namespace {
     ):
       mNewGen(newGen),
       mEliminated(eliminated),
-      mIndexes(indexes) {
-      mIndexes.clear();
-    }
+      mIndexes(indexes) {}
+
     virtual bool proceed(size_t index) {
       if (index == mNewGen)
         return true;
diff --git a/src/mathicgb/TypicalReducer.cpp b/src/mathicgb/TypicalReducer.cpp
index ba1db91..95fe0b0 100755
--- a/src/mathicgb/TypicalReducer.cpp
+++ b/src/mathicgb/TypicalReducer.cpp
@@ -133,7 +133,7 @@ std::unique_ptr<Poly> TypicalReducer::classicReduceSPoly(
   return std::move(reduced);
 }
 
-void TypicalReducer::classicReduceSPolyGroup
+void TypicalReducer::classicReduceSPolySet
 (std::vector<std::pair<size_t, size_t> >& spairs,
  const PolyBasis& basis,
  std::vector<std::unique_ptr<Poly> >& reducedOut) {
@@ -145,6 +145,18 @@ void TypicalReducer::classicReduceSPolyGroup
   }
 }
 
+void TypicalReducer::classicReducePolySet
+(const std::vector<std::unique_ptr<Poly> >& polys,
+ const PolyBasis& basis,
+ std::vector<std::unique_ptr<Poly> >& reducedOut)
+{
+  for (auto it = polys.begin(); it != polys.end(); ++it) {
+    auto reducedPoly = classicReduce(**it, basis);
+    if (!reducedPoly->isZero())
+      reducedOut.push_back(std::move(reducedPoly));
+  }  
+}
+
 void TypicalReducer::setThreadCount(size_t threadCount) {
   // multithreading not supported here (yet!)
 }
diff --git a/src/mathicgb/TypicalReducer.hpp b/src/mathicgb/TypicalReducer.hpp
index 2ffa597..15cb59c 100755
--- a/src/mathicgb/TypicalReducer.hpp
+++ b/src/mathicgb/TypicalReducer.hpp
@@ -33,11 +33,16 @@ public:
   virtual std::unique_ptr<Poly> classicReduceSPoly
     (const Poly& a, const Poly& b, const PolyBasis& basis);
 
-  virtual void classicReduceSPolyGroup
+  virtual void classicReduceSPolySet
   (std::vector<std::pair<size_t, size_t> >& spairs,
    const PolyBasis& basis,
    std::vector<std::unique_ptr<Poly> >& reducedOut);
 
+  virtual void classicReducePolySet
+  (const std::vector<std::unique_ptr<Poly> >& polys,
+   const PolyBasis& basis,
+   std::vector<std::unique_ptr<Poly> >& reducedOut);
+
   virtual void setThreadCount(size_t threadCount);
 
 protected:

-- 
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