[mathicgb] 302/393: Allowed component/revcomponent distinction to be passed on to the monoid in tests. Used this to get rid of OrderE entirely from FreeModuleOrder.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:26 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 f725bcf69a3d68c02c53ff025a24bddff1ff6da2
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date:   Mon Apr 29 20:08:04 2013 +0200

    Allowed component/revcomponent distinction to be passed on to the monoid in tests. Used this to get rid of OrderE entirely from FreeModuleOrder.
---
 src/cli/GBAction.cpp             | 16 +++++++-------
 src/cli/SigGBAction.cpp          | 18 ++++++++--------
 src/mathicgb/Basis.cpp           | 30 ++++++++++++++++++---------
 src/mathicgb/Basis.hpp           | 17 ++++++++++-----
 src/mathicgb/FreeModuleOrder.cpp | 43 ++------------------------------------
 src/mathicgb/MonoMonoid.hpp      | 14 ++++++-------
 src/mathicgb/MonoProcessor.hpp   | 45 +++++++++++++++++++---------------------
 src/mathicgb/SignatureGB.cpp     | 11 +++++-----
 src/mathicgb/SignatureGB.hpp     |  1 +
 src/mathicgb/io-util.cpp         |  8 +++++--
 src/test/gb-test.cpp             | 33 +++++++++++++++++++++++------
 11 files changed, 118 insertions(+), 118 deletions(-)

