[mathicgb] 392/393: Changed the library interface to accept module inputs. This is currently still only connected to the same non-module backend as before.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:39 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 3acd01636ac86ccf36a71d2f81ed67511fb230ba
Author: Bjarke Hammersholt Roune <www.broune.com>
Date:   Sun Oct 6 15:01:53 2013 -0700

    Changed the library interface to accept module inputs. This is currently still only connected to the same non-module backend as before.
---
 src/mathicgb.cpp      |  62 ++++++++++++-----
 src/mathicgb.h        | 157 ++++++++++++++++++++++++++++++++---------
 src/test/mathicgb.cpp | 188 ++++++++++++++++++++++++++++----------------------
 3 files changed, 277 insertions(+), 130 deletions(-)

diff --git a/src/mathicgb.cpp b/src/mathicgb.cpp
index 17f4bce..60a5fbc 100755
--- a/src/mathicgb.cpp
+++ b/src/mathicgb.cpp
@@ -72,9 +72,10 @@ bool logNumber(const char* logName, double& number) {
 
 namespace mgbi {
   struct StreamStateChecker::Pimpl {
-    Pimpl(Coefficient modulus, VarIndex varCount):
+    Pimpl(Coefficient modulus, VarIndex varCount, Component comCount):
       modulus(modulus),
       varCount(varCount),
+      comCount(comCount),
       state(Initial),
 
       hasClaimedPolyCount(false),
@@ -100,6 +101,7 @@ namespace mgbi {
 
     const Coefficient modulus;
     const VarIndex varCount;
+    const Component comCount;
 
     State state;
 
@@ -133,8 +135,12 @@ namespace mgbi {
     return true;
   };
 
-  StreamStateChecker::StreamStateChecker(const Coefficient modulus, const VarIndex varCount):
-    mPimpl(new Pimpl(modulus, varCount))
+  StreamStateChecker::StreamStateChecker(
+    const Coefficient modulus,
+    const VarIndex varCount,
+    const Component comCount
+  ):
+    mPimpl(new Pimpl(modulus, varCount, comCount))
   {
     try {
       MATHICGB_STREAM_CHECK(isPrime(modulus), "The modulus must be prime");
@@ -211,7 +217,7 @@ namespace mgbi {
     MATHICGB_ASSERT(mPimpl->debugAssertValid());
   }
 
-  void StreamStateChecker::appendTermBegin() {
+  void StreamStateChecker::appendTermBegin(const Component com) {
     MATHICGB_ASSERT(mPimpl->debugAssertValid());
 
     MATHICGB_STREAM_CHECK(
@@ -232,6 +238,11 @@ namespace mgbi {
       "The number of terms in a polynomial must not exceed the amount "
       "passed to appendPolynomialBegin()."
     );
+    MATHICGB_STREAM_CHECK(
+      com < mPimpl->comCount,
+      "The component passed to appendTermBegin must be strictly less "
+      "than the number of components."
+    );
      
     mPimpl->state = Pimpl::MakingTerm;
     mPimpl->seenTermCount += 1;
@@ -333,9 +344,14 @@ namespace mgbi {
 // ** Implementation of the class GroebnerConfiguration
 
 struct GroebnerConfiguration::Pimpl {
-  Pimpl(Coefficient modulus, VarIndex varCount):
+  Pimpl(
+    Coefficient modulus,
+    VarIndex varCount,
+    Component comCount
+  ):
     mModulus(modulus),
     mVarCount(varCount),
+    mComCount(comCount),
     mBaseOrder(RevLexDescendingBaseOrder),
     mGradings(varCount, 1),
     mComponentBefore(ComponentAfterBaseOrder),
@@ -387,6 +403,7 @@ struct GroebnerConfiguration::Pimpl {
 
   const Coefficient mModulus;
   const VarIndex mVarCount;
+  const Component mComCount;
   BaseOrder mBaseOrder;
   std::vector<Exponent> mGradings;
   size_t mComponentBefore;
@@ -403,9 +420,10 @@ struct GroebnerConfiguration::Pimpl {
 
 GroebnerConfiguration::GroebnerConfiguration(
   Coefficient modulus,
-  VarIndex varCount
+  VarIndex varCount,
+  Component comCount
 ):
-  mPimpl(new Pimpl(modulus, varCount))
+  mPimpl(new Pimpl(modulus, varCount, comCount))
 {
   if (modulus > std::numeric_limits<unsigned short>::max()) {
     MATHICGB_ASSERT_NO_ASSUME(false);
@@ -445,6 +463,10 @@ auto GroebnerConfiguration::varCount() const -> VarIndex {
   return mPimpl->mVarCount;
 }
 
+auto GroebnerConfiguration::comCount() const -> Component {
+  return mPimpl->mComCount;
+}
+
 const char* GroebnerConfiguration::baseOrderName(BaseOrder order) {
   switch (order) {
     case RevLexDescendingBaseOrder:
@@ -619,7 +641,7 @@ struct GroebnerInputIdealStream::Pimpl {
     conf(conf)
 #ifdef MATHICGB_DEBUG
     , hasBeenDestroyed(false),
-    checker(conf.modulus(), conf.varCount())
+    checker(conf.modulus(), conf.varCount(), conf.comCount())
 #endif
   {}
 
@@ -655,16 +677,20 @@ GroebnerInputIdealStream::~GroebnerInputIdealStream() {
   delete[] mExponents;
 }
 
-const GroebnerConfiguration& GroebnerInputIdealStream::configuration() {
+const GroebnerConfiguration& GroebnerInputIdealStream::configuration() const {
   return mPimpl->conf;
 }
 
 auto GroebnerInputIdealStream::modulus() const -> Coefficient {
-  return mPimpl->conf.modulus();
+  return configuration().modulus();
 }
 
 auto GroebnerInputIdealStream::varCount() const -> VarIndex {
-  return mPimpl->conf.varCount();
+  return configuration().varCount();
+}
+
+auto GroebnerInputIdealStream::comCount() const -> Component {
+  return configuration().comCount();
 }
 
 void GroebnerInputIdealStream::idealBegin() {
@@ -704,9 +730,9 @@ void GroebnerInputIdealStream::appendPolynomialBegin(size_t termCount) {
   MATHICGB_ASSERT(debugAssertValid());
 }
 
-void GroebnerInputIdealStream::appendTermBegin() {
+void GroebnerInputIdealStream::appendTermBegin(const Component com) {
   MATHICGB_ASSERT(debugAssertValid());
-  MATHICGB_IF_DEBUG(mPimpl->checker.appendTermBegin());
+  MATHICGB_IF_DEBUG(mPimpl->checker.appendTermBegin(com));
 
   std::fill_n(mExponents, varCount(), 0);
 
@@ -817,9 +843,7 @@ namespace mgbi {
       mPimpl->mTermIt = mPimpl->basis->getPoly(mPimpl->polyIndex)->begin();
   }
 
-  auto IdealAdapter::nextTerm() const
-  -> std::pair<Coefficient, const Exponent*>
-  {
+  auto IdealAdapter::nextTerm() const -> ConstTerm {
     MATHICGB_ASSERT(mPimpl->basis.get() != 0);
     MATHICGB_ASSERT(mPimpl->polyIndex < mPimpl->basis->size());
 
@@ -845,7 +869,11 @@ namespace mgbi {
         mPimpl->mTermIt = mPimpl->basis->getPoly(mPimpl->polyIndex)->begin();
     }
 
-    return std::make_pair(from.coef, to);
+    ConstTerm term;
+    term.coef = from.coef;
+    term.exponents = to;
+    term.com = 0;
+    return term;
   }
 }
 
diff --git a/src/mathicgb.h b/src/mathicgb.h
index b889688..2b021ce 100755
--- a/src/mathicgb.h
+++ b/src/mathicgb.h
@@ -46,19 +46,50 @@ namespace mgb { // Part of the public interface of MathicGB
   /// Use this class to describe a configuration of a Groebner basis algorithm
   /// that you want to run.
   ///
+  /// If you came here to compute the Groebner basis of an ideal in a
+  /// polynomial ring and you don't want to deal with modules: Don't worry
+  /// about it. A module with one component over a polynomial ring is the
+  /// same thing as that ring. Simply set the componentCount to 1. Then all
+  /// (module) monomials will have component 0 and you can just ignore that.
+  /// The internal implementation has a special case for this case you will
+  /// not pay an overhead for this other than passing a few 0 components
+  /// through the interface.
+  ///
   /// @todo: expose more of the available functionality.
   class GroebnerConfiguration {
   public:
+    // Type for the coefficient of a term. 2*x is a term with coefficient 2.
     typedef unsigned int Coefficient;
+
+    /// Type to specify a variable in the polynomial ring. If the variables
+    /// are x, y, z in that order, then x has index 0, y has index 1 and z
+    /// has index 2.
     typedef size_t VarIndex;
+
+    /// Type for the exponent of a variable. If x is a variable, then
+    /// x*x = x^2 has exponent 2.
     typedef int Exponent;
 
-    GroebnerConfiguration(Coefficient modulus, VarIndex varCount);
+    /// Type for the component of a module monomial. The module monomial
+    /// x*y*z * e_i has component i.
+    typedef size_t Component;
+
+    /// A configuration in a module over a polynomial ring with varCount
+    /// variables and the coefficients are from the finite field with
+    /// modulus elements. modulus must be a prime. The module has the basis
+    /// e_0, ..., e_k where k is componentCount - 1.
+    GroebnerConfiguration(
+      Coefficient modulus,
+      VarIndex varCount,
+      Component comCount
+    );
+
     GroebnerConfiguration(const GroebnerConfiguration& conf);
     ~GroebnerConfiguration();
 
     Coefficient modulus() const;
     VarIndex varCount() const;
+    Component comCount() const;
 
     enum BaseOrder {
       /// Reverse lexicographic order with x_1 > x_2 > ... > x_n.
@@ -265,11 +296,11 @@ namespace mgb { // Part of the public interface of MathicGB
     void* callbackDataInternal() const;
 
     struct Pimpl;
-    Pimpl* mPimpl;
+    Pimpl* const mPimpl;
   };
 
-  /// After making a configuration, use this class to communicate the input
-  /// basis you want want to run a Groebner basis algorithm on.
+  /// After making a configuration, use this class to communicate a basis
+  /// of the input ideal that you want to run a Groebner basis algorithm on.
   class GroebnerInputIdealStream {
   public:
     GroebnerInputIdealStream(const GroebnerConfiguration& conf);
@@ -278,16 +309,21 @@ namespace mgb { // Part of the public interface of MathicGB
     typedef GroebnerConfiguration::Coefficient Coefficient;
     typedef GroebnerConfiguration::VarIndex VarIndex;
     typedef GroebnerConfiguration::Exponent Exponent;
+    typedef GroebnerConfiguration::Component Component;
 
-    const GroebnerConfiguration& configuration();
+    const GroebnerConfiguration& configuration() const;
     Coefficient modulus() const;
     VarIndex varCount() const;
+    Component comCount() const;
 
     void idealBegin();
     void idealBegin(size_t polyCount);
     void appendPolynomialBegin();
     void appendPolynomialBegin(size_t termCount);
-    void appendTermBegin();
+
+    /// Signals the beginning of communication of a module term of the
+    /// current module element.
+    void appendTermBegin(Component com);
 
     /// The sequence of indices appended to a term must be in strictly
     /// ascending order.
@@ -313,7 +349,7 @@ namespace mgb { // Part of the public interface of MathicGB
   ///   - varCount() const;
   ///   - idealBegin(size_t polyCount);
   ///   - void appendPolynomialBegin(size_t termCount);
-  ///   - void appendTermBegin();
+  ///   - void appendTermBegin(Component com);
   ///   - void appendExponent(VarIndex index, Exponent exponent);
   ///   - void appendTermDone(Coefficient coefficient);
   ///   - void appendPolynomialDone();
@@ -371,23 +407,30 @@ namespace mgb { // Part of the public interface of MathicGB
     typedef GroebnerConfiguration::Coefficient Coefficient;
     typedef GroebnerConfiguration::VarIndex VarIndex;
     typedef GroebnerConfiguration::Exponent Exponent;
+    typedef GroebnerConfiguration::Component Component;
 
     /// All calls are written to log and then passed on to stream.
     IdealStreamLog(std::ostream& log, Stream& stream);
 
     /// All calls are written to log.
-    IdealStreamLog(std::ostream& log, Coefficient modulus, VarIndex varCount);
+    IdealStreamLog(
+      std::ostream& log,
+      Coefficient modulus,
+      VarIndex varCount,
+      Component comCount
+    );
 
     ~IdealStreamLog();
 
     Coefficient modulus() const;
     VarIndex varCount() const;
+    Component comCount() const;
 
     void idealBegin();
     void idealBegin(size_t polyCount);
     void appendPolynomialBegin();
     void appendPolynomialBegin(size_t termCount);
-    void appendTermBegin();
+    void appendTermBegin(Component com);
     void appendExponent(VarIndex index, Exponent exponent);
     void appendTermDone(Coefficient coefficient);
     void appendPolynomialDone();
@@ -396,6 +439,7 @@ namespace mgb { // Part of the public interface of MathicGB
   private:
     const Coefficient mModulus;
     const VarIndex mVarCount;
+    const Component mComCount;
     Stream* const mStream;
     std::ostream& mLog;
   };
@@ -408,17 +452,23 @@ namespace mgb { // Part of the public interface of MathicGB
     typedef GroebnerConfiguration::Coefficient Coefficient;
     typedef GroebnerConfiguration::VarIndex VarIndex;
     typedef GroebnerConfiguration::Exponent Exponent;
+    typedef GroebnerConfiguration::Component Component;
 
-    NullIdealStream(Coefficient modulus, VarIndex varCount);
+    NullIdealStream(
+      Coefficient modulus,
+      VarIndex varCount,
+      Component comCount
+    );
 
     Coefficient modulus() const {return mModulus;}
     VarIndex varCount() const {return mVarCount;}
+    Component comCount() const {return mComCount;}
 
     void idealBegin() {}
     void idealBegin(size_t polyCount) {}
     void appendPolynomialBegin() {}
     void appendPolynomialBegin(size_t termCount) {}
-    void appendTermBegin() {}
+    void appendTermBegin(Component com) {}
     void appendExponent(VarIndex index, Exponent exponent) {}
     void appendTermDone(Coefficient coefficient) {}
     void appendPolynomialDone() {}
@@ -427,6 +477,7 @@ namespace mgb { // Part of the public interface of MathicGB
   private:
     const Coefficient mModulus;
     const VarIndex mVarCount;
+    const Component mComCount;
   };
 
   template<class OutputStream>
@@ -442,15 +493,20 @@ namespace mgb { // Part of the public interface of MathicGB
       typedef GroebnerConfiguration::Coefficient Coefficient;
       typedef GroebnerConfiguration::VarIndex VarIndex;
       typedef GroebnerConfiguration::Exponent Exponent;
+      typedef GroebnerConfiguration::Component Component;
 
-      StreamStateChecker(const Coefficient modulus, const VarIndex varCount);
+      StreamStateChecker(
+        const Coefficient modulus,
+        const VarIndex varCount,
+        const Component comCount
+      );
       ~StreamStateChecker();
 
       void idealBegin();
       void idealBegin(size_t polyCount);
       void appendPolynomialBegin();
       void appendPolynomialBegin(size_t termCount);
-      void appendTermBegin();
+      void appendTermBegin(Component com);
       void appendExponent(VarIndex index, Exponent exponent);
       void appendTermDone(Coefficient coefficient);
       void appendPolynomialDone();
@@ -475,17 +531,19 @@ namespace mgb { // Part of the public interface of MathicGB
     typedef GroebnerConfiguration::Coefficient Coefficient;
     typedef GroebnerConfiguration::VarIndex VarIndex;
     typedef GroebnerConfiguration::Exponent Exponent;
+    typedef GroebnerConfiguration::Component Component;
 
     IdealStreamChecker(Stream& stream);
 
     Coefficient modulus() const;
     VarIndex varCount() const;
+    Component comCount() const;
 
     void idealBegin();
     void idealBegin(size_t polyCount);
     void appendPolynomialBegin();
     void appendPolynomialBegin(size_t termCount);
-    void appendTermBegin();
+    void appendTermBegin(Component com);
     void appendExponent(VarIndex index, Exponent exponent);
     void appendTermDone(Coefficient coefficient);
     void appendPolynomialDone();
@@ -517,7 +575,7 @@ namespace mgb {
   // the caller to use different implementations of the STL.
   inline void GroebnerInputIdealStream::appendExponent(
     const VarIndex index,
-    Exponent exponent
+    const Exponent exponent
   ) {
 #ifdef MATHICGB_DEBUG
     assert(index < varCount());
@@ -584,25 +642,33 @@ namespace mgb {
   IdealStreamLog<Stream>::IdealStreamLog(std::ostream& log, Stream& stream):
     mModulus(stream.modulus()),
     mVarCount(stream.varCount()),
+    mComCount(stream.comCount()),
     mStream(&stream),
     mLog(log)
   {
     mLog << "IdealStreamLog s(stream, log); // modulus=" << mModulus
-      << ", varCount=" << mVarCount << '\n';
+      << ", varCount=" << mVarCount
+      << ", comCount=" << mComCount << '\n';
   }
 
   template<class Stream> 
   IdealStreamLog<Stream>::IdealStreamLog(
     std::ostream& log,
     Coefficient modulus,
-    VarIndex varCount
+    VarIndex varCount,
+    Component comCount
   ):
     mModulus(modulus),
     mVarCount(varCount),
+    mComCount(comCount),
     mStream(0),
     mLog(log)
   {
-    mLog << "IdealStreamLog s(stream, " << mModulus << ", " << mVarCount << ");\n";
+    mLog
+      << "IdealStreamLog s(stream, "
+      << mModulus << ", "
+      << mVarCount << ", "
+      << mComCount << ");\n";
   }
 
   template<class Stream> 
@@ -622,6 +688,12 @@ namespace mgb {
     return mVarCount;
   }
 
+  template<class Stream> 
+  typename IdealStreamLog<Stream>::Component
+  IdealStreamLog<Stream>::comCount() const {
+    return mComCount;
+  }
+
   template<class Stream>
   void IdealStreamLog<Stream>::idealBegin() {
     mLog << "s.idealBegin();\n";
@@ -651,10 +723,10 @@ namespace mgb {
   }
 
   template<class Stream> 
-  void IdealStreamLog<Stream>::appendTermBegin() {
-    mLog << "s.appendTermBegin();\n";
+  void IdealStreamLog<Stream>::appendTermBegin(const Component com) {
+    mLog << "s.appendTermBegin(" << com << ");\n";
     if (mStream != 0)
-      mStream->appendTermBegin();
+      mStream->appendTermBegin(com);
   }
 
   template<class Stream> 
@@ -693,7 +765,7 @@ namespace mgb {
   template<class Stream>
   IdealStreamChecker<Stream>::IdealStreamChecker(Stream& stream):
     mStream(stream),
-    mChecker(stream.modulus(), stream.varCount())
+    mChecker(stream.modulus(), stream.varCount(), stream.comCount())
   {}
 
   template<class Stream>
@@ -709,6 +781,12 @@ namespace mgb {
   }
 
   template<class Stream>
+  typename IdealStreamChecker<Stream>::Component
+  IdealStreamChecker<Stream>::comCount() const {
+    return mStream.comCount();
+  }
+
+  template<class Stream>
   void IdealStreamChecker<Stream>::idealBegin() {
     mChecker.idealBegin();
     mStream.idealBegin();
@@ -733,9 +811,9 @@ namespace mgb {
   }
 
   template<class Stream>
-  void IdealStreamChecker<Stream>::appendTermBegin() {
-    mChecker.appendTermBegin();
-    mStream.appendTermBegin();
+  void IdealStreamChecker<Stream>::appendTermBegin(const Component com) {
+    mChecker.appendTermBegin(com);
+    mStream.appendTermBegin(com);
   }
 
   template<class Stream>
@@ -763,12 +841,20 @@ namespace mgb {
   }
 
   // ** Implementation of the class NullIdealStream
-  // This class has to be inline as it is a template.
+  // This class isn't a template, but it might become one and it is so
+  // trivial that making it inline is not a big deal - it's not much more
+  // than just its interface. The idea is also for this class to have minimal
+  // overhead and making it inline helps with that.
+
   inline NullIdealStream::NullIdealStream(
     Coefficient modulus,
-    VarIndex varCount
+    VarIndex varCount,
+    Component comCount
   ):
-    mModulus(modulus), mVarCount(varCount) {}
+    mModulus(modulus),
+    mVarCount(varCount),
+    mComCount(comCount)
+  {}
 
   namespace mgbi {
     /// Used to read an internal MathicGB ideal without exposing the type of
@@ -778,16 +864,23 @@ namespace mgb {
       typedef GroebnerConfiguration::Coefficient Coefficient;
       typedef GroebnerConfiguration::VarIndex VarIndex;
       typedef GroebnerConfiguration::Exponent Exponent;
-      typedef std::pair<Coefficient, const Exponent*> ConstTerm;
+      typedef GroebnerConfiguration::Component Component;
       typedef size_t PolyIndex;
       typedef size_t TermIndex;
 
+      struct ConstTerm {
+        Coefficient coef;
+        const Exponent* exponents;
+        Component com;
+      };
+
       IdealAdapter();
       ~IdealAdapter();
 
       VarIndex varCount() const;
       size_t polyCount() const;
       size_t termCount(PolyIndex poly) const;
+      Component componentCount() const;
 
       /// Sets the internal position to the first term of the first polynomial.
       void toFirstTerm();
@@ -828,11 +921,11 @@ namespace mgb {
       const size_t termCount = ideal.termCount(polyIndex);
       output.appendPolynomialBegin(termCount);
       for (size_t termIndex = 0; termIndex < termCount; ++termIndex) {
-        output.appendTermBegin();
         const ConstTerm term = ideal.nextTerm();
+        output.appendTermBegin(term.com);
         for (size_t var = 0; var < varCount; ++var)
-          output.appendExponent(var, term.second[var]);
-        output.appendTermDone(term.first);
+          output.appendExponent(var, term.exponents[var]);
+        output.appendTermDone(term.coef);
       }
       output.appendPolynomialDone();
     }
diff --git a/src/test/mathicgb.cpp b/src/test/mathicgb.cpp
index 4ace516..0a31130 100755
--- a/src/test/mathicgb.cpp
+++ b/src/test/mathicgb.cpp
@@ -10,20 +10,23 @@ using namespace mgb;
 namespace {
   template<class Stream>
   void makeBasis(Stream& s) {
+    MATHICGB_ASSERT(s.varCount() >= 3);
+    MATHICGB_ASSERT(s.comCount() >= 1);
+
     s.idealBegin();
       s.appendPolynomialBegin(); // x^2 - y
-        s.appendTermBegin();
+        s.appendTermBegin(0);
           s.appendExponent(0,2);
         s.appendTermDone(1);
-        s.appendTermBegin();
+        s.appendTermBegin(0);
           s.appendExponent(1,1);
         s.appendTermDone(s.modulus() - 1);
       s.appendPolynomialDone();
       s.appendPolynomialBegin(2); // x^3-z
-        s.appendTermBegin();
+        s.appendTermBegin(0);
           s.appendExponent(0,3);
         s.appendTermDone(1);
-        s.appendTermBegin();
+        s.appendTermBegin(0);
           s.appendExponent(2,1);
         s.appendTermDone(s.modulus() - 1);
       s.appendPolynomialDone();
@@ -34,36 +37,36 @@ namespace {
   void makeGroebnerBasis(Stream& s) {
     s.idealBegin(3);
       s.appendPolynomialBegin(2); // x^2 - y
-        s.appendTermBegin();
+        s.appendTermBegin(0);
           s.appendExponent(0, 2);
           s.appendExponent(1, 0);
           s.appendExponent(2, 0);
         s.appendTermDone(1);
-        s.appendTermBegin();
+        s.appendTermBegin(0);
           s.appendExponent(0, 0);
           s.appendExponent(1, 1);
           s.appendExponent(2, 0);
         s.appendTermDone(s.modulus() - 1);
       s.appendPolynomialDone();
       s.appendPolynomialBegin(2); // xy - z
-        s.appendTermBegin();
+        s.appendTermBegin(0);
           s.appendExponent(0, 1);
           s.appendExponent(1, 1);
           s.appendExponent(2, 0);
         s.appendTermDone(1);
-        s.appendTermBegin();
+        s.appendTermBegin(0);
           s.appendExponent(0, 0);
           s.appendExponent(1, 0);
           s.appendExponent(2, 1);
         s.appendTermDone(s.modulus() - 1);
       s.appendPolynomialDone();
       s.appendPolynomialBegin(2); // y^2 - xz
-        s.appendTermBegin();
+        s.appendTermBegin(0);
           s.appendExponent(0, 0);
           s.appendExponent(1, 2);
           s.appendExponent(2, 0);
         s.appendTermDone(1);
-        s.appendTermBegin();
+        s.appendTermBegin(0);
           s.appendExponent(0, 1);
           s.appendExponent(1, 0);
           s.appendExponent(2, 1);
@@ -76,97 +79,97 @@ namespace {
   void makeCyclic5Basis(Stream& s) {
     s.idealBegin(5); // polyCount
     s.appendPolynomialBegin(5);
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(0, 1); // index, exponent
     s.appendTermDone(1); // coefficient
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(1, 1); // index, exponent
     s.appendTermDone(1); // coefficient
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(2, 1); // index, exponent
     s.appendTermDone(1); // coefficient
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(3, 1); // index, exponent
     s.appendTermDone(1); // coefficient
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(4, 1); // index, exponent
     s.appendTermDone(1); // coefficient
     s.appendPolynomialDone();
     s.appendPolynomialBegin(5);
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(0, 1); // index, exponent
     s.appendExponent(1, 1); // index, exponent
     s.appendTermDone(1); // coefficient
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(1, 1); // index, exponent
     s.appendExponent(2, 1); // index, exponent
     s.appendTermDone(1); // coefficient
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(2, 1); // index, exponent
     s.appendExponent(3, 1); // index, exponent
     s.appendTermDone(1); // coefficient
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(0, 1); // index, exponent
     s.appendExponent(4, 1); // index, exponent
     s.appendTermDone(1); // coefficient
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(3, 1); // index, exponent
     s.appendExponent(4, 1); // index, exponent
     s.appendTermDone(1); // coefficient
     s.appendPolynomialDone();
     s.appendPolynomialBegin(5);
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     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.appendTermBegin(0);
     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.appendTermBegin(0);
     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.appendTermBegin(0);
     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.appendTermBegin(0);
     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.appendTermBegin(0);
     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.appendTermBegin(0);
     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.appendTermBegin(0);
     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.appendTermBegin(0);
     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.appendTermBegin(0);
     s.appendExponent(1, 1); // index, exponent
     s.appendExponent(2, 1); // index, exponent
     s.appendExponent(3, 1); // index, exponent
@@ -174,14 +177,14 @@ namespace {
     s.appendTermDone(1); // coefficient
     s.appendPolynomialDone();
     s.appendPolynomialBegin(2);
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     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.appendTermBegin(0);
     s.appendTermDone(100); // coefficient
     s.appendPolynomialDone();
     s.idealDone();
@@ -191,20 +194,20 @@ namespace {
   void makeSimpleIdeal(Stream& s) { // variables a,b,c,d.  a2-bc, ab-cd.
     s.idealBegin();
       s.appendPolynomialBegin(); // a^2-b*c
-        s.appendTermBegin();
+        s.appendTermBegin(0);
           s.appendExponent(0,2);
         s.appendTermDone(1);
-        s.appendTermBegin();
+        s.appendTermBegin(0);
           s.appendExponent(1,1);
           s.appendExponent(2,1);
         s.appendTermDone(s.modulus() - 1);
       s.appendPolynomialDone();
       s.appendPolynomialBegin(2); // a*b-c*d
-        s.appendTermBegin();
+        s.appendTermBegin(0);
           s.appendExponent(0,1);
           s.appendExponent(1,1);
         s.appendTermDone(1);
-        s.appendTermBegin();
+        s.appendTermBegin(0);
           s.appendExponent(2,1);
           s.appendExponent(3,1);
         s.appendTermDone(s.modulus() - 1);
@@ -218,13 +221,13 @@ namespace {
     // (order: eliminate 1 variable: [1 0 0 0; 1 1 1 1]).
     s.idealBegin(4); // polyCount
     s.appendPolynomialBegin(2);
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(0, 2); // index, exponent
     s.appendExponent(1, 0); // index, exponent
     s.appendExponent(2, 0); // index, exponent
     s.appendExponent(3, 0); // index, exponent
     s.appendTermDone(1); // coefficient
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(0, 0); // index, exponent
     s.appendExponent(1, 1); // index, exponent
     s.appendExponent(2, 1); // index, exponent
@@ -232,13 +235,13 @@ namespace {
     s.appendTermDone(100); // coefficient
     s.appendPolynomialDone();
     s.appendPolynomialBegin(2);
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(0, 1); // index, exponent
     s.appendExponent(1, 1); // index, exponent
     s.appendExponent(2, 0); // index, exponent
     s.appendExponent(3, 0); // index, exponent
     s.appendTermDone(1); // coefficient
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(0, 0); // index, exponent
     s.appendExponent(1, 0); // index, exponent
     s.appendExponent(2, 1); // index, exponent
@@ -246,13 +249,13 @@ namespace {
     s.appendTermDone(100); // coefficient
     s.appendPolynomialDone();
     s.appendPolynomialBegin(2);
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(0, 1); // index, exponent
     s.appendExponent(1, 0); // index, exponent
     s.appendExponent(2, 1); // index, exponent
     s.appendExponent(3, 1); // index, exponent
     s.appendTermDone(1); // coefficient
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(0, 0); // index, exponent
     s.appendExponent(1, 2); // index, exponent
     s.appendExponent(2, 1); // index, exponent
@@ -260,13 +263,13 @@ namespace {
     s.appendTermDone(100); // coefficient
     s.appendPolynomialDone();
     s.appendPolynomialBegin(2);
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(0, 0); // index, exponent
     s.appendExponent(1, 3); // index, exponent
     s.appendExponent(2, 1); // index, exponent
     s.appendExponent(3, 0); // index, exponent
     s.appendTermDone(1); // coefficient
-    s.appendTermBegin();
+    s.appendTermBegin(0);
     s.appendExponent(0, 0); // index, exponent
     s.appendExponent(1, 0); // index, exponent
     s.appendExponent(2, 2); // index, exponent
@@ -279,16 +282,26 @@ namespace {
 
 TEST(MathicGBLib, NullIdealStream) {
   {
-    mgb::NullIdealStream stream(2, 3);
+    mgb::NullIdealStream stream(2, 3, 1);
     ASSERT_EQ(2, stream.modulus());
     ASSERT_EQ(3, stream.varCount());
+    ASSERT_EQ(1, stream.comCount());
     makeBasis(stream);
   }
 
   {
-    mgb::NullIdealStream stream(101, 0);
+    mgb::NullIdealStream stream(2, 3, 4);
+    ASSERT_EQ(2, stream.modulus());
+    ASSERT_EQ(3, stream.varCount());
+    ASSERT_EQ(4, stream.comCount());
+    makeBasis(stream);
+  }
+
+  {
+    mgb::NullIdealStream stream(101, 0, 0);
     ASSERT_EQ(101, stream.modulus());
     ASSERT_EQ(0, stream.varCount());
+    ASSERT_EQ(0, stream.comCount());
   }
 }
 
@@ -297,25 +310,25 @@ TEST(MathicGBLib, IdealStreamLog) {
     const char* const idealStr = 
       "s.idealBegin();\n"
       "s.appendPolynomialBegin();\n"
-      "s.appendTermBegin();\n"
+      "s.appendTermBegin(0);\n"
       "s.appendExponent(0, 2); // index, exponent\n"
       "s.appendTermDone(1); // coefficient\n"
-      "s.appendTermBegin();\n"
+      "s.appendTermBegin(0);\n"
       "s.appendExponent(1, 1); // index, exponent\n"
       "s.appendTermDone(6); // coefficient\n"
       "s.appendPolynomialDone();\n"
       "s.appendPolynomialBegin(2);\n"
-      "s.appendTermBegin();\n"
+      "s.appendTermBegin(0);\n"
       "s.appendExponent(0, 3); // index, exponent\n"
       "s.appendTermDone(1); // coefficient\n"
-      "s.appendTermBegin();\n"
+      "s.appendTermBegin(0);\n"
       "s.appendExponent(2, 1); // index, exponent\n"
       "s.appendTermDone(6); // coefficient\n"
       "s.appendPolynomialDone();\n"
       "s.idealDone();\n";
 
     std::ostringstream out1;
-    mgb::IdealStreamLog<> stream1(out1, 7, 3);
+    mgb::IdealStreamLog<> stream1(out1, 7, 3, 1);
 
     mgb::IdealStreamChecker<decltype(stream1)> checker(stream1);
 
@@ -336,38 +349,50 @@ TEST(MathicGBLib, IdealStreamLog) {
 
     makeBasis(stream3);
     const auto str1 = std::string(
-      "IdealStreamLog s(stream, 7, 3);\n"
+      "IdealStreamLog s(stream, 7, 3, 1);\n"
     ) + idealStr;
     ASSERT_EQ(str1, out1.str())
       << "Displayed expected:\n" << out1.str()
       << "Displayed actual:\n" << str1 << std::endl;
 
     const auto str2 = std::string(
-      "IdealStreamLog s(stream, log); // modulus=7, varCount=3\n"
+      "IdealStreamLog s(stream, log); // modulus=7, varCount=3, comCount=1\n"
     ) + idealStr;
     ASSERT_EQ(str2, out2.str()) << "Displayed expected:\n" << out2.str();
     ASSERT_EQ(str2, out3.str()) << "Displayed expected:\n" << out3.str();
   }
 
-  // The ideal <> in no variables
+  // The ideal <> in no variables and no components
   {
     std::ostringstream out;
-    mgb::IdealStreamLog<> stream(out, 101, 0);
+    mgb::IdealStreamLog<> stream(out, 101, 0, 0);
     ASSERT_EQ(101, stream.modulus());
     ASSERT_EQ(0, stream.varCount());
     stream.idealBegin(0);
     stream.idealDone();
   }
 
-  // The ideal <1, 0> in no variables
+  // The ideal <0> in no variables and no components
   {
     std::ostringstream out;
-    mgb::IdealStreamLog<> stream(out, 101, 0);
+    mgb::IdealStreamLog<> stream(out, 101, 0, 0);
+    ASSERT_EQ(101, stream.modulus());
+    ASSERT_EQ(0, stream.varCount());
+    stream.idealBegin(1);
+      stream.appendPolynomialBegin(0); // 0
+      stream.appendPolynomialDone();
+    stream.idealDone();
+  }
+
+  // The ideal <1, 0> in no variables and 1 component
+  {
+    std::ostringstream out;
+    mgb::IdealStreamLog<> stream(out, 101, 0, 0);
     ASSERT_EQ(101, stream.modulus());
     ASSERT_EQ(0, stream.varCount());
     stream.idealBegin(2);
       stream.appendPolynomialBegin(0); // 1
-        stream.appendTermBegin();
+        stream.appendTermBegin(0);
         stream.appendTermDone(1);
       stream.appendPolynomialDone();
       stream.appendPolynomialBegin(0); // 0
@@ -377,41 +402,41 @@ TEST(MathicGBLib, IdealStreamLog) {
 }
 
 TEST(MathicGBLib, ZeroIdealGB) {
-  mgb::GroebnerConfiguration configuration(2, 0);
+  mgb::GroebnerConfiguration configuration(2, 0, 0);
   mgb::GroebnerInputIdealStream input(configuration);
   std::ostringstream out;
-  mgb::IdealStreamLog<> logStream(out, 2, 0);
+  mgb::IdealStreamLog<> logStream(out, 2, 0, 0);
 
   input.idealBegin(0);
   input.idealDone();
   mgb::computeGroebnerBasis(input, logStream);
 
   const auto msg =
-    "IdealStreamLog s(stream, 2, 0);\n"
+    "IdealStreamLog s(stream, 2, 0, 0);\n"
     "s.idealBegin(0); // polyCount\n"
     "s.idealDone();\n";
   EXPECT_EQ(msg, out.str());
 }
 
 TEST(MathicGBLib, OneIdealGB) {
-  mgb::GroebnerConfiguration configuration(2, 0);
+  mgb::GroebnerConfiguration configuration(2, 0, 1);
   mgb::GroebnerInputIdealStream input(configuration);
   std::ostringstream out;
-  mgb::IdealStreamLog<> logStream(out, 2, 0);
+  mgb::IdealStreamLog<> logStream(out, 2, 0, 1);
 
   input.idealBegin(1);
   input.appendPolynomialBegin(1);
-  input.appendTermBegin();
+  input.appendTermBegin(0);
   input.appendTermDone(1);
   input.appendPolynomialDone();
   input.idealDone();
   mgb::computeGroebnerBasis(input, logStream);
 
   const auto msg =
-     "IdealStreamLog s(stream, 2, 0);\n"
+     "IdealStreamLog s(stream, 2, 0, 1);\n"
      "s.idealBegin(1); // polyCount\n"
      "s.appendPolynomialBegin(1);\n"
-     "s.appendTermBegin();\n"
+     "s.appendTermBegin(0);\n"
      "s.appendTermDone(1); // coefficient\n"
      "s.appendPolynomialDone();\n"
      "s.idealDone();\n";
@@ -419,17 +444,17 @@ TEST(MathicGBLib, OneIdealGB) {
 }
 
 TEST(MathicGBLib, EasyGB) {
-  mgb::GroebnerConfiguration configuration(101, 3);
+  mgb::GroebnerConfiguration configuration(101, 3, 1);
   mgb::GroebnerInputIdealStream input(configuration);
   std::ostringstream computedStr;
-  mgb::IdealStreamLog<> computed(computedStr, 101, 3);
+  mgb::IdealStreamLog<> computed(computedStr, 101, 3, 1);
   mgb::IdealStreamChecker<decltype(computed)> checked(computed);
 
   makeBasis(input);
   mgb::computeGroebnerBasis(input, checked);
 
   std::ostringstream correctStr;
-  mgb::IdealStreamLog<> correct(correctStr, 101, 3);
+  mgb::IdealStreamLog<> correct(correctStr, 101, 3, 1);
   mgb::IdealStreamChecker<decltype(correct)> correctChecked(correct);
   makeGroebnerBasis(correctChecked);
 
@@ -439,17 +464,17 @@ TEST(MathicGBLib, EasyGB) {
 }
 
 TEST(MathicGBLib, EasyReGB) {
-  mgb::GroebnerConfiguration configuration(101, 3);
+  mgb::GroebnerConfiguration configuration(101, 3, 1);
   mgb::GroebnerInputIdealStream input(configuration);
   std::ostringstream computedStr;
-  mgb::IdealStreamLog<> computed(computedStr, 101, 3);
+  mgb::IdealStreamLog<> computed(computedStr, 101, 3, 1);
   mgb::IdealStreamChecker<decltype(computed)> checked(computed);
 
   makeGroebnerBasis(input);
   mgb::computeGroebnerBasis(input, checked);
 
   std::ostringstream correctStr;
-  mgb::IdealStreamLog<> correct(correctStr, 101, 3);
+  mgb::IdealStreamLog<> correct(correctStr, 101, 3, 1);
   mgb::IdealStreamChecker<decltype(correct)> correctChecked(correct);
   makeGroebnerBasis(correctChecked);
 
@@ -460,7 +485,7 @@ TEST(MathicGBLib, EasyReGB) {
 
 TEST(MathicGBLib, Cyclic5) {
   for (int i = 0; i < 2; ++i) {
-    mgb::GroebnerConfiguration configuration(101, 5);
+    mgb::GroebnerConfiguration configuration(101, 5, 1);
     const auto reducer = i == 0 ?
       mgb::GroebnerConfiguration::ClassicReducer :
       mgb::GroebnerConfiguration::MatrixReducer;
@@ -468,7 +493,8 @@ TEST(MathicGBLib, Cyclic5) {
     mgb::GroebnerInputIdealStream input(configuration);
     makeCyclic5Basis(input);
 
-    mgb::NullIdealStream computed(input.modulus(), input.varCount());
+    mgb::NullIdealStream computed
+      (input.modulus(), input.varCount(), input.comCount());
 
     mgb::computeGroebnerBasis(input, computed);
   }
@@ -493,7 +519,7 @@ namespace {
 TEST(MathicGBLib, EarlyExit) {
   typedef mgb::GroebnerConfiguration::Callback::Action Action;
   auto check = [](bool useClassic, int count, Action action) {
-    mgb::GroebnerConfiguration configuration(101, 5);
+    mgb::GroebnerConfiguration configuration(101, 5, 1);
     const auto reducer = useClassic ?
       mgb::GroebnerConfiguration::ClassicReducer :
       mgb::GroebnerConfiguration::MatrixReducer;
@@ -504,7 +530,7 @@ TEST(MathicGBLib, EarlyExit) {
     makeCyclic5Basis(input);
 
     std::ostringstream strOut;
-    mgb::IdealStreamLog<> out(strOut, 101, 5);
+    mgb::IdealStreamLog<> out(strOut, 101, 5, 1);
     mgb::computeGroebnerBasis(input, out);
     return strOut.str().size();
   };
@@ -514,7 +540,7 @@ TEST(MathicGBLib, EarlyExit) {
     size_t minSize = check(useClassic, 1, Action::StopWithPartialOutputAction);
     size_t midSize = check(useClassic, 4, Action::StopWithPartialOutputAction);
     size_t maxSize = check(useClassic, 1, Action::ContinueAction);
-    ASSERT_LT(none, 35u); // the stream writes a header even for no output
+    ASSERT_LT(none, 38u); // the stream writes a header even for no output
     ASSERT_LT(none, minSize);
     ASSERT_LT(minSize, midSize);
     ASSERT_LT(midSize, maxSize);
@@ -527,7 +553,7 @@ TEST(MathicGBLib, SimpleEliminationGB) {
   std::vector<Exponent> gradings(v, v + sizeof(v)/sizeof(*v));
 
   for (int i = 0; i < 2; ++i) {
-    mgb::GroebnerConfiguration configuration(101, 4);
+    mgb::GroebnerConfiguration configuration(101, 4, 1);
     const auto reducer = i == 0 ?
       mgb::GroebnerConfiguration::ClassicReducer :
       mgb::GroebnerConfiguration::MatrixReducer;
@@ -539,14 +565,14 @@ TEST(MathicGBLib, SimpleEliminationGB) {
 
     mgb::GroebnerInputIdealStream input(configuration);
     std::ostringstream computedStr;
-    mgb::IdealStreamLog<> computed(computedStr, 101, 4);
+    mgb::IdealStreamLog<> computed(computedStr, 101, 4, 1);
     mgb::IdealStreamChecker<decltype(computed)> checked(computed);
 
     makeSimpleIdeal(input);
     mgb::computeGroebnerBasis(input, checked);
 
     std::ostringstream correctStr;
-    mgb::IdealStreamLog<> correct(correctStr, 101, 4);
+    mgb::IdealStreamLog<> correct(correctStr, 101, 4, 1);
     mgb::IdealStreamChecker<decltype(correct)> correctChecked(correct);
     makeSimpleIdealGroebnerBasis(correctChecked);
 
@@ -563,7 +589,7 @@ TEST(MathicGBLib, SimpleEliminationGB) {
 }
 
 TEST(MathicGBLib, GlobalOrderOrNot) {
-  mgb::GroebnerConfiguration conf(101, 4);
+  mgb::GroebnerConfiguration conf(101, 4, 1);
   const auto lex =
     mgb::GroebnerConfiguration::BaseOrder::LexAscendingBaseOrder;
   const auto revLex =

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