[mathicgb] 327/393: Added check to library interface setMonomialOrder that rejects non-global orders. Also added tests for this.
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:30 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 5d3559120047f212ac19feb3fb72add1c613a9fa
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date: Wed Aug 14 13:15:04 2013 +0200
Added check to library interface setMonomialOrder that rejects non-global orders. Also added tests for this.
---
src/mathicgb.cpp | 25 +++++++++++++++++++++----
src/mathicgb.h | 23 ++++++++++++++---------
src/test/mathicgb.cpp | 30 ++++++++++++++++++++++++++++++
3 files changed, 65 insertions(+), 13 deletions(-)
diff --git a/src/mathicgb.cpp b/src/mathicgb.cpp
index 13e3b07..765d059 100755
--- a/src/mathicgb.cpp
+++ b/src/mathicgb.cpp
@@ -444,18 +444,35 @@ namespace mgb {
return mPimpl->mVarCount;
}
- void GroebnerConfiguration::setMonomialOrderInternal(
+ bool GroebnerConfiguration::setMonomialOrderInternal(
MonomialOrderData order
) {
MATHICGB_ASSERT(Pimpl::baseOrderValid(order.baseOrder));
+ MATHICGB_ASSERT(varCount() != 0 || order.gradingsSize == 0);
MATHICGB_ASSERT(varCount() == 0 || order.gradingsSize % varCount() == 0);
-
- // Currently only reverse lex supported. TODO: make it work
- MATHICGB_ASSERT(order.baseOrder == ReverseLexicographicBaseOrder);
+
+ // Check if order is global.
+ if (varCount() != 0) {
+ const size_t rowCount = order.gradingsSize / varCount();
+ for (VarIndex var = 0; var < varCount(); ++var) {
+ // check if 1 < x_var.
+ for (size_t row = 0; row < rowCount; ++row) {
+ const Exponent e = order.gradings[row * varCount() + var];
+ if (e < 0)
+ return false; // order not global
+ if (e > 0)
+ goto orderGlobalForVar;
+ }
+ if (order.baseOrder == ReverseLexicographicBaseOrder)
+ return false; // order not global
+ orderGlobalForVar:;
+ }
+ }
mPimpl->mBaseOrder = order.baseOrder;
mPimpl->mGradings.assign
(order.gradings, order.gradings + order.gradingsSize);
+ return true;
}
auto GroebnerConfiguration::monomialOrderInternal() const ->
diff --git a/src/mathicgb.h b/src/mathicgb.h
index 7cba315..be693b9 100755
--- a/src/mathicgb.h
+++ b/src/mathicgb.h
@@ -86,16 +86,21 @@ namespace mgb { // Part of the public interface of MathicGB
/// to all the rows of the matrix, then the base order is used to break the
/// tie.
///
- /// You must ensure that the combination of grading and base order in fact
- /// defines a monomial order. For example, ungraded reverse lex is not
- /// a monomial order, so you must not ask for a Groebner basis with
- /// respect to that order.
+ /// An order is global if 1 is the smallest of all monomials. Equivalently,
+ /// if 1 < x for each variable x in the ambient ring. In MathicGB only
+ /// global orders are considered monomial orders and non-global orders
+ /// are not supported. setMonomialOrder will return true if the specified
+ /// order is global. Otherwise, setMonomialOrder returns false and the
+ /// requested order is NOT set. So you can ignore the return value if
+ /// and only if you are certain that the order you are requesting is in
+ /// fact global. For example, ungraded reverse lex is not a (global) monomial
+ /// order.
///
/// Each row of the matrix adds overhead to the Groebner basis
/// computation both in terms of time and space.
- ///
+ ///
/// The default grading is (1, ..., 1)-graded reverse lex.
- void setMonomialOrder(
+ bool setMonomialOrder(
BaseOrder order,
const std::vector<Exponent>& gradings
);
@@ -231,7 +236,7 @@ namespace mgb { // Part of the public interface of MathicGB
const Exponent* gradings;
size_t gradingsSize;
};
- void setMonomialOrderInternal(MonomialOrderData order);
+ bool setMonomialOrderInternal(MonomialOrderData order);
MonomialOrderData monomialOrderInternal() const;
static Callback::Action callbackCaller(void* obj);
@@ -517,7 +522,7 @@ namespace mgb {
// the library does internally. So we have to decay objects of
// type std::vector to pointers.
- inline void GroebnerConfiguration::setMonomialOrder(
+ inline bool GroebnerConfiguration::setMonomialOrder(
const BaseOrder baseOrder,
const std::vector<Exponent>& gradings
) {
@@ -530,7 +535,7 @@ namespace mgb {
gradings.empty() ? static_cast<Exponent*>(0) : &*gradings.begin(),
gradings.size()
};
- setMonomialOrderInternal(data);
+ return setMonomialOrderInternal(data);
}
inline std::pair<
diff --git a/src/test/mathicgb.cpp b/src/test/mathicgb.cpp
index c2b0010..1e75299 100755
--- a/src/test/mathicgb.cpp
+++ b/src/test/mathicgb.cpp
@@ -558,3 +558,33 @@ TEST(MathicGBLib, SimpleEliminationGB) {
#endif
}
}
+
+TEST(MathicGBLib, GlobalOrderOrNot) {
+ mgb::GroebnerConfiguration conf(101, 4);
+ const auto lex =
+ mgb::GroebnerConfiguration::BaseOrder::LexicographicBaseOrder;
+ const auto revLex =
+ mgb::GroebnerConfiguration::BaseOrder::ReverseLexicographicBaseOrder;
+
+ std::vector<mgb::GroebnerConfiguration::Exponent> mat;
+
+ mat = {};
+ ASSERT_TRUE(conf.setMonomialOrder(lex, mat));
+ ASSERT_FALSE(conf.setMonomialOrder(revLex, mat));
+
+ mat = {1,2,3,0};
+ ASSERT_TRUE(conf.setMonomialOrder(lex, mat));
+ ASSERT_FALSE(conf.setMonomialOrder(revLex, mat));
+
+ mat = {1,0,0,0, -3,0,1,2};
+ ASSERT_TRUE(conf.setMonomialOrder(lex, mat));
+ ASSERT_FALSE(conf.setMonomialOrder(revLex, mat));
+
+ mat = {1,1,0,0, 3,0,1,2};
+ ASSERT_TRUE(conf.setMonomialOrder(lex, mat));
+ ASSERT_TRUE(conf.setMonomialOrder(revLex, mat));
+
+ mat = {1,0,0,0, 3,1,1,-2};
+ ASSERT_FALSE(conf.setMonomialOrder(lex, mat));
+ ASSERT_FALSE(conf.setMonomialOrder(revLex, mat));
+}
--
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