[mathicgb] 237/393: Library interface now has an option for using a classic reducer or a matrix reducer.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:10 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 b7fa809d1f92ffdd57c1b9280b45cc3a5d7b8c25
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date:   Thu Apr 11 21:51:51 2013 -0400

    Library interface now has an option for using a classic reducer or a matrix reducer.
---
 src/mathicgb.cpp      | 102 +++++++++++++++------
 src/mathicgb.h        |  10 ++
 src/test/mathicgb.cpp | 246 ++++++++++++++++++++++++++------------------------
 3 files changed, 213 insertions(+), 145 deletions(-)

diff --git a/src/mathicgb.cpp b/src/mathicgb.cpp
old mode 100644
new mode 100755
index 89f131a..6a00550
--- a/src/mathicgb.cpp
+++ b/src/mathicgb.cpp
@@ -274,17 +274,41 @@ namespace mgb {
 
   struct GroebnerConfiguration::Pimpl {
     Pimpl(Coefficient modulus, VarIndex varCount):
+      mModulus(modulus),
+      mVarCount(varCount),
+      mReducer(DefaultReducer)
 #ifdef MATHICGB_DEBUG
-      hasBeenDestroyed(false),
+      , mHasBeenDestroyed(false)
 #endif
-      modulus(modulus),
-      varCount(varCount)
     {
     }
 
-    MATHICGB_IF_DEBUG(bool hasBeenDestroyed);
-    const Coefficient modulus;
-    const VarIndex varCount;
+    ~Pimpl() {
+      MATHICGB_ASSERT(debugAssertValid());
+      MATHICGB_IF_DEBUG(mHasBeenDestroyed = true;)
+    }
+
+    static bool reducerValid(Reducer reducer) {
+      return
+        reducer == DefaultReducer ||
+        reducer == ClassicReducer ||
+        reducer == MatrixReducer;
+    }
+
+    bool debugAssertValid() const {
+#ifdef MATHICGB_DEBUG
+      MATHICGB_ASSERT(this != 0);
+      MATHICGB_ASSERT(reducerValid(mReducer));
+      MATHICGB_ASSERT(mModulus != 0);
+      MATHICGB_ASSERT_NO_ASSUME(!mHasBeenDestroyed);
+#endif
+      return true;
+    }
+
+    const Coefficient mModulus;
+    const VarIndex mVarCount;
+    Reducer mReducer;
+    MATHICGB_IF_DEBUG(bool mHasBeenDestroyed);
   };
 
   GroebnerConfiguration::GroebnerConfiguration(
@@ -307,6 +331,7 @@ namespace mgb {
         << " is not prime. MathicGB only supports prime fields.";
       mathic::reportError(str.str());
     }
+    MATHICGB_ASSERT(mPimpl->debugAssertValid());
   }
 
   GroebnerConfiguration::GroebnerConfiguration(
@@ -314,24 +339,29 @@ namespace mgb {
   ):
     mPimpl(new Pimpl(*conf.mPimpl))
   {
-    MATHICGB_ASSERT(conf.mPimpl->modulus != 0);
-    MATHICGB_ASSERT_NO_ASSUME(!conf.mPimpl->hasBeenDestroyed);
+    MATHICGB_ASSERT(conf.mPimpl->debugAssertValid());
   }
 
   GroebnerConfiguration::~GroebnerConfiguration() {
-    MATHICGB_ASSERT(mPimpl != 0);
-    MATHICGB_ASSERT_NO_ASSUME(!mPimpl->hasBeenDestroyed);
-    MATHICGB_IF_DEBUG(mPimpl->hasBeenDestroyed = true);
-
+    MATHICGB_ASSERT(mPimpl->debugAssertValid());
     delete mPimpl;
   }
 
   auto GroebnerConfiguration::modulus() const -> Coefficient {
-    return mPimpl->modulus;
+    return mPimpl->mModulus;
   }
  
   auto GroebnerConfiguration::varCount() const -> VarIndex {
-    return mPimpl->varCount;
+    return mPimpl->mVarCount;
+  }
+
+  void GroebnerConfiguration::setReducer(Reducer reducer) {
+    MATHICGB_ASSERT(Pimpl::reducerValid(reducer));
+    mPimpl->mReducer = reducer;
+  }
+
+  auto GroebnerConfiguration::reducer() const -> Reducer {
+    return mPimpl->mReducer;
   }
 }
 
@@ -339,10 +369,6 @@ namespace mgb {
 namespace mgb {
   struct GroebnerInputIdealStream::Pimpl {
     Pimpl(const GroebnerConfiguration& conf):
-#ifdef MATHICGB_DEBUG
-      hasBeenDestroyed(false),
-      checker(conf.modulus(), conf.varCount()),
-#endif
       // @todo: varCount should not be int. Fix PolyRing constructor,
       // then remove this static_cast.
       ring(conf.modulus(), static_cast<int>(conf.varCount()), 1),
@@ -350,20 +376,24 @@ namespace mgb {
       poly(ring),
       monomial(ring.allocMonomial()),
       conf(conf)
+#ifdef MATHICGB_DEBUG
+      , hasBeenDestroyed(false),
+      checker(conf.modulus(), conf.varCount())
+#endif
     {}
 
     ~Pimpl() {
       ring.freeMonomial(monomial);
     }
 
-    MATHICGB_IF_DEBUG(bool hasBeenDestroyed);
-    MATHICGB_IF_DEBUG(::mgbi::StreamStateChecker checker);
     const PolyRing ring;
     Ideal ideal;
     Poly poly;
     Monomial monomial;
     const GroebnerConfiguration conf;
-  };
+    MATHICGB_IF_DEBUG(bool hasBeenDestroyed);
+    MATHICGB_IF_DEBUG(::mgbi::StreamStateChecker checker); 
+ };
 
   GroebnerInputIdealStream::GroebnerInputIdealStream(
     const GroebnerConfiguration& conf
@@ -532,7 +562,7 @@ namespace mgbi {
   }
 }
 
-// ** Implementation of function mgbi::internalComputeGreobnerBasis
+// ** Implementation of function mgbi::internalComputeGroebnerBasis
 namespace mgbi {
   void internalComputeGroebnerBasis(
     GroebnerInputIdealStream& inputWhichWillBeCleared,
@@ -542,19 +572,37 @@ namespace mgbi {
     /// polynomial-by-polynomial as data is transferred to out. Also
     /// make it so that ideal is not copied.
 
-    auto& ideal = PimplOf()(inputWhichWillBeCleared).ideal;
-    const auto& ring = ideal.ring();
+    auto&& ideal = PimplOf()(inputWhichWillBeCleared).ideal;
+    auto&& conf = inputWhichWillBeCleared.configuration();
+    auto&& ring = ideal.ring();
     const auto varCount = ring.getNumVars();
+    MATHICGB_ASSERT(PimplOf()(conf).debugAssertValid());
+
+    // Make reducer
+    typedef GroebnerConfiguration GConf;
+    Reducer::ReducerType reducerType;
+    switch (conf.reducer()) {
+    case GConf::ClassicReducer:
+      reducerType = Reducer::Reducer_BjarkeGeo;
+      break;
 
-    // Compute Groebner basis
-    const auto reducer = Reducer::makeReducer(Reducer::Reducer_F4_New, ring);
+    default:
+    case GConf::DefaultReducer:
+    case GConf::MatrixReducer:
+      reducerType = Reducer::Reducer_F4_New;
+      break;
+    }
+    const auto reducer = Reducer::makeReducer(reducerType, ring);
+
+    // Set up and configure algorithm
     BuchbergerAlg alg(ideal, 4, *reducer, 2, true, 0);
     alg.setSPairGroupSize(10000);
     alg.setReducerMemoryQuantum(100 * 1024);
     alg.setUseAutoTopReduction(true);
     alg.setUseAutoTailReduction(false);
-    alg.computeGrobnerBasis();
 
+    // Compute Groebner basis
+    alg.computeGrobnerBasis();
     PimplOf()(output).ideal = alg.basis().toIdealAndRetireAll();
   }
 }
diff --git a/src/mathicgb.h b/src/mathicgb.h
old mode 100644
new mode 100755
index 4c3973d..db9662f
--- a/src/mathicgb.h
+++ b/src/mathicgb.h
@@ -36,7 +36,17 @@ namespace mgb { // Part of the public interface of MathicGB
     Coefficient modulus() const;
     VarIndex varCount() const;
 
+    enum Reducer {
+      DefaultReducer = 0,
+      ClassicReducer = 1, /// the classic polynomial division algorithm
+      MatrixReducer = 2 /// use linear algebra as in F4
+    };
+    void setReducer(Reducer reducer);
+    Reducer reducer() const;
+
   private:
+    friend class mgbi::PimplOf;
+
     struct Pimpl;
     Pimpl* mPimpl;
   };
diff --git a/src/test/mathicgb.cpp b/src/test/mathicgb.cpp
old mode 100644
new mode 100755
index b782e07..91850c2
--- a/src/test/mathicgb.cpp
+++ b/src/test/mathicgb.cpp
@@ -67,6 +67,121 @@ namespace {
       s.appendPolynomialDone();
     s.idealDone();
   }
+
+  template<class Stream>
+  void makeCyclic5Basis(Stream& s) {
+    s.idealBegin(5); // polyCount
+    s.appendPolynomialBegin(5);
+    s.appendTermBegin();
+    s.appendExponent(0, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendExponent(1, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendExponent(2, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendExponent(3, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendExponent(4, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendPolynomialDone();
+    s.appendPolynomialBegin(5);
+    s.appendTermBegin();
+    s.appendExponent(0, 1); // index, exponent
+    s.appendExponent(1, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendExponent(1, 1); // index, exponent
+    s.appendExponent(2, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendExponent(2, 1); // index, exponent
+    s.appendExponent(3, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendExponent(0, 1); // index, exponent
+    s.appendExponent(4, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendExponent(3, 1); // index, exponent
+    s.appendExponent(4, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendPolynomialDone();
+    s.appendPolynomialBegin(5);
+    s.appendTermBegin();
+    s.appendExponent(0, 1); // index, exponent
+    s.appendExponent(1, 1); // index, exponent
+    s.appendExponent(2, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendExponent(1, 1); // index, exponent
+    s.appendExponent(2, 1); // index, exponent
+    s.appendExponent(3, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendExponent(0, 1); // index, exponent
+    s.appendExponent(1, 1); // index, exponent
+    s.appendExponent(4, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendExponent(0, 1); // index, exponent
+    s.appendExponent(3, 1); // index, exponent
+    s.appendExponent(4, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendExponent(2, 1); // index, exponent
+    s.appendExponent(3, 1); // index, exponent
+    s.appendExponent(4, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendPolynomialDone();
+    s.appendPolynomialBegin(5);
+    s.appendTermBegin();
+    s.appendExponent(0, 1); // index, exponent
+    s.appendExponent(1, 1); // index, exponent
+    s.appendExponent(2, 1); // index, exponent
+    s.appendExponent(3, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendExponent(0, 1); // index, exponent
+    s.appendExponent(1, 1); // index, exponent
+    s.appendExponent(2, 1); // index, exponent
+    s.appendExponent(4, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendExponent(0, 1); // index, exponent
+    s.appendExponent(1, 1); // index, exponent
+    s.appendExponent(3, 1); // index, exponent
+    s.appendExponent(4, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendExponent(0, 1); // index, exponent
+    s.appendExponent(2, 1); // index, exponent
+    s.appendExponent(3, 1); // index, exponent
+    s.appendExponent(4, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendExponent(1, 1); // index, exponent
+    s.appendExponent(2, 1); // index, exponent
+    s.appendExponent(3, 1); // index, exponent
+    s.appendExponent(4, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendPolynomialDone();
+    s.appendPolynomialBegin(2);
+    s.appendTermBegin();
+    s.appendExponent(0, 1); // index, exponent
+    s.appendExponent(1, 1); // index, exponent
+    s.appendExponent(2, 1); // index, exponent
+    s.appendExponent(3, 1); // index, exponent
+    s.appendExponent(4, 1); // index, exponent
+    s.appendTermDone(1); // coefficient
+    s.appendTermBegin();
+    s.appendTermDone(100); // coefficient
+    s.appendPolynomialDone();
+    s.idealDone();
+  }
 }
 
 TEST(MathicGBLib, NullIdealStream) {
@@ -249,122 +364,17 @@ TEST(MathicGBLib, EasyReGB) {
 }
 
 TEST(MathicGBLib, Cyclic5) {
-  mgb::GroebnerConfiguration configuration(101, 5);
-  mgb::GroebnerInputIdealStream s(configuration);
-  s.idealBegin(5); // polyCount
-  s.appendPolynomialBegin(5);
-  s.appendTermBegin();
-  s.appendExponent(0, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendExponent(1, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendExponent(2, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendExponent(3, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendExponent(4, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendPolynomialDone();
-  s.appendPolynomialBegin(5);
-  s.appendTermBegin();
-  s.appendExponent(0, 1); // index, exponent
-  s.appendExponent(1, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendExponent(1, 1); // index, exponent
-  s.appendExponent(2, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendExponent(2, 1); // index, exponent
-  s.appendExponent(3, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendExponent(0, 1); // index, exponent
-  s.appendExponent(4, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendExponent(3, 1); // index, exponent
-  s.appendExponent(4, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendPolynomialDone();
-  s.appendPolynomialBegin(5);
-  s.appendTermBegin();
-  s.appendExponent(0, 1); // index, exponent
-  s.appendExponent(1, 1); // index, exponent
-  s.appendExponent(2, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendExponent(1, 1); // index, exponent
-  s.appendExponent(2, 1); // index, exponent
-  s.appendExponent(3, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendExponent(0, 1); // index, exponent
-  s.appendExponent(1, 1); // index, exponent
-  s.appendExponent(4, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendExponent(0, 1); // index, exponent
-  s.appendExponent(3, 1); // index, exponent
-  s.appendExponent(4, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendExponent(2, 1); // index, exponent
-  s.appendExponent(3, 1); // index, exponent
-  s.appendExponent(4, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendPolynomialDone();
-  s.appendPolynomialBegin(5);
-  s.appendTermBegin();
-  s.appendExponent(0, 1); // index, exponent
-  s.appendExponent(1, 1); // index, exponent
-  s.appendExponent(2, 1); // index, exponent
-  s.appendExponent(3, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendExponent(0, 1); // index, exponent
-  s.appendExponent(1, 1); // index, exponent
-  s.appendExponent(2, 1); // index, exponent
-  s.appendExponent(4, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendExponent(0, 1); // index, exponent
-  s.appendExponent(1, 1); // index, exponent
-  s.appendExponent(3, 1); // index, exponent
-  s.appendExponent(4, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendExponent(0, 1); // index, exponent
-  s.appendExponent(2, 1); // index, exponent
-  s.appendExponent(3, 1); // index, exponent
-  s.appendExponent(4, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendExponent(1, 1); // index, exponent
-  s.appendExponent(2, 1); // index, exponent
-  s.appendExponent(3, 1); // index, exponent
-  s.appendExponent(4, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendPolynomialDone();
-  s.appendPolynomialBegin(2);
-  s.appendTermBegin();
-  s.appendExponent(0, 1); // index, exponent
-  s.appendExponent(1, 1); // index, exponent
-  s.appendExponent(2, 1); // index, exponent
-  s.appendExponent(3, 1); // index, exponent
-  s.appendExponent(4, 1); // index, exponent
-  s.appendTermDone(1); // coefficient
-  s.appendTermBegin();
-  s.appendTermDone(100); // coefficient
-  s.appendPolynomialDone();
-  s.idealDone();
-
-  std::ostringstream computedStr;
-  mgb::IdealStreamLog<> computed(computedStr, s.modulus(), s.varCount());
-
-  mgb::computeGroebnerBasis(s, computed);
+  for (int i = 0; i < 2; ++i) {
+    mgb::GroebnerConfiguration configuration(101, 5);
+    const auto reducer = i == 0 ?
+      mgb::GroebnerConfiguration::ClassicReducer :
+      mgb::GroebnerConfiguration::MatrixReducer;
+    configuration.setReducer(reducer);
+    mgb::GroebnerInputIdealStream input(configuration);
+    makeCyclic5Basis(input);
+
+    mgb::NullIdealStream computed(input.modulus(), input.varCount());
+
+    mgb::computeGroebnerBasis(input, computed);
+  }
 }

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