Loading...
Searching...
No Matches
singmathic.cc File Reference
`#include "kernel/mod2.h"`
`#include "misc/options.h"`
`#include "kernel/ideals.h"`
`#include "kernel/polys.h"`
`#include "Singular/ipid.h"`
`#include "Singular/feOpt.h"`
`#include "Singular/mod_lib.h"`
`#include <mathicgb.h>`
`#include <iostream>`

Go to the source code of this file.

## Data Structures

class | MathicToSingStream

## Typedefs

typedef mgb::GroebnerConfiguration::Coefficient | Coefficient
typedef mgb::GroebnerConfiguration::VarIndex | VarIndex
typedef mgb::GroebnerConfiguration::Exponent | Exponent
typedef mgb::GroebnerConfiguration::BaseOrder | BaseOrder

## Functions

bool | setOrder (ring r, mgb::GroebnerConfiguration &conf)
bool | prOrderMatrix (ring r)
void | prOrder (ring r)
BOOLEAN | prOrderX (leftv result, leftv arg)
BOOLEAN | mathicgb (leftv result, leftv arg)
int SI_MOD_INIT | singmathic (SModulFunctions *psModulFunctions)

## Typedef Documentation

## BaseOrder

typedef mgb::GroebnerConfiguration::BaseOrder BaseOrder

Definition at line 21 of file singmathic.cc.

## Coefficient

typedef mgb::GroebnerConfiguration::Coefficient Coefficient

Definition at line 18 of file singmathic.cc.

## Exponent

typedef mgb::GroebnerConfiguration::Exponent Exponent

Definition at line 20 of file singmathic.cc.

## VarIndex

typedef mgb::GroebnerConfiguration::VarIndex VarIndex

Definition at line 19 of file singmathic.cc.

## Function Documentation

## mathicgb()

BOOLEAN mathicgb | ( | leftv | result,
|  | leftv | arg )

Definition at line 520 of file singmathic.cc.

{
result->rtyp=NONE;
if (arg == NULL || arg->next != NULL ||
((arg->Typ() != IDEAL_CMD) &&(arg->Typ() != MODUL_CMD)))
{
WerrorS("Syntax: mathicgb(<ideal>/<module>)");
return TRUE;
}
if (!rField_is_Zp(currRing))
{
WerrorS("Polynomial ring must be over Zp.");
return TRUE;
}
const int characteristic = n_GetChar(currRing->cf);
const int varCount = currRing->N;
const ideal I=(ideal) arg->Data();
mgb::GroebnerConfiguration conf(characteristic, varCount,I->rank);
feOptIndex fno=feGetOptIndex(FE_OPT_THREADS);
//conf.setMaxThreadCount(0); // default number of cores
conf.setMaxThreadCount((int)(long)feOptSpec[fno].value);
if (!setOrder(currRing, conf))
return TRUE;
if (TEST_OPT_PROT)
conf.setLogging("all");
mgb::GroebnerInputIdealStream toMathic(conf);
const ideal id = static_cast<const ideal>(arg->Data());
const int size = IDELEMS(id);
toMathic.idealBegin(size);
for (int i = 0; i < size; ++i)
{
const poly origP = id->m[i];
int termCount = 0;
for (poly p = origP; p != 0; p = pNext(p))
++termCount;
toMathic.appendPolynomialBegin(termCount);
for (poly p = origP; p != 0; p = pNext(p))
{
toMathic.appendTermBegin(pGetComp(p));
for (int i = 1; i <= currRing->N; ++i)
toMathic.appendExponent(i - 1, pGetExp(p, i));
const long coefLong = reinterpret_cast<long>(pGetCoeff(p));
toMathic.appendTermDone(static_cast<int>(coefLong));
}
toMathic.appendPolynomialDone();
}
toMathic.idealDone();
MathicToSingStream fromMathic(characteristic, varCount);
mgb::computeGroebnerBasis(toMathic, fromMathic);
result->rtyp = arg->Typ();
result->data = fromMathic.takeIdeal();
return FALSE;
}
TRUE
#define TRUE
Definition auxiliary.h:101
FALSE
#define FALSE
Definition auxiliary.h:97
size
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition cf_ops.cc:600
i
int i
Definition cfEzgcd.cc:132
p
int p
Definition cfModGcd.cc:4086
MathicToSingStream
Definition singmathic.cc:25
sleftv::Typ
int Typ()
Definition subexpr.cc:1048
sleftv::Data
void * Data()
Definition subexpr.cc:1192
sleftv::next
leftv next
Definition subexpr.h:86
n_GetChar
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition coeffs.h:450
result
return result
Definition facAbsBiFact.cc:76
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
feOptIndex
feOptIndex
Definition feOptGen.h:15
feGetOptIndex
feOptIndex feGetOptIndex(const char *name)
Definition feOpt.cc:104
feOptSpec
EXTERN_VAR struct fe_option feOptSpec[]
Definition feOpt.h:17
IDEAL_CMD
@ IDEAL_CMD
Definition grammar.cc:285
MODUL_CMD
@ MODUL_CMD
Definition grammar.cc:288
pNext
#define pNext(p)
Definition monomials.h:36
pGetCoeff
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition monomials.h:44
NULL
#define NULL
Definition omList.c:12
TEST_OPT_PROT
#define TEST_OPT_PROT
Definition options.h:105
currRing
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
pGetComp
#define pGetComp(p)
Component.
Definition polys.h:38
pGetExp
#define pGetExp(p, i)
Exponent.
Definition polys.h:42
rField_is_Zp
static BOOLEAN rField_is_Zp(const ring r)
Definition ring.h:506
IDELEMS
#define IDELEMS(i)
Definition simpleideals.h:23
setOrder
bool setOrder(ring r, mgb::GroebnerConfiguration &conf)
Definition singmathic.cc:108
NONE
#define NONE
Definition tok.h:223

