My Project  UNKNOWN_GIT_VERSION
mod_main.cc
Go to the documentation of this file.
1 #include "kernel/mod2.h"
2 
3 #include "omalloc/omalloc.h"
4 
5 #include "misc/intvec.h"
6 #include "misc/options.h"
7 
8 #include "coeffs/coeffs.h"
9 
10 #include "polys/PolyEnumerator.h"
11 
13 #include "polys/monomials/ring.h"
14 #include "polys/simpleideals.h"
15 
16 #include "kernel/GBEngine/kstd1.h"
17 
18 #include "kernel/polys.h"
19 
20 #include "kernel/GBEngine/syz.h"
21 
22 #include "Singular/tok.h"
23 #include "Singular/ipid.h"
24 #include "Singular/lists.h"
25 #include "Singular/attrib.h"
26 
27 #include "Singular/ipid.h"
28 #include "Singular/ipshell.h" // For iiAddCproc
29 
30 // extern coeffs coeffs_BIGINT
31 
32 #include "singularxx_defs.h"
33 
34 #include "syzextra.h"
35 
36 
37 #include "Singular/mod_lib.h"
38 
39 
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 
44 #include "polys/monomials/ring.h"
45 
46 
47 // returns TRUE, if idRankFreeModule(m) > 0 ???
48 /// test whether this input has vectors among entries or no enties
49 /// result must be FALSE for only 0-entries
50 static BOOLEAN id_IsModule(ideal id, ring r)
51 {
52  id_Test(id, r);
53 
54  if( id->rank != 1 ) return TRUE;
55 
56  if (rRing_has_Comp(r))
57  {
58  const int l = IDELEMS(id);
59 
60  for (int j=0; j<l; j++)
61  if (id->m[j] != NULL && p_GetComp(id->m[j], r) > 0)
62  return TRUE;
63 
64  return FALSE; // rank: 1, only zero or no entries? can be an ideal OR module... BUT in the use-case should better be an ideal!
65  }
66 
67  return FALSE;
68 }
69 
70 
71 
72 
73 static inline void NoReturn(leftv& res)
74 {
75  res->rtyp = NONE;
76  res->data = NULL;
77 }
78 
79 /// wrapper around n_ClearContent
81 {
82  NoReturn(res);
83 
84  const char *usage = "'ClearContent' needs a (non-zero!) poly or vector argument...";
85 
86  if( h == NULL )
87  {
88  WarnS(usage);
89  return TRUE;
90  }
91 
92  assume( h != NULL );
93 
94  if( !( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD) )
95  {
96  WarnS(usage);
97  return TRUE;
98  }
99 
100  assume (h->Next() == NULL);
101 
102  poly ph = reinterpret_cast<poly>(h->Data());
103 
104  if( ph == NULL )
105  {
106  WarnS(usage);
107  return TRUE;
108  }
109 
110  const ring r = currRing;
111  assume( r != NULL ); assume( r->cf != NULL ); const coeffs C = r->cf;
112 
113  number n;
114 
115  // experimentall (recursive enumerator treatment) of alg. ext
116  CPolyCoeffsEnumerator itr(ph);
117  n_ClearContent(itr, n, C);
118 
119  res->data = n;
120  res->rtyp = NUMBER_CMD;
121 
122  return FALSE;
123 }
124 
125 /// wrapper around n_ClearDenominators
127 {
128  NoReturn(res);
129 
130  const char *usage = "'ClearDenominators' needs a (non-zero!) poly or vector argument...";
131 
132  if( h == NULL )
133  {
134  WarnS(usage);
135  return TRUE;
136  }
137 
138  assume( h != NULL );
139 
140  if( !( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD) )
141  {
142  WarnS(usage);
143  return TRUE;
144  }
145 
146  assume (h->Next() == NULL);
147 
148  poly ph = reinterpret_cast<poly>(h->Data());
149 
150  if( ph == NULL )
151  {
152  WarnS(usage);
153  return TRUE;
154  }
155 
156  const ring r = currRing;
157  assume( r != NULL ); assume( r->cf != NULL ); const coeffs C = r->cf;
158 
159  number n;
160 
161  // experimentall (recursive enumerator treatment) of alg. ext.
162  CPolyCoeffsEnumerator itr(ph);
163  n_ClearDenominators(itr, n, C);
164 
165  res->data = n;
166  res->rtyp = NUMBER_CMD;
167 
168  return FALSE;
169 }
170 
171 
172 /// try to get an optional (simple) integer argument out of h
173 /// or return the default value
174 static int getOptionalInteger(const leftv& h, const int _n)
175 {
176  if( h!= NULL && h->Typ() == INT_CMD )
177  {
178  int n = (int)(long)(h->Data());
179 
180  if( n < 0 )
181  Warn("Negative (%d) optional integer argument", n);
182 
183  return (n);
184  }
185 
186  return (_n);
187 }
188 
189 static inline number jjLONG2N(long d)
190 {
191  return n_Init(d, coeffs_BIGINT);
192 }
193 
194 static inline void view(const intvec* v)
195 {
196 #ifndef SING_NDEBUG
197  v->view();
198 #else
199  // This code duplication is only due to Hannes's #ifndef SING_NDEBUG!
200  Print ("intvec: {rows: %d, cols: %d, length: %d, Values: \n", v->rows(), v->cols(), v->length());
201 
202  for (int i = 0; i < v->rows(); i++)
203  {
204  Print ("Row[%3d]:", i);
205  for (int j = 0; j < v->cols(); j++)
206  Print (" %5d", (*v)[j + i * (v->cols())] );
207  PrintLn ();
208  }
209  PrintS ("}\n");
210 #endif
211 
212 }
213 
214 
215 
216 /// wrapper around p_Tail and id_Tail
218 {
219  NoReturn(res);
220 
221  if( h == NULL )
222  {
223  WarnS("Tail needs a poly/vector/ideal/module argument...");
224  return TRUE;
225  }
226 
227  assume( h != NULL );
228 
229  const ring r = currRing;
230 
231  if( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD)
232  {
233  res->data = p_Tail( (const poly)h->Data(), r );
234  res->rtyp = h->Typ();
235 
236  h = h->Next(); assume (h == NULL);
237 
238  return FALSE;
239  }
240 
241  if( h->Typ() == IDEAL_CMD || h->Typ() == MODUL_CMD)
242  {
243  res->data = id_Tail( (const ideal)h->Data(), r );
244  res->rtyp = h->Typ();
245 
246  h = h->Next(); assume (h == NULL);
247 
248  return FALSE;
249  }
250 
251  WarnS("Tail needs a single poly/vector/ideal/module argument...");
252  return TRUE;
253 }
254 
255 /// Get leading component
257 {
258  if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD))
259  {
260  const ring r = currRing;
261 
262  const poly p = (poly)(h->Data());
263 
264  if (p != NULL )
265  {
266  assume( p != NULL );
267  p_LmTest(p, r);
268 
269  const unsigned long iComp = p_GetComp(p, r);
270 
271  // assume( iComp > 0 ); // p is a vector
272 
273  res->data = reinterpret_cast<void *>(jjLONG2N(iComp));
274  }
275  else
276  res->data = reinterpret_cast<void *>(jjLONG2N(0));
277 
278 
279  res->rtyp = BIGINT_CMD;
280  return FALSE;
281  }
282 
283  WerrorS("`leadcomp(<poly/vector>)` expected");
284  return TRUE;
285 }
286 
287 /// Same for Induced Schreyer ordering (ordering on components is defined by sign!)
289 {
290  int sign = 1;
291  if ((h!=NULL) && (h->Typ()==INT_CMD))
292  {
293  const int s = (int)((long)(h->Data()));
294 
295  if( s != -1 && s != 1 )
296  {
297  WerrorS("`MakeInducedSchreyerOrdering(<int>)` called with wrong integer argument (must be +-1)!");
298  return TRUE;
299  }
300 
301  sign = s;
302  }
303 
304  assume( sign == 1 || sign == -1 );
305  res->data = reinterpret_cast<void *>(rAssure_InducedSchreyerOrdering(currRing, TRUE, sign));
306  res->rtyp = RING_CMD; // return new ring!
307  // QRING_CMD?
308  return FALSE;
309 }
310 
311 
312 /// ?
314 {
315  const ring r = currRing;
316 
317  int p = 0; // which IS-block? p^th!
318 
319  if ((h!=NULL) && (h->Typ()==INT_CMD))
320  {
321  p = (int)((long)(h->Data())); h=h->next;
322  assume(p >= 0);
323  }
324 
325  const int pos = rGetISPos(p, r);
326 
327  if( /*(*/ -1 == pos /*)*/ )
328  {
329  WerrorS("`GetInducedData([int])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)");
330  return TRUE;
331  }
332 
333 
334  const int iLimit = r->typ[pos].data.is.limit;
335  const ideal F = r->typ[pos].data.is.F;
336 
337  ideal FF = id_Copy(F, r);
338 
340  l->Init(2);
341 
342  l->m[0].rtyp = INT_CMD;
343  l->m[0].data = reinterpret_cast<void *>(iLimit);
344 
345 
346  // l->m[1].rtyp = MODUL_CMD;
347 
348  if( id_IsModule(FF, r) ) // ???
349  {
350  l->m[1].rtyp = MODUL_CMD;
351 
352  // Print("before: %d\n", FF->nrows);
353  // FF->nrows = id_RankFreeModule(FF, r); // ???
354  // Print("after: %d\n", FF->nrows);
355  }
356  else
357  l->m[1].rtyp = IDEAL_CMD;
358 
359  l->m[1].data = reinterpret_cast<void *>(FF);
360 
361  res->rtyp = LIST_CMD; // list of int/module
362  res->data = reinterpret_cast<void *>(l);
363 
364  return FALSE;
365 
366 }
367 
368 /// Returns old SyzCompLimit, can set new limit
370 {
371  res->Init();
372  NoReturn(res);
373 
374  const ring r = currRing;
375 
376  if( !( (h!=NULL) && ( (h->Typ()==IDEAL_CMD) || (h->Typ()==MODUL_CMD))) )
377  {
378  WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` expected");
379  return TRUE;
380  }
381 
382  const ideal F = (ideal)h->Data(); ; // No copy!
383  h=h->next;
384 
385  int rank = 0;
386 
387  if ((h!=NULL) && (h->Typ()==INT_CMD))
388  {
389  rank = (int)((long)(h->Data())); h=h->next;
390  assume(rank >= 0);
391  } else
392  rank = id_RankFreeModule(F, r); // Starting syz-comp (1st: i+1)
393 
394  int p = 0; // which IS-block? p^th!
395 
396  if ((h!=NULL) && (h->Typ()==INT_CMD))
397  {
398  p = (int)((long)(h->Data())); h=h->next;
399  assume(p >= 0);
400  }
401 
402  const int posIS = rGetISPos(p, r);
403 
404  if( /*(*/ -1 == posIS /*)*/ )
405  {
406  WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)");
407  return TRUE;
408  }
409 
410  // F & componentWeights belong to that ordering block of currRing now:
411  rSetISReference(r, F, rank, p); // F will be copied!
412  return FALSE;
413 }
414 
415 
416 /// Get raw syzygies (idPrepare)
418 {
419  // extern int rGetISPos(const int p, const ring r);
420 
421  const ring r = currRing;
422 
423  const bool isSyz = rIsSyzIndexRing(r);
424  const int posIS = rGetISPos(0, r);
425 
426 
427  if ( !( (h!=NULL) && (h->Typ()==MODUL_CMD) && (h->Data() != NULL) ) )
428  {
429  WerrorS("`idPrepare(<module>)` expected");
430  return TRUE;
431  }
432 
433  const ideal I = reinterpret_cast<ideal>(h->Data());
434 
435  assume( I != NULL );
436  idTest(I);
437 
438  int iComp = -1;
439 
440  h=h->next;
441  if ( (h!=NULL) && (h->Typ()==INT_CMD) )
442  {
443  iComp = (int)((long)(h->Data()));
444  }
445  else
446  {
447  if( (!isSyz) && (-1 == posIS) )
448  {
449  WerrorS("`idPrepare(<...>)` called on incompatible ring (not created by 'MakeSyzCompOrdering' or 'MakeInducedSchreyerOrdering'!)");
450  return TRUE;
451  }
452 
453  if( isSyz )
454  iComp = rGetCurrSyzLimit(r);
455  else
456  iComp = id_RankFreeModule(r->typ[posIS].data.is.F, r); // ;
457  }
458 
459  assume(iComp >= 0);
460 
461 
462  intvec* w = reinterpret_cast<intvec *>(atGet(h, "isHomog", INTVEC_CMD));
463  tHomog hom = testHomog;
464 
465  // int add_row_shift = 0;
466  //
467  if (w!=NULL)
468  {
469  w = ivCopy(w);
470  // add_row_shift = ww->min_in();
471  //
472  // (*ww) -= add_row_shift;
473  //
474  // if (idTestHomModule(I, currRing->qideal, ww))
475  // {
476  hom = isHomog;
477  // w = ww;
478  // }
479  // else
480  // {
481  // //WarnS("wrong weights");
482  // delete ww;
483  // w = NULL;
484  // hom=testHomog;
485  // }
486  }
487 
488 
489  // computes syzygies of h1,
490  // works always in a ring with ringorder_s
491  // NOTE: rSetSyzComp(syzcomp) should better be called beforehand
492  // ideal idPrepare (ideal h1, tHomog hom, int syzcomp, intvec **w);
493 
494  ideal J = // idPrepare( I, hom, iComp, &w);
495  kStd(I, currRing->qideal, hom, &w, NULL, iComp);
496 
497  idTest(J);
498 
499  if (w!=NULL)
500  atSet(res, omStrDup("isHomog"), w, INTVEC_CMD);
501  // if (w!=NULL) delete w;
502 
503  res->rtyp = MODUL_CMD;
504  res->data = reinterpret_cast<void *>(J);
505  return FALSE;
506 }
507 
508 extern "C" int SI_MOD_INIT(syzextra)(SModulFunctions* psModulFunctions)
509 {
510 
511 #define ADD(C,D,E) \
512  psModulFunctions->iiAddCproc((currPack->libname? currPack->libname: ""), (char*)C, D, E);
513 
514 
515  ADD("ClearContent", FALSE, _ClearContent);
516  ADD("ClearDenominators", FALSE, _ClearDenominators);
517 
518  ADD("leadcomp", FALSE, leadcomp);
519 
520  ADD("SetInducedReferrence", FALSE, SetInducedReferrence);
521  ADD("GetInducedData", FALSE, GetInducedData);
522  ADD("MakeInducedSchreyerOrdering", FALSE, MakeInducedSchreyerOrdering);
523 
524  ADD("idPrepare", FALSE, idPrepare);
525 
526  ADD("Tail", FALSE, Tail);
527 
528 #undef ADD
529  return MAX_TOK;
530 }
NoReturn
static void NoReturn(leftv &res)
Definition: mod_main.cc:73
singularxx_defs.h
FALSE
#define FALSE
Definition: auxiliary.h:94
mod_lib.h
SetInducedReferrence
static BOOLEAN SetInducedReferrence(leftv res, leftv h)
Returns old SyzCompLimit, can set new limit.
Definition: mod_main.cc:369
omalloc.h
MakeInducedSchreyerOrdering
static BOOLEAN MakeInducedSchreyerOrdering(leftv res, leftv h)
Same for Induced Schreyer ordering (ordering on components is defined by sign!)
Definition: mod_main.cc:288
p_GetComp
#define p_GetComp(p, r)
Definition: monomials.h:62
j
int j
Definition: facHensel.cc:105
leadcomp
static BOOLEAN leadcomp(leftv res, leftv h)
Get leading component.
Definition: mod_main.cc:256
NUMBER_CMD
Definition: grammar.cc:288
BIGINT_CMD
Definition: tok.h:37
LIST_CMD
Definition: tok.h:117
lists.h
attrib.h
MODUL_CMD
Definition: grammar.cc:287
NONE
#define NONE
Definition: tok.h:218
MAX_TOK
Definition: tok.h:215
polys.h
simpleideals.h
omStrDup
#define omStrDup(s)
Definition: omAllocDecl.h:261
sign
static int sign(int x)
Definition: ring.cc:3345
omAllocBin
#define omAllocBin(bin)
Definition: omAllocDecl.h:203
options.h
idTest
#define idTest(id)
Definition: ideals.h:46
testHomog
Definition: structs.h:40
idPrepare
static BOOLEAN idPrepare(leftv res, leftv h)
Get raw syzygies (idPrepare)
Definition: mod_main.cc:417
sleftv
Class used for (list of) interpreter objects.
Definition: subexpr.h:81
w
const CanonicalForm & w
Definition: facAbsFact.cc:55
RING_CMD
Definition: grammar.cc:281
syzextra.h
slists_bin
omBin slists_bin
Definition: lists.cc:22
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:4936
Tail
static BOOLEAN Tail(leftv res, leftv h)
wrapper around p_Tail and id_Tail
Definition: mod_main.cc:217
CPolyCoeffsEnumerator
Definition: PolyEnumerator.h:129
tHomog
tHomog
Definition: structs.h:36
rGetCurrSyzLimit
static int rGetCurrSyzLimit(const ring r)
Definition: ring.h:712
currRing
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
TRUE
#define TRUE
Definition: auxiliary.h:98
i
int i
Definition: cfEzgcd.cc:125
ivCopy
intvec * ivCopy(const intvec *o)
Definition: intvec.h:132
res
CanonicalForm res
Definition: facAbsFact.cc:64
INT_CMD
Definition: tok.h:95
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:781
PrintS
void PrintS(const char *s)
Definition: reporter.cc:283
BOOLEAN
int BOOLEAN
Definition: auxiliary.h:85
GetInducedData
static BOOLEAN GetInducedData(leftv res, leftv h)
?
Definition: mod_main.cc:313
id_Tail
ideal id_Tail(const ideal id, const ring r)
return the tail of a given ideal or module returns NULL if input is NULL, otherwise the result is a n...
Definition: syzextra.cc:50
p_Tail
poly p_Tail(const poly p, const ring r)
return the tail of a given polynomial or vector returns NULL if input is NULL, otherwise the result i...
Definition: syzextra.cc:42
IDEAL_CMD
Definition: grammar.cc:284
h
static Poly * h
Definition: janet.cc:972
mod2.h
coeffs
atSet
void atSet(idhdl root, char *name, void *data, int typ)
Definition: attrib.cc:151
intvec
Definition: intvec.h:16
isHomog
Definition: structs.h:39
jjLONG2N
static number jjLONG2N(long d)
Definition: mod_main.cc:189
getOptionalInteger
static int getOptionalInteger(const leftv &h, const int _n)
try to get an optional (simple) integer argument out of h or return the default value
Definition: mod_main.cc:174
p_polys.h
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:537
VECTOR_CMD
Definition: grammar.cc:292
syzextra
int SI_MOD_INIT() syzextra(SModulFunctions *psModulFunctions)
Definition: mod_main.cc:508
intvec.h
PolyEnumerator.h
rAssure_InducedSchreyerOrdering
ring rAssure_InducedSchreyerOrdering(const ring r, BOOLEAN complete, int sgn)
Definition: ring.cc:4768
ADD
#define ADD(C, D, E)
p_LmTest
#define p_LmTest(p, r)
Definition: p_polys.h:157
slists
Definition: lists.h:21
INTVEC_CMD
Definition: tok.h:100
_ClearDenominators
static BOOLEAN _ClearDenominators(leftv res, leftv h)
wrapper around n_ClearDenominators
Definition: mod_main.cc:126
coeffs_BIGINT
coeffs coeffs_BIGINT
Definition: ipid.cc:51
ring.h
id_IsModule
static BOOLEAN id_IsModule(ideal id, ring r)
test whether this input has vectors among entries or no enties result must be FALSE for only 0-entrie...
Definition: mod_main.cc:50
kstd1.h
_ClearContent
static BOOLEAN _ClearContent(leftv res, leftv h)
wrapper around n_ClearContent
Definition: mod_main.cc:80
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:949
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:956
rRing_has_Comp
#define rRing_has_Comp(r)
Definition: monomials.h:259
Print
#define Print
Definition: emacs.cc:79
atGet
void * atGet(idhdl root, const char *name, int t, void *defaultReturnValue)
Definition: attrib.cc:130
tok.h
WerrorS
void WerrorS(const char *s)
Definition: feFopen.cc:24
WarnS
#define WarnS
Definition: emacs.cc:77
SModulFunctions
Definition: ipid.h:66
syz.h
assume
#define assume(x)
Definition: mod2.h:384
NULL
#define NULL
Definition: omList.c:9
lists
slists * lists
Definition: mpr_numeric.h:145
l
int l
Definition: cfEzgcd.cc:93
Warn
#define Warn
Definition: emacs.cc:76
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
p
int p
Definition: cfModGcd.cc:4019
s
const CanonicalForm int s
Definition: facAbsFact.cc:55
POLY_CMD
Definition: grammar.cc:289
rIsSyzIndexRing
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition: ring.h:709
ipshell.h
IDELEMS
#define IDELEMS(i)
Definition: simpleideals.h:24
kStd
ideal kStd(ideal F, ideal Q, tHomog h, intvec **w, intvec *hilb, int syzComp, int newIdeal, intvec *vw, s_poly_proc_t sp)
Definition: kstd1.cc:2086
id_Copy
ideal id_Copy(ideal h1, const ring r)
copy an ideal
Definition: simpleideals.cc:403
PrintLn
void PrintLn()
Definition: reporter.cc:309
id_Test
#define id_Test(A, lR)
Definition: simpleideals.h:79
view
static void view(const intvec *v)
Definition: mod_main.cc:194
ipid.h
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:4904
coeffs.h