60 mTerm->coef =
reinterpret_cast<number
>(coefficient);
97 bool setOrder(ring
r, mgb::GroebnerConfiguration& conf) {
98 const VarIndex varCount = conf.varCount();
100 bool didSetComponentBefore =
false;
102 mgb::GroebnerConfiguration::RevLexDescendingBaseOrder;
104 std::vector<Exponent> gradings;
109 if (r->block0[
block] < 0 || r->block1[
block] < 0) {
110 WerrorS(
"Unexpected negative block0/block1 in ring.");
115 const int*
const weights = r->wvhdl[
block];
116 if (block0 > block1) {
117 WerrorS(
"Unexpected block0 > block1 in ring.");
123 if (block0 != 0 || block1 != 0 || weights != 0) {
124 WerrorS(
"Unexpected non-zero fields on c/C block in ring.");
127 if (didSetComponentBefore) {
128 WerrorS(
"Unexpected two c/C blocks in ring.");
131 didSetComponentBefore =
true;
133 conf.setComponentBefore
134 (mgb::GroebnerConfiguration::ComponentAfterBaseOrder);
136 conf.setComponentBefore(gradings.size() / varCount);
140 if (block0 == 0 || block1 == 0) {
141 WerrorS(
"Expected block0 != 0 and block1 != 0 in ring.");
144 if (block1 > varCount) {
146 WerrorS(
"Expected block1 <= #vars in ring.");
151 const size_t dim =
static_cast<size_t>(block1 - block0 + 1);
170 WerrorS(
"Block type a64 not supported for MathicGB interface.");
177 const bool wGrading =
180 if (oneGrading || minusOneGrading || wGrading || minusWGrading) {
181 const VarIndex begin = gradings.size();
182 gradings.resize(begin + varCount);
183 if (oneGrading || minusOneGrading) {
185 WerrorS(
"Expect wvhdl == 0 in Dp/dp/Ds/ds-block in ring.");
188 const Exponent value = oneGrading ? 1 : -1;
189 for (
int var = block0 - 1; var < block1; ++var)
190 gradings[begin + var] = value;
193 WerrorS(
"Expect wvhdl != 0 in a/Wp/wp/ws/Ws-block in ring.");
197 for (
int var = 0; var <
dim; ++var)
198 gradings[begin + (block0 - 1) + var] = weights[var];
200 for (
int var = 0; var <
dim; ++var)
201 gradings[begin + (block0 - 1) + var] = -weights[var];
209 const bool lexFromLeft =
217 const bool revlexFromRight =
223 if (lexFromLeft || lexFromRight || revlexFromLeft || revlexFromRight) {
230 baseOrder = mgb::GroebnerConfiguration::LexAscendingBaseOrder;
231 else if (revlexFromRight)
232 baseOrder = mgb::GroebnerConfiguration::RevLexDescendingBaseOrder;
233 else if (lexFromLeft)
234 baseOrder = mgb::GroebnerConfiguration::LexDescendingBaseOrder;
236 baseOrder = mgb::GroebnerConfiguration::RevLexAscendingBaseOrder;
240 const size_t begin = gradings.size();
241 gradings.resize(begin + dim * varCount);
242 const Exponent value = (lexFromLeft || lexFromRight) ? 1 : -1;
243 if (lexFromLeft || revlexFromLeft) {
244 for (
size_t row = 0; row <
dim; ++row)
245 gradings[begin + row * varCount + (block0 - 1) + row] = value;
247 for (
size_t row = 0; row <
dim; ++row)
248 gradings[begin + row * varCount + (block1 - 1) - row] = value;
256 WerrorS(
"Expected wvhdl != 0 in M-block in ring.");
259 const size_t begin = gradings.size();
260 gradings.resize(begin + dim * varCount);
261 for (
size_t row = 0; row <
dim; ++row)
262 for (
size_t col = block0 - 1; col < block1; ++col)
263 gradings[begin + row * varCount + col] = weights[row * dim + col];
274 WerrorS(
"Schreyer order s/S/IS not supported in MathicGB interface.");
280 WerrorS(
"Block type am not supported in MathicGB interface");
284 WerrorS(
"Invalid L-block found in order of ring.");
289 WerrorS(
"aa ordering not supported by the MathicGB interface.");
293 WerrorS(
"Invalid unspec-block found in order of ring.");
296 WerrorS(
"Unknown block type found in order of ring.");
300 if (!didSetComponentBefore) {
301 WerrorS(
"Expected to find a c/C block in ring.");
305 if (!conf.setMonomialOrder(baseOrder, gradings)) {
306 WerrorS(
"MathicGB does not support non-global orders.");
313 const int varCount = r->N;
314 mgb::GroebnerConfiguration conf(101, varCount);
317 const std::vector<Exponent>& gradings = conf.monomialOrder().second;
318 if (gradings.size() % varCount != 0) {
319 WerrorS(
"Expected matrix to be a multiple of varCount.");
322 const size_t rowCount = gradings.size() / varCount;
323 std::cout <<
"Order matrix:\n";
324 for (
size_t row = 0; row < rowCount; ++row) {
325 for (
size_t col = 0; col < varCount; ++col)
326 std::cerr <<
' ' << gradings[row * varCount + col];
331 << mgb::GroebnerConfiguration::baseOrderName(conf.monomialOrder().first)
333 std::cerr <<
"Component before: " << conf.componentBefore() <<
'\n';
334 std::cerr <<
"Components ascending: " << conf.componentsAscending() <<
'\n';
335 std::cerr <<
"Schreyering: " << conf.schreyering() <<
'\n';
339 std::cout <<
"Printing order of ring.\n";
341 switch (r->order[
block]) {
439 std::cout <<
"unspec";
442 const int b0 = r->block0[
block];
443 const int b1 = r->block1[
block];
444 std::cout <<
' ' << b0 <<
':' << b1 <<
" (" << r->wvhdl[
block] <<
")" << std::flush;
445 if (r->wvhdl[
block] != 0 && b0 != 0) {
446 for (
int v = 0;
v <= b1 - b0; ++
v)
447 std::cout <<
' ' << r->wvhdl[
block][
v];
449 std::cout <<
" null";
456 WerrorS(
"There is no current ring.");
476 WerrorS(
"Syntax: mathicgb(<ideal>)");
480 WerrorS(
"Polynomial ring must be over Zp.");
486 mgb::GroebnerConfiguration conf(characteristic, varCount);
490 conf.setLogging(
"all");
492 mgb::GroebnerInputIdealStream toMathic(conf);
496 toMathic.idealBegin(size);
497 for (
int i = 0;
i <
size; ++
i) {
498 const poly origP =
id->m[
i];
502 toMathic.appendPolynomialBegin(termCount);
505 toMathic.appendTermBegin();
507 toMathic.appendExponent(
i - 1,
pGetExp(
p,
i));
508 const long coefLong =
reinterpret_cast<long>(
pGetCoeff(
p));
509 toMathic.appendTermDone(static_cast<int>(coefLong));
511 toMathic.appendPolynomialDone();
513 toMathic.idealDone();
516 mgb::computeGroebnerBasis(toMathic, fromMathic);
523 template class std::vector<Exponent>;
524 template void mgb::computeGroebnerBasis<MathicToSingStream>
529 PrintS(
"Initializing Singular-Mathic interface Singmathic.\n");
530 psModulFunctions->iiAddCproc(
536 psModulFunctions->iiAddCproc(
542 psModulFunctions->iiAddCproc(
544 "mathicgb_setRingGlobal",
for idElimination, like a, except pFDeg, pWeigths ignore it
Class used for (list of) interpreter objects.
BOOLEAN prOrderX(leftv result, leftv arg)
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)
BOOLEAN setRingGlobal(leftv result, leftv arg)
MathicToSingStream(Coefficient modulus, VarIndex varCount)
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
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)
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
void idDelete(ideal *h, ring r=currRing)
delete an ideal
Induced (Schreyer) ordering.
void PrintS(const char *s)
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)
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()