## prOrder()

void prOrder | ( | ring | r | ) |

< for int64 weights

< S?

< s?

< for idElimination, like a, except pFDeg, pWeigths ignore it

< opposite of ls

< Induced (Schreyer) ordering

Definition at line 387 of file singmathic.cc.

{
std::cout << "Printing order of ring.\n";
for (int block = 0; ; ++block)
{
switch (r->order[block])
{
case ringorder_no: // end of blocks
return;
case ringorder_a:
std::cout << "a";
break;
case ringorder_a64: ///< for int64 weights
std::cout << "a64";
break;
case ringorder_c:
std::cout << "c";
break;
case ringorder_C:
std::cout << "C";
break;
case ringorder_M:
std::cout << "M";
break;
case ringorder_S: ///< S?
std::cout << "S";
break;
case ringorder_s: ///< s?
std::cout << "s";
break;
case ringorder_lp:
std::cout << "lp";
break;
case ringorder_dp:
std::cout << "dp";
break;
case ringorder_rp:
std::cout << "rp";
break;
case ringorder_Dp:
std::cout << "Dp";
break;
case ringorder_wp:
std::cout << "wp";
break;
case ringorder_Wp:
std::cout << "Wp";
break;
case ringorder_ls:
std::cout << "ls"; // not global
break;
case ringorder_ds:
std::cout << "ds"; // not global
break;
case ringorder_Ds:
std::cout << "Ds"; // not global
break;
case ringorder_ws:
std::cout << "ws"; // not global
break;
case ringorder_Ws:
std::cout << "Ws"; // not global
break;
case ringorder_am:
std::cout << "am";
break;
case ringorder_L:
std::cout << "L";
break;
// the following are only used internally
case ringorder_aa: ///< for idElimination, like a, except pFDeg, pWeigths ignore it
std::cout << "aa";
break;
case ringorder_rs: ///< opposite of ls
std::cout << "rs";
break;
case ringorder_IS: ///< Induced (Schreyer) ordering
std::cout << "IS";
break;
case ringorder_unspec:
std::cout << "unspec";
break;
}
const int b0 = r->block0[block];
const int b1 = r->block1[block];
std::cout << ' ' << b0 << ':' << b1 << " (" << r->wvhdl[block] << ")" << std::flush;
if (r->wvhdl[block] != 0 && b0 != 0)
{
for (int v = 0; v <= b1 - b0; ++v)
std::cout << ' ' << r->wvhdl[block][v];
} else
std::cout << " null";
std::cout << '\n';
}
}
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
ringorder_rp
#define ringorder_rp
Definition ring.h:100
ringorder_lp
@ ringorder_lp
Definition ring.h:78
ringorder_a
@ ringorder_a
Definition ring.h:71
ringorder_am
@ ringorder_am
Definition ring.h:90
ringorder_a64
@ ringorder_a64
for int64 weights
Definition ring.h:72
ringorder_C
@ ringorder_C
Definition ring.h:74
ringorder_S
@ ringorder_S
S?
Definition ring.h:76
ringorder_ds
@ ringorder_ds
Definition ring.h:86
ringorder_Dp
@ ringorder_Dp
Definition ring.h:81
ringorder_unspec
@ ringorder_unspec
Definition ring.h:96
ringorder_L
@ ringorder_L
Definition ring.h:91
ringorder_Ds
@ ringorder_Ds
Definition ring.h:87
ringorder_dp
@ ringorder_dp
Definition ring.h:79
ringorder_c
@ ringorder_c
Definition ring.h:73
ringorder_aa
@ ringorder_aa
for idElimination, like a, except pFDeg, pWeigths ignore it
Definition ring.h:93
ringorder_no
@ ringorder_no
Definition ring.h:70
ringorder_Wp
@ ringorder_Wp
Definition ring.h:83
ringorder_ws
@ ringorder_ws
Definition ring.h:88
ringorder_Ws
@ ringorder_Ws
Definition ring.h:89
ringorder_IS
@ ringorder_IS
Induced (Schreyer) ordering.
Definition ring.h:95
ringorder_ls
@ ringorder_ls
degree, ip
Definition ring.h:85
ringorder_s
@ ringorder_s
s?
Definition ring.h:77
ringorder_wp
@ ringorder_wp
Definition ring.h:82
ringorder_M
@ ringorder_M
Definition ring.h:75
ringorder_rs
#define ringorder_rs
Definition ring.h:101
block
#define block
Definition scanner.cc:646

