67 mTerm->coef = reinterpret_cast<number>(coefficient);
108 bool setOrder(ring r, mgb::GroebnerConfiguration& conf)
110 const VarIndex varCount = conf.varCount();
112 bool didSetComponentBefore =
false;
114 mgb::GroebnerConfiguration::RevLexDescendingBaseOrder;
116 std::vector<Exponent> gradings;
122 if (r->block0[
block] < 0 || r->block1[
block] < 0)
124 WerrorS(
"Unexpected negative block0/block1 in ring.");
127 const VarIndex block0 = static_cast<VarIndex>(r->block0[
block]);
128 const VarIndex block1 = static_cast<VarIndex>(r->block1[
block]);
129 const int*
const weights = r->wvhdl[
block];
132 WerrorS(
"Unexpected block0 > block1 in ring.");
139 if (block0 != 0 || block1 != 0 || weights != 0)
141 WerrorS(
"Unexpected non-zero fields on c/C block in ring.");
144 if (didSetComponentBefore)
146 WerrorS(
"Unexpected two c/C blocks in ring.");
149 didSetComponentBefore =
true;
152 conf.setComponentBefore
153 (mgb::GroebnerConfiguration::ComponentAfterBaseOrder);
155 conf.setComponentBefore(gradings.size() / varCount);
159 if (block0 == 0 || block1 == 0)
161 WerrorS(
"Expected block0 != 0 and block1 != 0 in ring.");
164 if (block1 > varCount)
167 WerrorS(
"Expected block1 <= #vars in ring.");
172 const size_t dim = static_cast<size_t>(block1 - block0 + 1);
192 WerrorS(
"Block type a64 not supported for MathicGB interface.");
199 const bool wGrading =
202 if (oneGrading || minusOneGrading || wGrading || minusWGrading)
204 const VarIndex begin = gradings.size();
205 gradings.resize(begin + varCount);
206 if (oneGrading || minusOneGrading)
210 WerrorS(
"Expect wvhdl == 0 in Dp/dp/Ds/ds-block in ring.");
213 const Exponent value = oneGrading ? 1 : -1;
214 for (
int var = block0 - 1; var < block1; ++var)
215 gradings[begin + var] = value;
221 WerrorS(
"Expect wvhdl != 0 in a/Wp/wp/ws/Ws-block in ring.");
226 for (
int var = 0; var <
dim; ++var)
227 gradings[begin + (block0 - 1) + var] = weights[var];
231 for (
int var = 0; var <
dim; ++var)
232 gradings[begin + (block0 - 1) + var] = -weights[var];
240 const bool lexFromLeft =
248 const bool revlexFromRight =
254 if (lexFromLeft || lexFromRight || revlexFromLeft || revlexFromRight)
263 baseOrder = mgb::GroebnerConfiguration::LexAscendingBaseOrder;
264 else if (revlexFromRight)
265 baseOrder = mgb::GroebnerConfiguration::RevLexDescendingBaseOrder;
266 else if (lexFromLeft)
267 baseOrder = mgb::GroebnerConfiguration::LexDescendingBaseOrder;
269 baseOrder = mgb::GroebnerConfiguration::RevLexAscendingBaseOrder;
273 const size_t begin = gradings.size();
274 gradings.resize(begin +
dim * varCount);
275 const Exponent value = (lexFromLeft || lexFromRight) ? 1 : -1;
276 if (lexFromLeft || revlexFromLeft)
278 for (
size_t row = 0; row <
dim; ++row)
279 gradings[begin + row * varCount + (block0 - 1) + row] = value;
283 for (
size_t row = 0; row <
dim; ++row)
284 gradings[begin + row * varCount + (block1 - 1) - row] = value;
294 WerrorS(
"Expected wvhdl != 0 in M-block in ring.");
297 const size_t begin = gradings.size();
298 gradings.resize(begin +
dim * varCount);
299 for (
size_t row = 0; row <
dim; ++row)
300 for (
size_t col = block0 - 1; col < block1; ++col)
301 gradings[begin + row * varCount + col] = weights[row *
dim + col];
313 WerrorS(
"Schreyer order s/S/IS not supported in MathicGB interface.");
320 WerrorS(
"Block type am not supported in MathicGB interface");
325 WerrorS(
"Invalid L-block found in order of ring.");
331 WerrorS(
"aa ordering not supported by the MathicGB interface.");
336 WerrorS(
"Invalid unspec-block found in order of ring.");
339 WerrorS(
"Unknown block type found in order of ring.");
343 if (!didSetComponentBefore)
345 WerrorS(
"Expected to find a c/C block in ring.");
349 if (!conf.setMonomialOrder(baseOrder, gradings))
351 WerrorS(
"MathicGB does not support non-global orders.");
359 const int varCount = r->N;
360 mgb::GroebnerConfiguration conf(101, varCount,0);
363 const std::vector<Exponent>& gradings = conf.monomialOrder().second;
364 if (gradings.size() % varCount != 0)
366 WerrorS(
"Expected matrix to be a multiple of varCount.");
369 const size_t rowCount = gradings.size() / varCount;
370 std::cout <<
"Order matrix:\n";
371 for (
size_t row = 0; row < rowCount; ++row)
373 for (
size_t col = 0; col < varCount; ++col)
374 std::cerr <<
' ' << gradings[row * varCount + col];
379 << mgb::GroebnerConfiguration::baseOrderName(conf.monomialOrder().first)
381 std::cerr <<
"Component before: " << conf.componentBefore() <<
'\n';
382 std::cerr <<
"Components ascending: " << conf.componentsAscending() <<
'\n';
383 std::cerr <<
"Schreyering: " << conf.schreyering() <<
'\n';
389 std::cout <<
"Printing order of ring.\n";
392 switch (r->order[
block])
491 std::cout <<
"unspec";
494 const int b0 = r->block0[
block];
495 const int b1 = r->block1[
block];
496 std::cout <<
' ' << b0 <<
':' << b1 <<
" (" << r->wvhdl[
block] <<
")" << std::flush;
497 if (r->wvhdl[
block] != 0 && b0 != 0)
499 for (
int v = 0;
v <= b1 - b0; ++
v)
500 std::cout <<
' ' << r->wvhdl[
block][
v];
502 std::cout <<
" null";
511 WerrorS(
"There is no current ring.");
527 WerrorS(
"Syntax: mathicgb(<ideal>/<module>)");
532 WerrorS(
"Polynomial ring must be over Zp.");
538 const ideal I=(ideal) arg->
Data();
539 mgb::GroebnerConfiguration conf(characteristic, varCount,I->rank);
542 conf.setMaxThreadCount((
int)(
long)
feOptSpec[fno].value);
546 conf.setLogging(
"all");
548 mgb::GroebnerInputIdealStream toMathic(conf);
550 const ideal
id = static_cast<const ideal>(arg->
Data());
552 toMathic.idealBegin(
size);
555 const poly origP =
id->m[
i];
557 for (poly
p = origP;
p != 0;
p =
pNext(
p))
559 toMathic.appendPolynomialBegin(termCount);
561 for (poly
p = origP;
p != 0;
p =
pNext(
p))
565 toMathic.appendExponent(
i - 1,
pGetExp(
p,
i));
566 const long coefLong = reinterpret_cast<long>(
pGetCoeff(
p));
567 toMathic.appendTermDone(static_cast<int>(coefLong));
569 toMathic.appendPolynomialDone();
571 toMathic.idealDone();
574 mgb::computeGroebnerBasis(toMathic, fromMathic);
581 template class std::vector<Exponent>;
582 template void mgb::computeGroebnerBasis<MathicToSingStream>
587 psModulFunctions->iiAddCproc(
593 psModulFunctions->iiAddCproc(