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