61 mTerm->coef =
reinterpret_cast<number
>(coefficient);
98 bool setOrder(ring
r, mgb::GroebnerConfiguration& conf) {
101 bool didSetComponentBefore =
false;
103 mgb::GroebnerConfiguration::RevLexDescendingBaseOrder;
105 std::vector<Exponent> gradings;
110 if (r->block0[
block] < 0 || r->block1[
block] < 0) {
111 WerrorS(
"Unexpected negative block0/block1 in ring.");
116 const int*
const weights = r->wvhdl[
block];
117 if (block0 > block1) {
118 WerrorS(
"Unexpected block0 > block1 in ring.");
124 if (block0 != 0 || block1 != 0 || weights != 0) {
125 WerrorS(
"Unexpected non-zero fields on c/C block in ring.");
128 if (didSetComponentBefore) {
129 WerrorS(
"Unexpected two c/C blocks in ring.");
132 didSetComponentBefore =
true;
134 conf.setComponentBefore
135 (mgb::GroebnerConfiguration::ComponentAfterBaseOrder);
137 conf.setComponentBefore(gradings.size() /
varCount);
141 if (block0 == 0 || block1 == 0) {
142 WerrorS(
"Expected block0 != 0 and block1 != 0 in ring.");
145 if (block1 > varCount) {
147 WerrorS(
"Expected block1 <= #vars in ring.");
152 const size_t dim =
static_cast<size_t>(block1 - block0 + 1);
171 WerrorS(
"Block type a64 not supported for MathicGB interface.");
178 const bool wGrading =
181 if (oneGrading || minusOneGrading || wGrading || minusWGrading) {
182 const VarIndex begin = gradings.size();
183 gradings.resize(begin + varCount);
184 if (oneGrading || minusOneGrading) {
186 WerrorS(
"Expect wvhdl == 0 in Dp/dp/Ds/ds-block in ring.");
189 const Exponent value = oneGrading ? 1 : -1;
190 for (
int var = block0 - 1; var < block1; ++var)
191 gradings[begin + var] = value;
194 WerrorS(
"Expect wvhdl != 0 in a/Wp/wp/ws/Ws-block in ring.");
198 for (
int var = 0; var <
dim; ++var)
199 gradings[begin + (block0 - 1) + var] = weights[var];
201 for (
int var = 0; var <
dim; ++var)
202 gradings[begin + (block0 - 1) + var] = -weights[var];
210 const bool lexFromLeft =
218 const bool revlexFromRight =
224 if (lexFromLeft || lexFromRight || revlexFromLeft || revlexFromRight) {
231 baseOrder = mgb::GroebnerConfiguration::LexAscendingBaseOrder;
232 else if (revlexFromRight)
233 baseOrder = mgb::GroebnerConfiguration::RevLexDescendingBaseOrder;
234 else if (lexFromLeft)
235 baseOrder = mgb::GroebnerConfiguration::LexDescendingBaseOrder;
237 baseOrder = mgb::GroebnerConfiguration::RevLexAscendingBaseOrder;
241 const size_t begin = gradings.size();
242 gradings.resize(begin + dim * varCount);
243 const Exponent value = (lexFromLeft || lexFromRight) ? 1 : -1;
244 if (lexFromLeft || revlexFromLeft) {
245 for (
size_t row = 0; row <
dim; ++row)
246 gradings[begin + row * varCount + (block0 - 1) + row] = value;
248 for (
size_t row = 0; row <
dim; ++row)
249 gradings[begin + row * varCount + (block1 - 1) - row] = value;
257 WerrorS(
"Expected wvhdl != 0 in M-block in ring.");
260 const size_t begin = gradings.size();
261 gradings.resize(begin + dim * varCount);
262 for (
size_t row = 0; row <
dim; ++row)
263 for (
size_t col = block0 - 1; col < block1; ++col)
264 gradings[begin + row * varCount + col] = weights[row * dim + col];
275 WerrorS(
"Schreyer order s/S/IS not supported in MathicGB interface.");
281 WerrorS(
"Block type am not supported in MathicGB interface");
285 WerrorS(
"Invalid L-block found in order of ring.");
290 WerrorS(
"aa ordering not supported by the MathicGB interface.");
294 WerrorS(
"Invalid unspec-block found in order of ring.");
297 WerrorS(
"Unknown block type found in order of ring.");
301 if (!didSetComponentBefore) {
302 WerrorS(
"Expected to find a c/C block in ring.");
306 if (!conf.setMonomialOrder(baseOrder, gradings)) {
307 WerrorS(
"MathicGB does not support non-global orders.");
315 mgb::GroebnerConfiguration conf(101, varCount,0);
318 const std::vector<Exponent>& gradings = conf.monomialOrder().second;
319 if (gradings.size() % varCount != 0) {
320 WerrorS(
"Expected matrix to be a multiple of varCount.");
323 const size_t rowCount = gradings.size() /
varCount;
324 std::cout <<
"Order matrix:\n";
325 for (
size_t row = 0; row < rowCount; ++row) {
326 for (
size_t col = 0; col <
varCount; ++col)
327 std::cerr <<
' ' << gradings[row * varCount + col];
332 << mgb::GroebnerConfiguration::baseOrderName(conf.monomialOrder().first)
334 std::cerr <<
"Component before: " << conf.componentBefore() <<
'\n';
335 std::cerr <<
"Components ascending: " << conf.componentsAscending() <<
'\n';
336 std::cerr <<
"Schreyering: " << conf.schreyering() <<
'\n';
340 std::cout <<
"Printing order of ring.\n";
342 switch (r->order[
block]) {
440 std::cout <<
"unspec";
443 const int b0 = r->block0[
block];
444 const int b1 = r->block1[
block];
445 std::cout <<
' ' << b0 <<
':' << b1 <<
" (" << r->wvhdl[
block] <<
")" << std::flush;
446 if (r->wvhdl[
block] != 0 && b0 != 0) {
447 for (
int v = 0;
v <= b1 - b0; ++
v)
448 std::cout <<
' ' << r->wvhdl[
block][
v];
450 std::cout <<
" null";
457 WerrorS(
"There is no current ring.");
472 WerrorS(
"Syntax: mathicgb(<ideal>/<module>)");
476 WerrorS(
"Polynomial ring must be over Zp.");
482 const ideal I=(ideal) arg->
Data();
483 mgb::GroebnerConfiguration conf(characteristic, varCount,I->rank);
484 conf.setMaxThreadCount(0);
488 conf.setLogging(
"all");
490 mgb::GroebnerInputIdealStream toMathic(conf);
492 const ideal
id =
static_cast<const ideal
>(arg->
Data());
494 toMathic.idealBegin(size);
495 for (
int i = 0;
i <
size; ++
i) {
496 const poly origP =
id->m[
i];
500 toMathic.appendPolynomialBegin(termCount);
505 toMathic.appendExponent(
i - 1,
pGetExp(
p,
i));
506 const long coefLong =
reinterpret_cast<long>(
pGetCoeff(
p));
507 toMathic.appendTermDone(static_cast<int>(coefLong));
509 toMathic.appendPolynomialDone();
511 toMathic.idealDone();
514 mgb::computeGroebnerBasis(toMathic, fromMathic);
521 template class std::vector<Exponent>;
522 template void mgb::computeGroebnerBasis<MathicToSingStream>
527 psModulFunctions->iiAddCproc(
533 psModulFunctions->iiAddCproc(
for idElimination, like a, except pFDeg, pWeigths ignore it
Class used for (list of) interpreter objects.
BOOLEAN prOrderX(leftv result, leftv arg)
#define idDelete(H)
delete an ideal
bool setOrder(ring r, mgb::GroebnerConfiguration &conf)
int SI_MOD_INIT() singmathic(SModulFunctions *psModulFunctions)
mgb::GroebnerConfiguration::VarIndex VarIndex
Compatiblity layer for legacy polynomial operations (over currRing)
MathicToSingStream(Coefficient modulus, VarIndex varCount)
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
void appendTermBegin(const mgb::GroebnerConfiguration::Component c)
void WerrorS(const char *s)
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
void idealBegin(size_t polyCount)
#define pGetComp(p)
Component.
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
#define pGetExp(p, i)
Exponent.
void appendExponent(VarIndex index, Exponent exponent)
mgb::GroebnerConfiguration::Exponent Exponent
Induced (Schreyer) ordering.
void appendPolynomialBegin(size_t termCount)
BOOLEAN mathicgb(leftv result, leftv arg)
static int index(p_Length length, p_Ord ord)
bool prOrderMatrix(ring r)
static BOOLEAN rField_is_Zp(const ring r)
ideal idInit(int idsize, int rank)
initialise an ideal / module
const Variable & v
< [in] a sqrfree bivariate poly
void appendTermDone(Coefficient coefficient)
const Coefficient mModulus
Coefficient modulus() const
#define pInit()
allocates a new monomial and initializes everything to 0
VarIndex varCount() const
mgb::GroebnerConfiguration::BaseOrder BaseOrder
int exponent(const CanonicalForm &f, int q)
int exponent ( const CanonicalForm & f, int q )
mgb::GroebnerConfiguration::Coefficient Coefficient
void appendPolynomialDone()