## prOrderMatrix()

bool prOrderMatrix | ( | ring | r | ) |

Definition at line 357 of file singmathic.cc.

{
const int varCount = r->N;
mgb::GroebnerConfiguration conf(101, varCount,0);
if (!setOrder(r, conf))
return false;
const std::vector<Exponent>& gradings = conf.monomialOrder().second;
if (gradings.size() % varCount != 0)
{
WerrorS("Expected matrix to be a multiple of varCount.");
return false;
}
const size_t rowCount = gradings.size() / varCount;
std::cout << "Order matrix:\n";
for (size_t row = 0; row < rowCount; ++row)
{
for (size_t col = 0; col < varCount; ++col)
std::cerr << ' ' << gradings[row * varCount + col];
std::cerr << '\n';
}
std::cerr
<< "Base order: "
<< mgb::GroebnerConfiguration::baseOrderName(conf.monomialOrder().first)
<< '\n';
std::cerr << "Component before: " << conf.componentBefore() << '\n';
std::cerr << "Components ascending: " << conf.componentsAscending() << '\n';
std::cerr << "Schreyering: " << conf.schreyering() << '\n';
return true;
}

## prOrderX()

BOOLEAN prOrderX | ( | leftv | result,
|  | leftv | arg )

Definition at line 507 of file singmathic.cc.

{
if (currRing == 0)
{
WerrorS("There is no current ring.");
return TRUE;
}
prOrder(currRing);
prOrderMatrix(currRing);
result->rtyp=NONE;
return FALSE;
}
prOrderMatrix
bool prOrderMatrix(ring r)
Definition singmathic.cc:357
prOrder
void prOrder(ring r)
Definition singmathic.cc:387

## setOrder()

bool setOrder | ( | ring | r,
|  | mgb::GroebnerConfiguration & | conf )

Definition at line 108 of file singmathic.cc.