diff --git a/src/cli/GBAction.cpp b/src/cli/GBAction.cpp
index 02babb4..32f1322 100755
--- a/src/cli/GBAction.cpp
+++ b/src/cli/GBAction.cpp
@@ -58,14 +58,14 @@ void GBAction::performAction() {
   const std::string projectName = mParams.inputFileNameStem(0);
 
   // read input
-  std::unique_ptr<Basis> basis;
-  {
-    const std::string inputBasisFile = projectName + ".ideal";
-    std::ifstream inputFile(inputBasisFile.c_str());
-    if (inputFile.fail())
-      mic::reportError("Could not read input file \"" + inputBasisFile + '\n');
-    basis = Basis::parse(inputFile);
-  }
+  const std::string inputBasisFile = projectName + ".ideal";
+  std::ifstream inputFile(inputBasisFile.c_str());
+  if (inputFile.fail())
+    mic::reportError("Could not read input file \"" + inputBasisFile + '\n');
+  auto tuple = Basis::parse(inputFile);
+  auto& basis = std::get<1>(tuple);
+
+
   std::unique_ptr<PolyRing const> ring(&(basis->ring()));
 
   // run algorithm
diff --git a/src/cli/SigGBAction.cpp b/src/cli/SigGBAction.cpp
index 7d32653..b7566af 100755
--- a/src/cli/SigGBAction.cpp
+++ b/src/cli/SigGBAction.cpp
@@ -48,19 +48,19 @@ void SigGBAction::performAction() {
   mGBParams.perform();
 
   // read input file
-  std::unique_ptr<Basis> basis;
-  {
-    const std::string inputBasisFile = mParams.inputFileNameStem(0) + ".ideal";
-    std::ifstream inputFile(inputBasisFile.c_str());
-    if (inputFile.fail())
-      mic::reportError("Could not read input file \"" + inputBasisFile + '\n');
-    basis = Basis::parse(inputFile);
-  }
+  const std::string inputBasisFile = mParams.inputFileNameStem(0) + ".ideal";
+  std::ifstream inputFile(inputBasisFile.c_str());
+  if (inputFile.fail())
+    mic::reportError("Could not read input file \"" + inputBasisFile + '\n');
+  auto tuple = Basis::parse(inputFile);
+  auto& basis = std::get<1>(tuple);
+
   std::unique_ptr<PolyRing const> ring(&(basis->ring()));
 
   SignatureGB alg(
     std::move(*basis),
     mModuleOrder.value(),
+    std::get<2>(tuple)->componentsAscendingDesired(),
     Reducer::reducerType(mGBParams.mReducer.value()),
     mGBParams.mDivisorLookup.value(),
     mGBParams.mMonomialTable.value(),
@@ -117,7 +117,7 @@ const char* SigGBAction::description() const {
 const char* SigGBAction::shortDescription() const {
   return "Compute a signature Grobner basis";
 }
-  
+
 void SigGBAction::pushBackParameters(
   std::vector<mic::CliParameter*>& parameters
 ) {
diff --git a/src/mathicgb/Basis.cpp b/src/mathicgb/Basis.cpp
index 11788e5..7e86811 100755
--- a/src/mathicgb/Basis.cpp
+++ b/src/mathicgb/Basis.cpp
@@ -41,20 +41,30 @@ void Basis::sort(FreeModuleOrder& order) {
   std::sort(mGenerators.begin(), mGenerators.end(), cmp);
 }
 
-std::unique_ptr<Basis> Basis::parse(std::istream& in)
+auto Basis::parse(std::istream& in) -> Parsed
 {
-  PolyRing* R = PolyRing::read(in).first; // todo: fix this leak
-  size_t npolys;
-  in >> npolys;
-  auto result = make_unique<Basis>(*R);
-  for (size_t j = 0; j < npolys; ++j) {
-    auto g = make_unique<Poly>(*R);
+  auto r = PolyRing::read(in);
+  auto ring = make_unique<PolyRing>(std::move(*r.first));
+  delete r.first;
+
+  auto basis = make_unique<Basis>(*ring);
+  auto processor = make_unique<MonoProcessor<Monoid>>(ring->monoid());
+  processor->setComponentsAscendingDesired(r.second);
+
+  size_t polyCount;
+  in >> polyCount;
+  for (size_t i = 0; i < polyCount; ++i) {
+    auto poly = make_unique<Poly>(*ring);
     while (std::isspace(in.peek()))
       in.get();
-    g->parse(in);
-    result->insert(std::move(g));
+    poly->parse(in);
+    basis->insert(std::move(poly));
   }
-  return result;
+  return std::make_tuple(
+    std::move(ring),
+    std::move(basis),
+    std::move(processor)
+  );
 }
 
 void Basis::display(std::ostream& out, bool printComponent, bool componentIncreasingDesired) const
diff --git a/src/mathicgb/Basis.hpp b/src/mathicgb/Basis.hpp
index c01db6d..26eabf9 100755
--- a/src/mathicgb/Basis.hpp
+++ b/src/mathicgb/Basis.hpp
@@ -1,18 +1,20 @@
 #ifndef MATHICGB_BASIS_GUARD
 #define MATHICGB_BASIS_GUARD
 
+#include "Poly.hpp"
+#include "PolyRing.hpp"
+#include "MonoProcessor.hpp"
+#include <tuple>
 #include <memory>
 #include <algorithm>
 #include <vector>
-#include "Poly.hpp"
-#include "PolyRing.hpp"
 
 class Poly;
 class FreeModuleOrder;
 
+// Really: a list of polynomials
+// BUT ALSO maybe: includes memory areas for the polynomials?
 class Basis {
-  // Really: a list of polynomials
-  // BUT ALSO maybe: includes memory areas for the polynomials?
 public:
   Basis(const PolyRing &R) : mRing(R) {}
   ~Basis();
@@ -20,7 +22,12 @@ public:
   void insert(std::unique_ptr<Poly> p);
 
   /// reads ring, #gens, each generator in turn
-  static std::unique_ptr<Basis> parse(std::istream &i);
+  typedef std::tuple<
+    std::unique_ptr<PolyRing>,
+    std::unique_ptr<Basis>,
+    std::unique_ptr<MonoProcessor<PolyRing::Monoid>>
+  > Parsed;
+  static Parsed parse(std::istream &i);
 
   /// inverse operation to parse().
   void display(std::ostream &o, bool print_comp, bool componentIncreasingDesired) const;
diff --git a/src/mathicgb/FreeModuleOrder.cpp b/src/mathicgb/FreeModuleOrder.cpp
index 38a85eb..431407b 100755
--- a/src/mathicgb/FreeModuleOrder.cpp
+++ b/src/mathicgb/FreeModuleOrder.cpp
@@ -329,43 +329,6 @@ private:
   const size_t topindex;
 };
 
-// Let l(ae_i) be the leading monomial of ag_i.
-// Indexes are considered from high to low
-// rule 1: higher component wins (if mUp is true)
-// rule 1': lower components wins (if mUp is false)
-// rule 2: higher degree of l(ae_I) wins
-// rule 3: reverse lex on l(ae_i)
-class OrderE
-{
-public:
-  OrderE(const PolyRing& ring):
-    mRing(&ring), topindex(ring.maxMonomialSize() - 2)
-  {}
-
-  int signatureCompare(const_monomial a, const_monomial b) const {
-    if (*a != *b)
-      return *a < *b ? GT : LT;
-    return mRing->monomialCompare(a, b);
-  }
-
-  int signatureCompare(const_monomial a, const_monomial m2, const_monomial b) const {
-    int cmp = *a - *b;
-    if (cmp != 0) {
-      if (cmp < 0) return GT;
-      if (cmp > 0) return LT;
-    }
-    return mRing->monomialCompare(a, m2, b);
-  }
-
-  virtual char const* description() const {
-    return "IndexDown SchreyerGrevLex";
-  }
-
-private:
-  PolyRing const* const mRing;
-  size_t const topindex; // taken from R
-};
-
 void FreeModuleOrder::displayOrderTypes(std::ostream &o)
 {
   o << "FreeModule orders:" << std::endl;
@@ -387,16 +350,14 @@ std::unique_ptr<FreeModuleOrder> FreeModuleOrder::makeOrder(FreeModuleOrderType
   case 4:
   case 5:
   case 1:
+  case 6:
+  case 7:
     return make_unique<ConcreteOrder<OrderA>>(ring);
 
   case 2:
   case 3:
    return make_unique<ConcreteOrder<OrderC>>(ring);
 
-  case 6:
-  case 7:
-    return make_unique<ConcreteOrder<OrderE>>(ring);
-
   default: break;
   }
 
diff --git a/src/mathicgb/MonoMonoid.hpp b/src/mathicgb/MonoMonoid.hpp
index c7e7dbc..6451e3a 100755
--- a/src/mathicgb/MonoMonoid.hpp
+++ b/src/mathicgb/MonoMonoid.hpp
@@ -335,7 +335,7 @@ public:
   /// desired that i>j => e_i > e_j.
   static std::pair<MonoMonoid, bool> readMonoid(std::istream& in);
   void printMonoid
-    (const bool componentIncreasingDesired, std::ostream& out) const;
+    (const bool componentsAscendingDesired, std::ostream& out) const;
 
   bool operator==(const MonoMonoid& monoid) const {
     return this == &monoid;
@@ -1768,7 +1768,7 @@ auto MonoMonoid<E, HC, SH, SO>::readMonoid(std::istream& in) ->
   in >> gradingCount;
 
   Gradings gradings(static_cast<size_t>(varCount) * gradingCount);
-  bool componentIncreasingDesired = true;
+  bool componentsAscendingDesired = true;
   auto componentCompareIndex = Order::ComponentAfterBaseOrder;
   size_t w = 0;
   for (VarIndex grading = 0; grading <  gradingCount; ++grading) {
@@ -1779,9 +1779,9 @@ auto MonoMonoid<E, HC, SH, SO>::readMonoid(std::istream& in) ->
       std::string str;
       in >> str;
       if (str == "component")
-        componentIncreasingDesired = true;
+        componentsAscendingDesired = true;
       else if (str == "revcomponent")
-        componentIncreasingDesired = false;
+        componentsAscendingDesired = false;
       else
         mathic::reportError
           ("Expected component or revcomponent but read \"" + str + "\".");
@@ -1808,12 +1808,12 @@ auto MonoMonoid<E, HC, SH, SO>::readMonoid(std::istream& in) ->
     lexBaseOrder ? Order::LexBaseOrder : Order::RevLexBaseOrder,
     componentCompareIndex
   );
-  return std::make_pair(MonoMonoid(order), componentIncreasingDesired);
+  return std::make_pair(MonoMonoid(order), componentsAscendingDesired);
 }
 
 template<class E, bool HC, bool SH, bool SO>
 void MonoMonoid<E, HC, SH, SO>::printMonoid(
-  const bool componentIncreasingDesired,
+  const bool componentsAscendingDesired,
   std::ostream& out
 ) const {
   using MonoMonoidHelper::unchar;
@@ -1828,7 +1828,7 @@ void MonoMonoid<E, HC, SH, SO>::printMonoid(
       HasComponent &&
       grading == gradingCount() - 1 - componentGradingIndex()
     ) {
-      out << (componentIncreasingDesired ? " component\n" : " revcomponent\n");
+      out << (componentsAscendingDesired ? " component\n" : " revcomponent\n");
       continue;
     }
 
diff --git a/src/mathicgb/MonoProcessor.hpp b/src/mathicgb/MonoProcessor.hpp
index 2cc0416..2457ec7 100755
--- a/src/mathicgb/MonoProcessor.hpp
+++ b/src/mathicgb/MonoProcessor.hpp
@@ -1,8 +1,6 @@
 #ifndef MATHICGB_MONO_PROCESSOR_GUARD
 #define MATHICGB_MONO_PROCESSOR_GUARD
 
-#include "MonoMonoid.hpp"
-
 /// Does pre- and post-processing of monomials to implement monomial
 /// orders not directly supported by the monoid. This is so far only
 /// relevant for module monomials.
@@ -22,25 +20,19 @@ public:
   typedef typename Monoid::ConstMonoRef ConstMonoRef;
   typedef typename Monoid::ConstMonoPtr ConstMonoPtr;
 
-  static_assert(Monoid::HasComponent, "");
-
-  MonoProcessor(
-    bool componentsAscendingDesired, // todo: replace with MonoOrder
-    VarIndex componentCount, // todo: replace with MonoOrder
-    const Monoid& monoid,
-    MonoVector&& moduleAdjustments
-  ):
-    mMonoid(monoid),
-    mComponentsAscendingDesired(componentsAscendingDesired),
-    mComponentCount(componentCount),
-    mModuleAdjustmentsMemory(std::move(moduleAdjustments))
-  {
-    MATHICGB_ASSERT(mModuleAdjustmentsMemory.monoid() == this->monoid());
+  MonoProcessor(const Monoid& monoid):
+    mComponentsAscendingDesired(true),
+    mComponentCount(0),
+    mModuleAdjustmentsMemory(monoid)
+  {}
+
+  void setModuleAdjustments(MonoVector&& moduleAdjustments) {
+    MATHICGB_ASSERT(moduleAdjustments.monoid() == monoid());
     MATHICGB_ASSERT(mModuleAdjustmentsMemory.empty() ||
-      mModuleAdjustmentsMemory.size() == this->componentCount());
-    // todo: add a component count to the monoid and get it from there
-    // instead of storing it here.
+      mModuleAdjustmentsMemory.size() == componentCount());
+    mModuleAdjustmentsMemory = std::move(moduleAdjustments);
 
+    mModuleAdjustments.clear();
     for (
       auto it = mModuleAdjustmentsMemory.begin();
       it != mModuleAdjustmentsMemory.end();
@@ -79,15 +71,21 @@ public:
 
   bool needToReverseComponents() const {
     return Monoid::HasComponent &&
-      mComponentsAscendingDesired != mMonoid.componentsAscending();
+      componentsAscendingDesired() != monoid().componentsAscending();
+  }
+
+  void setComponentsAscendingDesired(bool value) {
+    mComponentsAscendingDesired = value;
   }
+  bool componentsAscendingDesired() const {return mComponentsAscendingDesired;}
 
   bool hasModuleAdjustments() const {
     return !mModuleAdjustments.empty();
   }
 
+  void setComponentCount(VarIndex count) {mComponentCount = count;}
   VarIndex componentCount() const {return mComponentCount;}
-  const Monoid& monoid() const {return mMonoid;}
+  const Monoid& monoid() const {return mModuleAdjustmentsMemory.monoid();}
 
 private:
   void operator==(const MonoProcessor&) const; // not available
@@ -106,9 +104,8 @@ private:
     return *mModuleAdjustments[component];
   }
 
-  const Monoid& mMonoid;
-  const bool mComponentsAscendingDesired;
-  const VarIndex mComponentCount;
+  bool mComponentsAscendingDesired;
+  VarIndex mComponentCount;
   MonoVector mModuleAdjustmentsMemory;
   std::vector<ConstMonoPtr> mModuleAdjustments;
 };
diff --git a/src/mathicgb/SignatureGB.cpp b/src/mathicgb/SignatureGB.cpp
index e8ecdec..9e352f3 100755
--- a/src/mathicgb/SignatureGB.cpp
+++ b/src/mathicgb/SignatureGB.cpp
@@ -15,6 +15,7 @@ int tracingLevel = 0;
 SignatureGB::SignatureGB(
   Basis&& basis,
   FreeModuleOrderType typ,
+  bool componentsAscendingDesired,
   Reducer::ReducerType reductiontyp,
   int divlookup_type,
   int montable_type,
@@ -48,12 +49,10 @@ SignatureGB::SignatureGB(
   if (typ == 5 || typ == 4 || typ == 3 || typ == 2 || typ == 6 || typ == 7)
     for (size_t gen = 0; gen < basis.size(); ++gen)
       schreyer.push_back(basis.getPoly(gen)->getLeadMonomial());
-  mProcessor = make_unique<MonoProcessor<Monoid>>(
-    typ == 2 || typ == 4 || typ == 6,
-    basis.size(),
-    monoid(),
-    std::move(schreyer)
-  );
+  mProcessor = make_unique<MonoProcessor<Monoid>>(monoid());
+  mProcessor->setComponentsAscendingDesired(componentsAscendingDesired);
+  mProcessor->setComponentCount(basis.size());
+  mProcessor->setModuleAdjustments(std::move(schreyer));
 
   // Populate GB
   for (size_t j = 0; j < basis.size(); j++)
diff --git a/src/mathicgb/SignatureGB.hpp b/src/mathicgb/SignatureGB.hpp
index 84995c0..ff3e47e 100755
--- a/src/mathicgb/SignatureGB.hpp
+++ b/src/mathicgb/SignatureGB.hpp
@@ -25,6 +25,7 @@ public:
   SignatureGB(
     Basis&& basis,
     FreeModuleOrderType typ,
+    bool componentsAscendingDesired,
     Reducer::ReducerType reductiontyp,
     int divlookup_type,
     int montable_type,
diff --git a/src/mathicgb/io-util.cpp b/src/mathicgb/io-util.cpp
index 40388a9..c1d5dfc 100755
--- a/src/mathicgb/io-util.cpp
+++ b/src/mathicgb/io-util.cpp
@@ -35,8 +35,12 @@ std::string toString(const Poly *g)
 
 std::unique_ptr<Basis> basisParseFromString(std::string str)
 {
-  std::istringstream i(str);
-  return std::unique_ptr<Basis>(Basis::parse(i));
+  // todo: fix the leak
+  std::istringstream in(str);
+  auto t = Basis::parse(in);
+  std::get<0>(t).release();
+  std::get<2>(t).release();
+  return std::move(std::get<1>(t));
 }
 
 std::unique_ptr<PolyRing> ringFromString(std::string ringinfo)
diff --git a/src/test/gb-test.cpp b/src/test/gb-test.cpp
index b98066e..6160e85 100755
--- a/src/test/gb-test.cpp
+++ b/src/test/gb-test.cpp
@@ -286,7 +286,19 @@ spairQueue	reducerType	divLookup	monTable	buchberger	postponeKoszul	useBaseDivis
     // check that we have a valid reducer type
     Reducer::ReducerType red = Reducer::ReducerType(reducerType);
     MATHICGB_ASSERT(static_cast<int>(red) == reducerType);
-    std::unique_ptr<Basis> I(basisParseFromString(idealStr));
+
+
+    std::istringstream in(idealStr);
+    auto tuple = Basis::parse(in);
+    auto& I = std::get<1>(tuple);
+
+    auto typ = freeModuleOrder;
+    if (typ == 2 || typ == 4)
+      std::get<2>(tuple)->setComponentsAscendingDesired(true);
+    else if (typ == 0 || typ == 1 || typ == 3 || typ == 5)
+      std::get<2>(tuple)->setComponentsAscendingDesired(false);
+    // xxx
+
     MATHICGB_ASSERT
       (Reducer::makeReducerNullOnUnknown(red, I->ring()).get() != 0);
 
@@ -307,10 +319,19 @@ spairQueue	reducerType	divLookup	monTable	buchberger	postponeKoszul	useBaseDivis
         << reducerType << ' ' << divLookup << ' '
         << monTable << ' ' << postponeKoszul << ' ' << useBaseDivisors;
     } else {
-     SignatureGB basis
-       (std::move(*I), freeModuleOrder, Reducer::reducerType(reducerType),
-         divLookup, monTable, postponeKoszul, useBaseDivisors,
-         preferSparseReducers, useSingularCriterionEarly, spairQueue);
+      SignatureGB basis(
+        std::move(*I),
+        freeModuleOrder,
+        std::get<2>(tuple)->componentsAscendingDesired(),
+        Reducer::reducerType(reducerType),
+        divLookup,
+        monTable,
+        postponeKoszul,
+        useBaseDivisors,
+        preferSparseReducers,
+        useSingularCriterionEarly,
+        spairQueue
+      );
       basis.computeGrobnerBasis();
       EXPECT_EQ(sigBasisStr, toString(basis.getGB(), 1))
         << reducerType << ' ' << divLookup << ' '
@@ -373,7 +394,7 @@ TEST(GB, gerdt93_0_5) {
 }
 
 TEST(GB, gerdt93_0_6) {
-  testGB(6, gerdt93Ideal(), gerdt93_gb_strat0_free6,
+  testGB(6, gerdt93IdealComponentFirst(true), gerdt93_gb_strat0_free6,
          gerdt93_syzygies_strat0_free6, gerdt93_initial_strat0_free6, 7);
 }
 

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