Loading...
Searching...
No Matches
mod_main.cc
Go to the documentation of this file.
#include "kernel/mod2.h"
#include "misc/intvec.h"
#include "misc/options.h"
#include "coeffs/coeffs.h"
#include "polys/PolyEnumerator.h"
#include "polys/monomials/p_polys.h"
#include "polys/monomials/ring.h"
#include "polys/simpleideals.h"
#include "kernel/GBEngine/kstd1.h"
#include "kernel/polys.h"
#include "kernel/GBEngine/syz.h"
#include "Singular/tok.h"
#include "Singular/ipid.h"
#include "Singular/lists.h"
#include "Singular/attrib.h"
#include "Singular/ipid.h"
#include "Singular/ipshell.h" // For iiAddCproc
// extern coeffs coeffs_BIGINT
#include "syzextra.h"
#include "Singular/mod_lib.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "polys/monomials/ring.h"
static inline void NoReturn(leftv& res)
{
res->rtyp = NONE;
res->data = NULL;
}
/// wrapper around n_ClearContent
static BOOLEAN _ClearContent(leftv res, leftv h)
{
NoReturn(res);
const char *usage = "'ClearContent' needs a (non-zero!) poly or vector argument...";
if( h == NULL )
{
WarnS(usage);
return TRUE;
}
assume( h != NULL );
if( !( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD) )
{
WarnS(usage);
return TRUE;
}
assume (h->Next() == NULL);
poly ph = reinterpret_cast<poly>(h->Data());
if( ph == NULL )
{
WarnS(usage);
return TRUE;
}
const ring r = currRing;
assume( r != NULL ); assume( r->cf != NULL ); const coeffs C = r->cf;
number n;
// experimentall (recursive enumerator treatment) of alg. ext
CPolyCoeffsEnumerator itr(ph);
n_ClearContent(itr, n, C);
res->data = n;
res->rtyp = NUMBER_CMD;
return FALSE;
}
/// wrapper around n_ClearDenominators
static BOOLEAN _ClearDenominators(leftv res, leftv h)
{
NoReturn(res);
const char *usage = "'ClearDenominators' needs a (non-zero!) poly or vector argument...";
if( h == NULL )
{
WarnS(usage);
return TRUE;
}
assume( h != NULL );
if( !( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD) )
{
WarnS(usage);
return TRUE;
}
assume (h->Next() == NULL);
poly ph = reinterpret_cast<poly>(h->Data());
if( ph == NULL )
{
WarnS(usage);
return TRUE;
}
const ring r = currRing;
assume( r != NULL ); assume( r->cf != NULL ); const coeffs C = r->cf;
number n;
// experimentall (recursive enumerator treatment) of alg. ext.
CPolyCoeffsEnumerator itr(ph);
n_ClearDenominators(itr, n, C);
res->data = n;
res->rtyp = NUMBER_CMD;
return FALSE;
}
#if 0 // unused
/// try to get an optional (simple) integer argument out of h
/// or return the default value
static int getOptionalInteger(const leftv& h, const int _n)
{
if( h!= NULL && h->Typ() == INT_CMD )
{
int n = (int)(long)(h->Data());
if( n < 0 )
Warn("Negative (%d) optional integer argument", n);
return (n);
}
return (_n);
}
#endif
static inline number jjLONG2N(long d)
{
return n_Init(d, coeffs_BIGINT);
}
static inline void view(const intvec* v)
{
#ifndef SING_NDEBUG
v->view();
#else
// This code duplication is only due to Hannes's #ifndef SING_NDEBUG!
Print ("intvec: {rows: %d, cols: %d, length: %d, Values: \n", v->rows(), v->cols(), v->length());
for (int i = 0; i < v->rows(); i++)
{
Print ("Row[%3d]:", i);
for (int j = 0; j < v->cols(); j++)
Print (" %5d", (*v)[j + i * (v->cols())] );
PrintLn ();
}
PrintS ("}\n");
#endif
}
/// Get leading component
static BOOLEAN leadcomp(leftv res, leftv h)
{
if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD))
{
const ring r = currRing;
const poly p = (poly)(h->Data());
if (p != NULL )
{
assume( p != NULL );
p_LmTest(p, r);
const unsigned long iComp = p_GetComp(p, r);
// assume( iComp > 0 ); // p is a vector
res->data = reinterpret_cast<void *>(jjLONG2N(iComp));
}
else
res->data = reinterpret_cast<void *>(jjLONG2N(0));
res->rtyp = BIGINT_CMD;
return FALSE;
}
WerrorS("`leadcomp(<poly/vector>)` expected");
return TRUE;
}
/// Same for Induced Schreyer ordering (ordering on components is defined by sign!)
static BOOLEAN MakeInducedSchreyerOrdering(leftv res, leftv h)
{
int sign = 1;
if ((h!=NULL) && (h->Typ()==INT_CMD))
{
const int s = (int)((long)(h->Data()));
if( s != -1 && s != 1 )
{
WerrorS("`MakeInducedSchreyerOrdering(<int>)` called with wrong integer argument (must be +-1)!");
return TRUE;
}
sign = s;
}
assume( sign == 1 || sign == -1 );
res->data = reinterpret_cast<void *>(rAssure_InducedSchreyerOrdering(currRing, TRUE, sign));
res->rtyp = RING_CMD; // return new ring!
// QRING_CMD?
return FALSE;
}
/// ?
static BOOLEAN GetInducedData(leftv res, leftv h)
{
const ring r = currRing;
int p = 0; // which IS-block? p^th!
if ((h!=NULL) && (h->Typ()==INT_CMD))
{
p = (int)((long)(h->Data())); h=h->next;
assume(p >= 0);
}
const int pos = rGetISPos(p, r);
if( /*(*/ -1 == pos /*)*/ )
{
WerrorS("`GetInducedData([int])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)");
return TRUE;
}
const int iLimit = r->typ[pos].data.is.limit;
const ideal F = r->typ[pos].data.is.F;
ideal FF = id_Copy(F, r);
lists l=(lists)omAllocBin(slists_bin);
l->Init(2);
l->m[0].rtyp = INT_CMD;
l->m[0].data = reinterpret_cast<void *>(iLimit);
// l->m[1].rtyp = MODUL_CMD;
if( id_IsModule(FF, r) ) // ???
{
l->m[1].rtyp = MODUL_CMD;
// Print("before: %d\n", FF->nrows);
// FF->nrows = id_RankFreeModule(FF, r); // ???
// Print("after: %d\n", FF->nrows);
}
else
l->m[1].rtyp = IDEAL_CMD;
l->m[1].data = reinterpret_cast<void *>(FF);
res->rtyp = LIST_CMD; // list of int/module
res->data = reinterpret_cast<void *>(l);
return FALSE;
}
/// Returns old SyzCompLimit, can set new limit
static BOOLEAN SetInducedReferrence(leftv res, leftv h)
{
res->Init();
NoReturn(res);
const ring r = currRing;
if( !( (h!=NULL) && ( (h->Typ()==IDEAL_CMD) || (h->Typ()==MODUL_CMD))) )
{
WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` expected");
return TRUE;
}
const ideal F = (ideal)h->Data(); ; // No copy!
h=h->next;
int rank = 0;
if ((h!=NULL) && (h->Typ()==INT_CMD))
{
rank = (int)((long)(h->Data())); h=h->next;
assume(rank >= 0);
} else
rank = id_RankFreeModule(F, r); // Starting syz-comp (1st: i+1)
int p = 0; // which IS-block? p^th!
if ((h!=NULL) && (h->Typ()==INT_CMD))
{
p = (int)((long)(h->Data())); h=h->next;
assume(p >= 0);
}
const int posIS = rGetISPos(p, r);
if( /*(*/ -1 == posIS /*)*/ )
{
WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)");
return TRUE;
}
// F & componentWeights belong to that ordering block of currRing now:
rSetISReference(r, F, rank, p); // F will be copied!
return FALSE;
}
/// Get raw syzygies (idPrepare)
static BOOLEAN idPrepare(leftv res, leftv h)
{
// extern int rGetISPos(const int p, const ring r);
const ring r = currRing;
const bool isSyz = rIsSyzIndexRing(r);
const int posIS = rGetISPos(0, r);
if ( !( (h!=NULL) && (h->Typ()==MODUL_CMD) && (h->Data() != NULL) ) )
{
WerrorS("`idPrepare(<module>)` expected");
return TRUE;
}
const ideal I = reinterpret_cast<ideal>(h->Data());
assume( I != NULL );
idTest(I);
int iComp = -1;
h=h->next;
if ( (h!=NULL) && (h->Typ()==INT_CMD) )
{
iComp = (int)((long)(h->Data()));
}
else
{
if( (!isSyz) && (-1 == posIS) )
{
WerrorS("`idPrepare(<...>)` called on incompatible ring (not created by 'MakeSyzCompOrdering' or 'MakeInducedSchreyerOrdering'!)");
return TRUE;
}
if( isSyz )
iComp = rGetCurrSyzLimit(r);
else
iComp = id_RankFreeModule(r->typ[posIS].data.is.F, r); // ;
}
assume(iComp >= 0);
intvec* w = reinterpret_cast<intvec *>(atGet(h, "isHomog", INTVEC_CMD));
tHomog hom = testHomog;
// int add_row_shift = 0;
//
if (w!=NULL)
{
w = ivCopy(w);
// add_row_shift = ww->min_in();
//
// (*ww) -= add_row_shift;
//
// if (idTestHomModule(I, currRing->qideal, ww))
// {
hom = isHomog;
// w = ww;
// }
// else
// {
// //WarnS("wrong weights");
// delete ww;
// w = NULL;
// hom=testHomog;
// }
}
// computes syzygies of h1,
// works always in a ring with ringorder_s
// NOTE: rSetSyzComp(syzcomp) should better be called beforehand
// ideal idPrepare (ideal h1, tHomog hom, int syzcomp, intvec **w);
ideal J = // idPrepare( I, hom, iComp, &w);
kStd2(I, currRing->qideal, hom, &w, (bigintmat*)NULL, iComp);
idTest(J);
if (w!=NULL)
atSet(res, omStrDup("isHomog"), w, INTVEC_CMD);
// if (w!=NULL) delete w;
res->rtyp = MODUL_CMD;
res->data = reinterpret_cast<void *>(J);
return FALSE;
}
extern "C" int SI_MOD_INIT(syzextra)(SModulFunctions* psModulFunctions)
{
#define ADD(C,D,E) \
psModulFunctions->iiAddCproc((currPack->libname? currPack->libname: ""), (char*)C, D, E);
ADD("ClearContent", FALSE, _ClearContent);
ADD("ClearDenominators", FALSE, _ClearDenominators);
ADD("leadcomp", FALSE, leadcomp);
ADD("SetInducedReferrence", FALSE, SetInducedReferrence);
ADD("GetInducedData", FALSE, GetInducedData);
ADD("MakeInducedSchreyerOrdering", FALSE, MakeInducedSchreyerOrdering);
ADD("idPrepare", FALSE, idPrepare);
#undef ADD
return MAX_TOK;
}
PolyEnumerator.h
Concrete implementation of enumerators over polynomials.
atSet
void atSet(idhdl root, char *name, void *data, int typ)
Definition attrib.cc:153
atGet
void * atGet(idhdl root, const char *name, int t, void *defaultReturnValue)
Definition attrib.cc:132
attrib.h
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
TRUE
#define TRUE
Definition auxiliary.h:101
FALSE
#define FALSE
Definition auxiliary.h:97
l
int l
Definition cfEzgcd.cc:100
i
int i
Definition cfEzgcd.cc:132
p
int p
Definition cfModGcd.cc:4086
CPolyCoeffsEnumerator
This is a polynomial enumerator for simple iteration over coefficients of polynomials.
Definition PolyEnumerator.h:130
bigintmat
Matrices of numbers.
Definition bigintmat.h:51
intvec
Definition intvec.h:24
coeffs.h
Coefficient rings, fields and other domains suitable for Singular polynomials.
n_ClearDenominators
static FORCE_INLINE void n_ClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &d, const coeffs r)
(inplace) Clears denominators on a collection of numbers number d is the LCM of all the coefficient d...
Definition coeffs.h:934
n_Init
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition coeffs.h:541
n_ClearContent
static FORCE_INLINE void n_ClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs r)
Computes the content and (inplace) divides it out on a collection of numbers number c is the content ...
Definition coeffs.h:927
Print
#define Print
Definition emacs.cc:80
Warn
#define Warn
Definition emacs.cc:77
WarnS
#define WarnS
Definition emacs.cc:78
s
const CanonicalForm int s
Definition facAbsFact.cc:51
res
CanonicalForm res
Definition facAbsFact.cc:60
w
const CanonicalForm & w
Definition facAbsFact.cc:51
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
j
int j
Definition facHensel.cc:110
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
IDEAL_CMD
@ IDEAL_CMD
Definition grammar.cc:285
MODUL_CMD
@ MODUL_CMD
Definition grammar.cc:288
VECTOR_CMD
@ VECTOR_CMD
Definition grammar.cc:293
NUMBER_CMD
@ NUMBER_CMD
Definition grammar.cc:289
POLY_CMD
@ POLY_CMD
Definition grammar.cc:290
RING_CMD
@ RING_CMD
Definition grammar.cc:282
idPrepare
static ideal idPrepare(ideal h1, ideal h11, tHomog hom, int syzcomp, intvec **w, GbVariant alg)
Definition ideals.cc:613
id_Copy
ideal id_Copy(ideal h1, const ring r)
copy an ideal
Definition simpleideals.cc:542
idTest
#define idTest(id)
Definition ideals.h:47
intvec.h
ivCopy
intvec * ivCopy(const intvec *o)
Definition intvec.h:146
ipid.h
SModulFunctions
Definition ipid.h:69
ipshell.h
h
STATIC_VAR Poly * h
Definition janet.cc:971
kStd2
ideal kStd2(ideal F, ideal Q, tHomog h, intvec **w, bigintmat *hilb, int syzComp, int newIdeal, intvec *vw, s_poly_proc_t sp)
generic interface to GB/SB computations, large hilbert vectors
Definition kstd1.cc:2607
kstd1.h
slists_bin
VAR omBin slists_bin
Definition lists.cc:23
lists.h
mod2.h
assume
#define assume(x)
Definition mod2.h:389
mod_lib.h
p_GetComp
#define p_GetComp(p, r)
Definition monomials.h:64
lists
slists * lists
Definition mpr_numeric.h:146
coeffs
The main handler for Singular numbers which are suitable for Singular polynomials.
omStrDup
#define omStrDup(s)
Definition omAllocDecl.h:263
omAllocBin
#define omAllocBin(bin)
Definition omAllocDecl.h:205
NULL
#define NULL
Definition omList.c:12
options.h
p_polys.h
p_LmTest
#define p_LmTest(p, r)
Definition p_polys.h:162
coeffs_BIGINT
VAR coeffs coeffs_BIGINT
Definition polys.cc:14
currRing
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
polys.h
Compatibility layer for legacy polynomial operations (over currRing).
PrintS
void PrintS(const char *s)
Definition reporter.cc:288
PrintLn
void PrintLn()
Definition reporter.cc:314
rAssure_InducedSchreyerOrdering
ring rAssure_InducedSchreyerOrdering(const ring r, BOOLEAN complete, int sgn)
Definition ring.cc:4989
rGetISPos
int rGetISPos(const int p, const ring r)
Finds p^th IS ordering, and returns its position in r->typ[] returns -1 if something went wrong!...
Definition ring.cc:5144
rSetISReference
BOOLEAN rSetISReference(const ring r, const ideal F, const int i, const int p)
Changes r by setting induced ordering parameters: limit and reference leading terms F belong to r,...
Definition ring.cc:5176
sign
static int sign(int x)
Definition ring.cc:3504
ring.h
rGetCurrSyzLimit
static int rGetCurrSyzLimit(const ring r)
Definition ring.h:729
rIsSyzIndexRing
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition ring.h:726
id_IsModule
BOOLEAN id_IsModule(ideal A, const ring src)
Definition simpleideals.cc:1011
id_RankFreeModule
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
Definition simpleideals.cc:992
simpleideals.h
leftv
sleftv * leftv
Definition structs.h:53
tHomog
tHomog
Definition structs.h:31
isHomog
@ isHomog
Definition structs.h:33
testHomog
@ testHomog
Definition structs.h:34
syz.h
GetInducedData
static BOOLEAN GetInducedData(leftv res, leftv h)
?
Definition mod_main.cc:244
idPrepare
static BOOLEAN idPrepare(leftv res, leftv h)
Get raw syzygies (idPrepare).
Definition mod_main.cc:348
syzextra
int SI_MOD_INIT syzextra(SModulFunctions *psModulFunctions)
Definition mod_main.cc:439
ADD
#define ADD(C, D, E)
leadcomp
static BOOLEAN leadcomp(leftv res, leftv h)
Get leading component.
Definition mod_main.cc:187
view
static void view(const intvec *v)
Definition mod_main.cc:164
_ClearDenominators
static BOOLEAN _ClearDenominators(leftv res, leftv h)
wrapper around n_ClearDenominators
Definition mod_main.cc:95
SetInducedReferrence
static BOOLEAN SetInducedReferrence(leftv res, leftv h)
Returns old SyzCompLimit, can set new limit.
Definition mod_main.cc:300
MakeInducedSchreyerOrdering
static BOOLEAN MakeInducedSchreyerOrdering(leftv res, leftv h)
Same for Induced Schreyer ordering (ordering on components is defined by sign!).
Definition mod_main.cc:219
_ClearContent
static BOOLEAN _ClearContent(leftv res, leftv h)
wrapper around n_ClearContent
Definition mod_main.cc:49
NoReturn
static void NoReturn(leftv &res)
Definition mod_main.cc:42
jjLONG2N
static number jjLONG2N(long d)
Definition mod_main.cc:159
syzextra.h
Computation of Syzygies.
tok.h
BIGINT_CMD
@ BIGINT_CMD
Definition tok.h:38
LIST_CMD
@ LIST_CMD
Definition tok.h:118
INTVEC_CMD
@ INTVEC_CMD
Definition tok.h:101
INT_CMD
@ INT_CMD
Definition tok.h:96
MAX_TOK
@ MAX_TOK
Definition tok.h:220
NONE
#define NONE
Definition tok.h:223