[mathicgb] 296/393: Added a class that describes a monomial order and added a constructor in MonoMonoid that takes that as a parameter. MonoOrder is not yet used otherwise.
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:23 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 38e6f231968176d43d9f82b6b45db340e1a300f4
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date: Tue Apr 23 07:45:00 2013 +0200
Added a class that describes a monomial order and added a constructor in MonoMonoid that takes that as a parameter. MonoOrder is not yet used otherwise.
---
Makefile.am | 2 +-
src/mathicgb/MonoMonoid.hpp | 39 ++++++++++++++++++
src/mathicgb/MonoOrder.hpp | 97 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 137 insertions(+), 1 deletion(-)
diff --git a/Makefile.am b/Makefile.am
index 96879c8..46ca9be 100755
--- a/Makefile.am
+++ b/Makefile.am
@@ -65,7 +65,7 @@ libmathicgb_la_SOURCES = src/mathicgb/BjarkeGeobucket2.cpp \
src/mathicgb/F4MatrixProjection.cpp src/mathicgb/ScopeExit.hpp \
src/mathicgb.cpp src/mathicgb.h src/mathicgb/mtbb.hpp \
src/mathicgb/PrimeField.hpp src/mathicgb/MonoMonoid.hpp \
- MonoProcessor.hpp
+ src/mathicgb/MonoProcessor.hpp src/mathicgb/MonoOrder.hpp
# The headers that libmathicgb installs.
diff --git a/src/mathicgb/MonoMonoid.hpp b/src/mathicgb/MonoMonoid.hpp
index c04113d..9e2ba63 100755
--- a/src/mathicgb/MonoMonoid.hpp
+++ b/src/mathicgb/MonoMonoid.hpp
@@ -1,6 +1,7 @@
#ifndef MATHICGB_MONO_MONOID_GUARD
#define MATHICGB_MONO_MONOID_GUARD
+#include "MonoOrder.hpp"
#include <vector>
#include <algorithm>
#include <memtailor.h>
@@ -133,6 +134,44 @@ public:
// *** Constructors and accessors
+ MonoMonoid(MonoOrder<Exponent>& order):
+ mVarCount(order.varCount()),
+ mGradingCount(gradingCount()),
+ mOrderIndexBegin(HasComponent + mVarCount),
+ mOrderIndexEnd(mOrderIndexBegin + StoreOrder * mGradingCount),
+ mEntryCount // todo: use max here
+ (mOrderIndexEnd + StoreHash == 0 ? 1 : mOrderIndexEnd + StoreHash),
+ mHashCoefficients(mVarCount),
+ mGradingIsTotalDegreeRevLex(order.gradingIsTotalDegreeRevLex()),
+ mGradings(),
+ mLexBaseOrder(order.baseOrder() == MonoOrder<Exponent>::LexBaseOrder),
+ mPool(*this)
+ {
+ if (!mGradingIsTotalDegreeRevLex) {
+ // Take negative values since reverse lex makes bigger values
+ // give smaller monomials, but we need bigger degrees to give
+ // bigger monomials.
+ auto& gradings = order.gradings();
+ MATHICGB_ASSERT(varCount == 0 || gradings.size() % varCount == 0);
+ MATHICGB_ASSERT(mLexBaseOrder || (varCount == 0) == (gradings.empty()));
+
+ for (VarIndex grading = 0; grading < gradingCount(); ++grading) {
+ for (VarIndex var = 0; var < varCount; ++var) {
+ auto w = gradings[gradingsOppositeRowIndex(grading, var)];
+ if (!mLexBaseOrder)
+ w = -w;
+ mGradings[gradingsIndex(grading, var)] = w;
+ }
+ }
+ }
+
+ std::srand(0); // To use the same hash coefficients every time.
+ for (VarIndex var = 0; var < varCount; ++var)
+ mHashCoefficients[var] = static_cast<HashValue>(std::rand());
+
+ MATHICGB_ASSERT(debugAssertValid());
+ }
+
MonoMonoid(
const VarIndex varCount,
const bool lexBaseOrder,
diff --git a/src/mathicgb/MonoOrder.hpp b/src/mathicgb/MonoOrder.hpp
new file mode 100755
index 0000000..93c615f
--- /dev/null
+++ b/src/mathicgb/MonoOrder.hpp
@@ -0,0 +1,97 @@
+#ifndef MATHICGB_MONO_ORDER_GUARD
+#define MATHICGB_MONO_ORDER_GUARD
+
+#include <vector>
+
+/// Class used to describe an monomial order or a module monomial
+/// order. Use this class to construct a monoid. The monoid does the
+/// actual comparisons.
+///
+/// You can extend the functionality for ordering offered here for
+/// module mononials by pre- and post-processing. See MonoProcessor.
+template<class Weight>
+class MonoOrder;
+
+template<class W>
+class MonoOrder {
+public:
+ typedef W Weight;
+ typedef size_t VarIndex;
+
+ MonoOrder(const VarIndex varCount):
+ mVarCount(varCount),
+ mGradings(false),
+ mTotalDegreeGrading(true),
+ mBaseOrder(RevLexBaseOrder),
+ mComponentBefore(ComponentLast),
+ mUseSchreyerOrder(true),
+ mComponentsAscendingDesired(true)
+ {}
+
+ const VarIndex varCount() const {return mVarCount;}
+
+ /// Set the matrix that defines the order. The entry layout is row
+ /// major. The first row is considered first, then the second row
+ /// and so on.
+ void setGradings(std::vector<Weight>&& gradings) {
+ MATHICGB_ASSERT(varCount() > 0 || gradings.empty());
+ MATHICGB_ASSERT(varCount() == 0 || gradings.size() % varCount() == 0);
+ mGradings = std::move(gradings);
+ mTotalDegreeGrading = false;
+ }
+
+ /// As calling setGradings with a vector of varCount() 1's.
+ void setTotalDegreeGrading() const {
+ mGradings.clear();
+ mTotalDegreeGrading = true;
+ }
+
+ std::vector<Weight>& gradings() {
+ if (mTotalDegreeGrading && mGradings.empty())
+ mGradings.resize(varCount(), 1);
+ return mGradings;
+ }
+
+ bool gradingIsTotalDegreeRevLex() const {
+ return baseOrder() == RevLexBaseOrder && mTotalDegreeGrading;
+ }
+
+ /// Returns the number of rows in the grading vector.
+ size_t gradingCount() const {return mGradings.size() / varCount();}
+
+ enum BaseOrder {
+ LexBaseOrder = 0,
+ RevLexBaseOrder = 1
+ };
+ /// Set the order to use as a tie-braker for the grading matrix.
+ void setBaseOrder(BaseOrder baseOrder) {mBaseOrder = baseOrder;}
+ BaseOrder baseOrder() const {return mBaseOrder;}
+
+ static const size_t ComponentLast = static_cast<size_t>(-1);
+
+ /// The component is considered before row (grading) and after row
+ /// (grading - 1) in the order matrix. If grading == 0 then the
+ /// component is considered before anything else. If grading ==
+ /// gradingCount() then grading is considered after the grading
+ /// matrix but before the base order. If grading is ComponentLast,
+ /// then the component is used as the final tie breaker after both
+ /// the grading matrix and the base order. All values of this setting
+ /// except for ComponentLast imply overhead equivalent to one extra row
+ /// in the grading matrix even for monoids without components.
+ /// ComponentLast has no overhead.
+ void setComponentBefore(const size_t grading) const {
+ MATHICGB_ASSERT(grading == ComponentLast || grading <= gradingCount);
+ mComponentBefore = grading;
+ }
+
+private:
+ const VarIndex mVarCount;
+ std::vector<Weight> mGradings;
+ bool mTotalDegreeGrading;
+ BaseOrder mBaseOrder;
+ size_t mComponentBefore;
+ bool mUseSchreyerOrder;
+ bool mComponentsAscendingDesired;
+};
+
+#endif
--
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