[mathicgb] 271/393: IO format now includes lex or revlex ordering explicitly. It still doesn't do anything yet.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:18 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 e5a7ec698926873c95645bf55da3f2d9e4395f2e
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date:   Wed Apr 17 15:00:32 2013 -0400

    IO format now includes lex or revlex ordering explicitly. It still doesn't do anything yet.
---
 src/mathicgb.cpp            |  2 ++
 src/mathicgb/MonoMonoid.hpp | 37 +++++++++++++++++++++++---
 src/mathicgb/PolyRing.cpp   |  3 ++-
 src/mathicgb/PolyRing.hpp   |  7 ++++-
 src/test/MonoMonoid.cpp     | 63 ++++++++++++++++++++++++++++-----------------
 src/test/poly-test.cpp      |  2 +-
 6 files changed, 85 insertions(+), 29 deletions(-)

diff --git a/src/mathicgb.cpp b/src/mathicgb.cpp
index 9af7c77..d3e491b 100755
--- a/src/mathicgb.cpp
+++ b/src/mathicgb.cpp
@@ -480,6 +480,8 @@ namespace mgb {
       ring(
         conf.modulus(),
         static_cast<int>(conf.varCount()),
+        conf.monomialOrder().first ==
+          GroebnerConfiguration::LexicographicBaseOrder,
         conf.monomialOrder().second
       ),
       ideal(ring),
diff --git a/src/mathicgb/MonoMonoid.hpp b/src/mathicgb/MonoMonoid.hpp
index a01d2f8..679b01c 100755
--- a/src/mathicgb/MonoMonoid.hpp
+++ b/src/mathicgb/MonoMonoid.hpp
@@ -133,7 +133,11 @@ public:
 
   // *** Constructors and accessors
 
-  MonoMonoid(VarIndex varCount, const std::vector<Exponent>& gradings):
+  MonoMonoid(
+    const VarIndex varCount,
+    const bool lexBaseOrder,
+    const std::vector<Exponent>& gradings
+  ):
     mVarCount(varCount),
     mGradingCount(varCount == 0 ? 0 : gradings.size() / varCount),
     mOrderIndexBegin(HasComponent + varCount),
@@ -154,6 +158,7 @@ public:
       }()
     ),
     mGradings(),
