62 mTerm->coef =
reinterpret_cast<number
>(coefficient);
99 bool setOrder(ring r, mgb::GroebnerConfiguration& conf) {
100 const VarIndex varCount = conf.varCount();
102 bool didSetComponentBefore =
false;
104 mgb::GroebnerConfiguration::RevLexDescendingBaseOrder;
106 std::vector<Exponent> gradings;
111 if (r->block0[
block] < 0 || r->block1[
block] < 0) {
112 WerrorS(
"Unexpected negative block0/block1 in ring.");
117 const int*
const weights = r->wvhdl[
block];
118 if (block0 > block1) {
119 WerrorS(
"Unexpected block0 > block1 in ring.");
125 if (block0 != 0 || block1 != 0 || weights != 0) {
126 WerrorS(
"Unexpected non-zero fields on c/C block in ring.");
129 if (didSetComponentBefore) {
130 WerrorS(
"Unexpected two c/C blocks in ring.");
133 didSetComponentBefore =
true;
135 conf.setComponentBefore
136 (mgb::GroebnerConfiguration::ComponentAfterBaseOrder);
138 conf.setComponentBefore(gradings.size() / varCount);
142 if (block0 == 0 || block1 == 0) {
143 WerrorS(
"Expected block0 != 0 and block1 != 0 in ring.");
146 if (block1 > varCount) {
148 WerrorS(
"Expected block1 <= #vars in ring.");
153 const size_t dim =
static_cast<size_t>(block1 - block0 + 1);
172 WerrorS(
"Block type a64 not supported for MathicGB interface.");
179 const bool wGrading =
182 if (oneGrading || minusOneGrading || wGrading || minusWGrading) {
183 const VarIndex begin = gradings.size();
184 gradings.resize(begin + varCount);
185 if (oneGrading || minusOneGrading) {
187 WerrorS(
"Expect wvhdl == 0 in Dp/dp/Ds/ds-block in ring.");
190 const Exponent value = oneGrading ? 1 : -1;
191 for (
int var = block0 - 1; var < block1; ++var)
192 gradings[begin + var] = value;
195 WerrorS(
"Expect wvhdl != 0 in a/Wp/wp/ws/Ws-block in ring.");
199 for (
int var = 0; var <
dim; ++var)
200 gradings[begin + (block0 - 1) + var] = weights[var];
202 for (
int var = 0; var <
dim; ++var)
203 gradings[begin + (block0 - 1) + var] = -weights[var];
211 const bool lexFromLeft =
219 const bool revlexFromRight =
225 if (lexFromLeft || lexFromRight || revlexFromLeft || revlexFromRight) {
232 baseOrder = mgb::GroebnerConfiguration::LexAscendingBaseOrder;
233 else if (revlexFromRight)
234 baseOrder = mgb::GroebnerConfiguration::RevLexDescendingBaseOrder;
235 else if (lexFromLeft)
236 baseOrder = mgb::GroebnerConfiguration::LexDescendingBaseOrder;
238 baseOrder = mgb::GroebnerConfiguration::RevLexAscendingBaseOrder;
242 const size_t begin = gradings.size();
243 gradings.resize(begin +
dim * varCount);
244 const Exponent value = (lexFromLeft || lexFromRight) ? 1 : -1;
245 if (lexFromLeft || revlexFromLeft) {
246 for (
size_t row = 0; row <
dim; ++row)
247 gradings[begin + row * varCount + (block0 - 1) + row] = value;
249 for (
size_t row = 0; row <
dim; ++row)
250 gradings[begin + row * varCount + (block1 - 1) - row] = value;
258 WerrorS(
"Expected wvhdl != 0 in M-block in ring.");
261 const size_t begin = gradings.size();
262 gradings.resize(begin +
dim * varCount);
263 for (
size_t row = 0; row <
dim; ++row)
264 for (
size_t col = block0 - 1; col < block1; ++col)
265 gradings[begin + row * varCount + col] = weights[row *
dim + col];
276 WerrorS(
"Schreyer order s/S/IS not supported in MathicGB interface.");
282 WerrorS(
"Block type am not supported in MathicGB interface");
286 WerrorS(
"Invalid L-block found in order of ring.");
291 WerrorS(
"aa ordering not supported by the MathicGB interface.");
295 WerrorS(
"Invalid unspec-block found in order of ring.");
298 WerrorS(
"Unknown block type found in order of ring.");
302 if (!didSetComponentBefore) {
303 WerrorS(
"Expected to find a c/C block in ring.");
307 if (!conf.setMonomialOrder(baseOrder, gradings)) {
308 WerrorS(
"MathicGB does not support non-global orders.");
315 const int varCount = r->N;
316 mgb::GroebnerConfiguration conf(101, varCount,0);
319 const std::vector<Exponent>& gradings = conf.monomialOrder().second;
320 if (gradings.size() % varCount != 0) {
321 WerrorS(
"Expected matrix to be a multiple of varCount.");
324 const size_t rowCount = gradings.size() / varCount;
325 std::cout <<
"Order matrix:\n";
326 for (
size_t row = 0; row < rowCount; ++row) {
327 for (
size_t col = 0; col < varCount; ++col)
328 std::cerr <<
' ' << gradings[row * varCount + col];
333 << mgb::GroebnerConfiguration::baseOrderName(conf.monomialOrder().first)
335 std::cerr <<
"Component before: " << conf.componentBefore() <<
'\n';
336 std::cerr <<
"Components ascending: " << conf.componentsAscending() <<
'\n';
337 std::cerr <<
"Schreyering: " << conf.schreyering() <<
'\n';
341 std::cout <<
"Printing order of ring.\n";
343 switch (r->order[
block]) {
441 std::cout <<
"unspec";
444 const int b0 = r->block0[
block];
445 const int b1 = r->block1[
block];
446 std::cout <<
' ' << b0 <<
':' << b1 <<
" (" << r->wvhdl[
block] <<
")" << std::flush;
447 if (r->wvhdl[
block] != 0 && b0 != 0) {
448 for (
int v = 0;
v <= b1 - b0; ++
v)
449 std::cout <<
' ' << r->wvhdl[
block][
v];
451 std::cout <<
" null";
458 WerrorS(
"There is no current ring.");
473 WerrorS(
"Syntax: mathicgb(<ideal>/<module>)");
477 WerrorS(
"Polynomial ring must be over Zp.");
483 const ideal I=(ideal) arg->
Data();
484 mgb::GroebnerConfiguration conf(characteristic, varCount,I->rank);
487 conf.setMaxThreadCount((
int)(
long)
feOptSpec[fno].value);
491 conf.setLogging(
"all");
493 mgb::GroebnerInputIdealStream toMathic(conf);
495 const ideal
id =
static_cast<const ideal
>(arg->
Data());
497 toMathic.idealBegin(
size);
498 for (
int i = 0;
i <
size; ++
i) {
499 const poly origP =
id->m[
i];
501 for (poly
p = origP;
p != 0;
p =
pNext(
p))
503 toMathic.appendPolynomialBegin(termCount);
505 for (poly
p = origP;
p != 0;
p =
pNext(
p)) {
508 toMathic.appendExponent(
i - 1,
pGetExp(
p,
i));
509 const long coefLong =
reinterpret_cast<long>(
pGetCoeff(
p));
510 toMathic.appendTermDone(
static_cast<int>(coefLong));
512 toMathic.appendPolynomialDone();
514 toMathic.idealDone();
517 mgb::computeGroebnerBasis(toMathic, fromMathic);
524 template class std::vector<Exponent>;
525 template void mgb::computeGroebnerBasis<MathicToSingStream>
530 psModulFunctions->iiAddCproc(
536 psModulFunctions->iiAddCproc(
void appendPolynomialDone()
void appendTermBegin(const mgb::GroebnerConfiguration::Component c)
VarIndex varCount() const
Coefficient modulus() const
void idealBegin(size_t polyCount)
MathicToSingStream(Coefficient modulus, VarIndex varCount)
void appendTermDone(Coefficient coefficient)
void appendExponent(VarIndex index, Exponent exponent)
void appendPolynomialBegin(size_t termCount)
const Coefficient mModulus
Class used for (list of) interpreter objects.
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
const Variable & v
< [in] a sqrfree bivariate poly
void WerrorS(const char *s)
feOptIndex feGetOptIndex(const char *name)
struct fe_option feOptSpec[]
int exponent(const CanonicalForm &f, int q)
int exponent ( const CanonicalForm & f, int q )
#define idDelete(H)
delete an ideal
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
static int index(p_Length length, p_Ord ord)
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Compatiblity layer for legacy polynomial operations (over currRing)
#define pGetComp(p)
Component.
#define pGetExp(p, i)
Exponent.
#define pInit()
allocates a new monomial and initializes everything to 0
static BOOLEAN rField_is_Zp(const ring r)
@ ringorder_a64
for int64 weights
@ ringorder_rs
opposite of ls
@ ringorder_aa
for idElimination, like a, except pFDeg, pWeigths ignore it
@ ringorder_IS
Induced (Schreyer) ordering.
ideal idInit(int idsize, int rank)
initialise an ideal / module
mgb::GroebnerConfiguration::Coefficient Coefficient
int SI_MOD_INIT() singmathic(SModulFunctions *psModulFunctions)
BOOLEAN mathicgb(leftv result, leftv arg)
BOOLEAN prOrderX(leftv result, leftv arg)
mgb::GroebnerConfiguration::Exponent Exponent
bool prOrderMatrix(ring r)
bool setOrder(ring r, mgb::GroebnerConfiguration &conf)
mgb::GroebnerConfiguration::VarIndex VarIndex
mgb::GroebnerConfiguration::BaseOrder BaseOrder