{
const VarIndex varCount = conf.varCount();
bool didSetComponentBefore = false;
mgb::GroebnerConfiguration::BaseOrder baseOrder =
mgb::GroebnerConfiguration::RevLexDescendingBaseOrder;
std::vector<Exponent> gradings;
for (int block = 0; r->order[block] != ringorder_no; ++block)
{
// *** ringorder_no
const rRingOrder_t type = static_cast<rRingOrder_t>(r->order[block]);
if (r->block0[block] < 0 || r->block1[block] < 0)
{
WerrorS("Unexpected negative block0/block1 in ring.");
return false;
}
const VarIndex block0 = static_cast<VarIndex>(r->block0[block]);
const VarIndex block1 = static_cast<VarIndex>(r->block1[block]);
const int* const weights = r->wvhdl[block];
if (block0 > block1)
{
WerrorS("Unexpected block0 > block1 in ring.");
return false;
}
// *** ringorder_c and ringorder_C
if (type == ringorder_c || type == ringorder_C)
{
if (block0 != 0 || block1 != 0 || weights != 0)
{
WerrorS("Unexpected non-zero fields on c/C block in ring.");
return false;
}
if (didSetComponentBefore)
{
WerrorS("Unexpected two c/C blocks in ring.");
return false;
}
didSetComponentBefore = true;
if (r->order[block + 1] == ringorder_no)
{
conf.setComponentBefore
(mgb::GroebnerConfiguration::ComponentAfterBaseOrder);
} else
conf.setComponentBefore(gradings.size() / varCount);
conf.setComponentsAscending(type == ringorder_C);
continue;
}
if (block0 == 0 || block1 == 0)
{
WerrorS("Expected block0 != 0 and block1 != 0 in ring.");
return false;
}
if (block1 > varCount)
{
// todo: first handle any block types where this is not true
WerrorS("Expected block1 <= #vars in ring.");
return false;
}
// dim is how many variables this block concerns.
const size_t dim = static_cast<size_t>(block1 - block0 + 1);
// *** single-graded/ungraded lex/revlex orders
// a(w): w-graded and that's it
// a64(w): w-graded with 64-bit weights (not supported here)
// lp: lex from left (descending)
// Dp: 1-graded, lex from left (descending)
// Ds: -1-graded, lex from left (descending)
// Wp(w): w-graded, lex from left (descending)
// Ws(w): -w-graded, lex from left (descending)
// rp: lex from right (ascending)
// rs: revlex from right (descending)
// dp: 1-graded, revlex from right (descending)
// ds: -1-graded, revlex from right (descending)
// wp(w): w-graded, revlex from right (descending)
// ws(w): -w-graded, revlex from right (descending)
// ls: revlex from left (ascending)
if (type == ringorder_a64)
{
WerrorS("Block type a64 not supported for MathicGB interface.");
return false;
}
// * handle the single-grading part
const bool oneGrading = (type == ringorder_Dp || type == ringorder_dp);
const bool minusOneGrading = (type == ringorder_Ds || type == ringorder_ds);
const bool wGrading =
(type == ringorder_a || type == ringorder_Wp || type == ringorder_wp);
const bool minusWGrading = (type == ringorder_ws || type == ringorder_Ws);
if (oneGrading || minusOneGrading || wGrading || minusWGrading)
{
const VarIndex begin = gradings.size();
gradings.resize(begin + varCount);
if (oneGrading || minusOneGrading)
{
if (weights != 0)
{
WerrorS("Expect wvhdl == 0 in Dp/dp/Ds/ds-block in ring.");
return false;
}
const Exponent value = oneGrading ? 1 : -1;
for (int var = block0 - 1; var < block1; ++var)
gradings[begin + var] = value;
}
else
{
if (weights == 0)
{
WerrorS("Expect wvhdl != 0 in a/Wp/wp/ws/Ws-block in ring.");
return false;
}
if (wGrading)
{
for (int var = 0; var < dim; ++var)
gradings[begin + (block0 - 1) + var] = weights[var];
}
else
{
for (int var = 0; var < dim; ++var)
gradings[begin + (block0 - 1) + var] = -weights[var];
}
}
}
if (type == ringorder_a)
continue; // a has only the grading, so we are done already
// * handle the lex/revlex part
const bool lexFromLeft =
type == ringorder_lp ||
type == ringorder_Dp ||
type == ringorder_Ds ||
type == ringorder_Wp ||
type == ringorder_Ws;
const bool lexFromRight = type == ringorder_rp;
const bool revlexFromLeft = type == ringorder_ls;
const bool revlexFromRight =
type == ringorder_rs ||
type == ringorder_dp ||
type == ringorder_ds ||
type == ringorder_wp ||
type == ringorder_ws;
if (lexFromLeft || lexFromRight || revlexFromLeft || revlexFromRight)
{
const int next = r->order[block + 1];
bool final = next == ringorder_no;
if (!final && r->order[block + 2] == ringorder_no)
final = next == ringorder_c || next == ringorder_C;
if (final)
{
if (lexFromRight)
baseOrder = mgb::GroebnerConfiguration::LexAscendingBaseOrder;
else if (revlexFromRight)
baseOrder = mgb::GroebnerConfiguration::RevLexDescendingBaseOrder;
else if (lexFromLeft)
baseOrder = mgb::GroebnerConfiguration::LexDescendingBaseOrder;
else
baseOrder = mgb::GroebnerConfiguration::RevLexAscendingBaseOrder;
continue;
}
const size_t begin = gradings.size();
gradings.resize(begin + dim * varCount);
const Exponent value = (lexFromLeft || lexFromRight) ? 1 : -1;
if (lexFromLeft || revlexFromLeft)
{
for (size_t row = 0; row < dim; ++row)
gradings[begin + row * varCount + (block0 - 1) + row] = value;
}
else
{
for (size_t row = 0; row < dim; ++row)
gradings[begin + row * varCount + (block1 - 1) - row] = value;
}
continue;
}
// *** ringorder_M: a square invertible matrix
if (type == ringorder_M)
{
if (weights == 0)
{
WerrorS("Expected wvhdl != 0 in M-block in ring.");
return false;
}
const size_t begin = gradings.size();
gradings.resize(begin + dim * varCount);
for (size_t row = 0; row < dim; ++row)
for (size_t col = block0 - 1; col < block1; ++col)
gradings[begin + row * varCount + col] = weights[row * dim + col];
continue;
}
// *** Miscellaneous unsupported or invalid block types
if (
type == ringorder_s ||
type == ringorder_S ||
type == ringorder_IS
)
{
// todo: Consider supporting this later.
WerrorS("Schreyer order s/S/IS not supported in MathicGB interface.");
return false;
}
if (type == ringorder_am)
{
// This block is a Schreyer-like ordering only used in Spielwiese.
// todo: Consider supporting it later.
WerrorS("Block type am not supported in MathicGB interface");
return false;
}
if (type == ringorder_L)
{
WerrorS("Invalid L-block found in order of ring.");
return false;
}
if (type == ringorder_aa)
{
// I don't know what an aa block is supposed to do.
WerrorS("aa ordering not supported by the MathicGB interface.");
return false;
}
if (type == ringorder_unspec)
{
WerrorS("Invalid unspec-block found in order of ring.");
return false;
}
WerrorS("Unknown block type found in order of ring.");
return false;
}
if (!didSetComponentBefore)
{
WerrorS("Expected to find a c/C block in ring.");
return false;
}
if (!conf.setMonomialOrder(baseOrder, gradings))
{
WerrorS("MathicGB does not support non-global orders.");
return false;
}
return true;
}
next
ListNode * next
Definition janet.h:31
rRingOrder_t
rRingOrder_t
order stuff
Definition ring.h:69
Exponent
mgb::GroebnerConfiguration::Exponent Exponent
Definition singmathic.cc:20
VarIndex
mgb::GroebnerConfiguration::VarIndex VarIndex
Definition singmathic.cc:19
dim
int dim(ideal I, ring r)
Definition tropicalStrategy.cc:23

## singmathic()

int SI_MOD_INIT singmathic | ( | SModulFunctions * | psModulFunctions | ) |

Definition at line 585 of file singmathic.cc.

{
psModulFunctions->iiAddCproc(
(currPack->libname ? currPack->libname : ""),
"mathicgb",
FALSE,
mathicgb
);
psModulFunctions->iiAddCproc(
(currPack->libname ? currPack->libname : ""),
"mathicgb_prOrder",
FALSE,
prOrderX
);
return MAX_TOK;
}
currPack
VAR package currPack
Definition ipid.cc:55
SModulFunctions::iiAddCproc
int(* iiAddCproc)(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition ipid.h:70
mathicgb
BOOLEAN mathicgb(leftv result, leftv arg)
Definition singmathic.cc:520
prOrderX
BOOLEAN prOrderX(leftv result, leftv arg)
Definition singmathic.cc:507
MAX_TOK
@ MAX_TOK
Definition tok.h:220