+    mLexBaseOrder(lexBaseOrder),
     mPool(*this)
   {
     MATHICGB_ASSERT(varCount == 0 || gradings.size() % varCount == 0);
@@ -188,6 +193,7 @@ public:
     mHashCoefficients(mVarCount),
     mGradingIsTotalDegree(true),
     mGradings(),
+    mLexBaseOrder(false),
     mPool(*this)
   {
     std::srand(0); // To use the same hash coefficients every time.
@@ -208,6 +214,7 @@ public:
     mHashCoefficients(monoid.mHashCoefficients),
     mGradingIsTotalDegree(monoid.mGradingIsTotalDegree),
     mGradings(monoid.mGradings),
+    mLexBaseOrder(monoid.mLexBaseOrder),
     mPool(*this)
   {
     MATHICGB_ASSERT(debugAssertValid());
@@ -227,6 +234,7 @@ public:
     mHashCoefficients(monoid.mHashCoefficients),
     mGradingIsTotalDegree(monoid.mGradingIsTotalDegree),
     mGradings(monoid.mGradings),
+    mLexBaseOrder(monoid.mLexBaseOrder),
     mPool(*this)
   {
     MATHICGB_ASSERT(debugAssertValid());
@@ -1599,6 +1607,11 @@ private:
   /// implicitly it is a single grading consisting of all 1s.
   std::vector<Exponent> mGradings;
 
+  /// If true then lex is used to break ties. Otherwise, revlex is
+  /// used. This applies as well to degrees, which implies that
+  /// degrees have to be stored negated if doing revlex.
+  const bool mLexBaseOrder;
+
   mutable MonoPool mPool;
 };
 
@@ -1624,6 +1637,22 @@ auto MonoMonoid<E, HC, SH, SO>::readMonoid(std::istream& in) -> MonoMonoid {
   VarIndex varCount;
   in >> varCount;
 
+  bool lexBaseOrder = false;
+  std::string str;
+  char c;
+  in >> c;
+  in.unget();
+  if (!std::isdigit(c)) {
+    std::string str;
+    in >> str;
+    if (str == "revlex")
+      lexBaseOrder = false;
+    else if (str == "lex")
+      lexBaseOrder = true;
+    else
+      mathic::reportError("Expected lex or revlex but read \"" + str + "\".");
+  }
+
   VarIndex gradingCount;
   in >> gradingCount;
 
@@ -1634,7 +1663,7 @@ auto MonoMonoid<E, HC, SH, SO>::readMonoid(std::istream& in) -> MonoMonoid {
     in >> e;
     gradings[w] = static_cast<Exponent>(e);
   }
-  return MonoMonoid(varCount, gradings);
+  return MonoMonoid(varCount, lexBaseOrder, gradings);
 }
 
 template<class E, bool HC, bool SH, bool SO>
@@ -1642,7 +1671,9 @@ void MonoMonoid<E, HC, SH, SO>::printMonoid(std::ostream& out) const {
   using MonoMonoidHelper::unchar;
   typedef typename unchar<Exponent>::type UncharredExponent;
 
-  out << varCount() << ' ' << gradingCount() << '\n';
+  out << varCount() << '\n'
+      << (mLexBaseOrder ? "lex" : "revlex")
+      << ' ' << gradingCount() << '\n';
   if (mGradingIsTotalDegree) {
     MATHICGB_ASSERT(mGradings.empty());
     for (VarIndex var = 0; var < varCount(); ++var)
diff --git a/src/mathicgb/PolyRing.cpp b/src/mathicgb/PolyRing.cpp
index 35bfc64..812b577 100755
--- a/src/mathicgb/PolyRing.cpp
+++ b/src/mathicgb/PolyRing.cpp
@@ -18,9 +18,10 @@ PolyRing::PolyRing(const Field& field, const Monoid& monoid):
 PolyRing::PolyRing(
   coefficient p0,
   int nvars,
+  bool lexBaseOrder,
   const std::vector<exponent>& weights
 ):
-  mField(p0), mMonoid(nvars, weights)
+  mField(p0), mMonoid(nvars, lexBaseOrder, weights)
 {}
 
 ///////////////////////////////////////
diff --git a/src/mathicgb/PolyRing.hpp b/src/mathicgb/PolyRing.hpp
index 78fdaef..0b79c0c 100755
--- a/src/mathicgb/PolyRing.hpp
+++ b/src/mathicgb/PolyRing.hpp
@@ -200,7 +200,12 @@ public:
   typedef MonoMonoid<exponent> Monoid;
   typedef PrimeField<unsigned long> Field;
 
-  PolyRing(coefficient charac, int nvars, const std::vector<exponent>& weights);
+  PolyRing(
+    coefficient charac,
+    int nvars,
+    bool lexBaseOrder,
+    const std::vector<exponent>& weights
+  );
   PolyRing(const Field& field, const Monoid& monoid);
 
   size_t getMemoryUse() const {
diff --git a/src/test/MonoMonoid.cpp b/src/test/MonoMonoid.cpp
index 9704289..facbf13 100755
--- a/src/test/MonoMonoid.cpp
+++ b/src/test/MonoMonoid.cpp
@@ -195,23 +195,38 @@ TYPED_TEST(Monoid, ReadWriteMonoid) {
   typedef TypeParam Monoid;
   typedef typename Monoid::VarIndex VarIndex;
 
-  const auto check =
-    [](const char* str, VarIndex varCount, VarIndex gradingCount) -> void
-  {
-    std::istringstream in(str);
-    const auto m = Monoid::readMonoid(in);
-    ASSERT_EQ(varCount, m.varCount());
-    ASSERT_EQ(gradingCount, m.gradingCount());
+  const auto check = [](
+    const char* const inStr,
+    const char* const outStr,
+    const VarIndex varCount,
+    const VarIndex gradingCount
+    ) -> void {
+    for (int i = 0; i < 2; ++i) {
+      const char* str = i == 0 ? inStr : outStr;
+      if (str == 0)
+        continue;
 
-    std::ostringstream out;
-    m.printMonoid(out);
-    ASSERT_EQ(str, out.str());
+      std::istringstream in(str);
+      const auto m = Monoid::readMonoid(in);
+      ASSERT_EQ(varCount, m.varCount());
+      ASSERT_EQ(gradingCount, m.gradingCount());
+      
+      std::ostringstream out;
+      m.printMonoid(out);
+      ASSERT_EQ(outStr, out.str());
+    }
   };
-  check("0 0\n", 0, 0);
-  check("1 1\n 2\n", 1, 1);
-  check("1 2\n 3\n 4\n", 1, 2);
-  check("2 2\n 3 4\n 5 6\n", 2, 2);
-  check("4 1\n 1 1 1 1\n", 4, 1);
+  check("0 0\n", "0\nrevlex 0\n", 0, 0);
+  check("1 1\n 2\n", "1\nrevlex 1\n 2\n", 1, 1);
+  check("1 2\n 3\n 4\n", "1\nrevlex 2\n 3\n 4\n", 1, 2);
+  check("2 2\n 3 4\n 5 6\n", "2\nrevlex 2\n 3 4\n 5 6\n", 2, 2);
+  check("4 1\n 1 1 1 1\n", "4\nrevlex 1\n 1 1 1 1\n", 4, 1);
+
+  check("0 lex 0", "0\nlex 0\n", 0, 0);
+  check("1 lex 1 2", "1\nlex 1\n 2\n", 1, 1);
+  check("1 lex 2 3 4", "1\nlex 2\n 3\n 4\n", 1, 2);
+  check("2 lex 2 3 4 5 6", "2\nlex 2\n 3 4\n 5 6\n", 2, 2);
+  check("4 lex 1 1 1 1 1", "4\nlex 1\n 1 1 1 1\n", 4, 1);
 }
 
 TYPED_TEST(Monoid, MonoPool) {
@@ -580,13 +595,15 @@ TYPED_TEST(Monoid, Order) {
   const auto sortedTotalDegreeRevLex =
     "1 Z A z c b a c2 bc ac b2 ab a2 c3 abc b3 a3";
   check(Monoid(52), sortedTotalDegreeRevLex);
-  check(Monoid(52, std::vector<Exponent>(52, 1)), sortedTotalDegreeRevLex);
-  check(Monoid(52, std::vector<Exponent>(52, 7)), sortedTotalDegreeRevLex);
+  check
+    (Monoid(52, false, std::vector<Exponent>(52, 1)), sortedTotalDegreeRevLex);
+  check
+    (Monoid(52, false, std::vector<Exponent>(52, 7)), sortedTotalDegreeRevLex);
   std::vector<Exponent> revLexGradings(52, 1);
   for (size_t grading = 51; grading != static_cast<size_t>(-1); --grading)
     for (size_t var = 0; var < 52; ++var)
       revLexGradings.push_back(var == grading ? -1 : 0);
-  check(Monoid(52, revLexGradings), sortedTotalDegreeRevLex);
+  check(Monoid(52, false, revLexGradings), sortedTotalDegreeRevLex);
 
   std::vector<Exponent> dupGradings = {
      5, 2, 3,
@@ -606,7 +623,7 @@ TYPED_TEST(Monoid, Order) {
   // bc3: 11 21
   // ab3: 11 21
   const auto sortedDupGradingsRevLex = "1 b c a bc c2 b3 bc3 ab3";
-  check(Monoid(3, dupGradings), sortedDupGradingsRevLex);
+  check(Monoid(3, false, dupGradings), sortedDupGradingsRevLex);
 
   std::vector<Exponent> lexGradings = {
     0, 0, 1,
@@ -615,7 +632,7 @@ TYPED_TEST(Monoid, Order) {
   };
   const auto sortedLex =
     "1 a a2 a3 b ab a2b b2 ab2 b3 c ac bc abc c2 ac2 bc2 c3";
-  check(Monoid(3, lexGradings), sortedLex);
+  check(Monoid(3, false, lexGradings), sortedLex);
 }
 
 TYPED_TEST(Monoid, RelativelyPrime) {
@@ -657,9 +674,9 @@ TYPED_TEST(Monoid, HasAmpleCapacityTotalDegree) {
   for (VarIndex varCount = 1; varCount < 33; ++varCount) {
     Monoid monoidTotalDegree(varCount);
     std::vector<Exponent> v(varCount, 1);
-    Monoid monoidTotalDegreeImplicit(varCount, v);
+    Monoid monoidTotalDegreeImplicit(varCount, false, v);
     v[0] = 7;
-    Monoid monoidGeneral(varCount, v);
+    Monoid monoidGeneral(varCount, false, v);
 
     Monoid* monoids[] = {
       &monoidTotalDegree,
@@ -712,7 +729,7 @@ TYPED_TEST(Monoid, CopyEqualConversion) {
   typedef MonoMonoid<Exponent, HasComponent, false, false> MonoidNone;
   typedef MonoMonoid<Exponent, HasComponent, true, true> MonoidAll;
   for (VarIndex varCount = 1; varCount < 33; ++varCount) {
-    MonoidNone none(varCount, std::vector<Exponent>(varCount, 1));
+    MonoidNone none(varCount, false, std::vector<Exponent>(varCount, 1));
     Monoid some(none);
     MonoidAll all(some);
 
diff --git a/src/test/poly-test.cpp b/src/test/poly-test.cpp
index 55f3b7d..5c12e15 100755
--- a/src/test/poly-test.cpp
+++ b/src/test/poly-test.cpp
@@ -49,7 +49,7 @@ TEST(PolyRing, read) {
   std::unique_ptr<PolyRing> R(ringFromString(ringinfo));
   R->write(o);
 
-  EXPECT_EQ("32003 6 1\n 1 1 1 1 1 1\n", o.str());
+  EXPECT_EQ("32003 6\nrevlex 1\n 1 1 1 1 1 1\n", o.str());
 }
 
 TEST(Poly,readwrite) {

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