My Project  debian-1:4.1.1-p2+ds-4build4
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 #if GOOGLE_PROFILE_ENABLED
41 #include <google/profiler.h>
42 #endif // #if GOOGLE_PROFILE_ENABLED
43 
44 
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48 
49 #include "polys/monomials/ring.h"
50 
51 
52 // returns TRUE, if idRankFreeModule(m) > 0 ???
53 /// test whether this input has vectors among entries or no enties
54 /// result must be FALSE for only 0-entries
55 static BOOLEAN id_IsModule(ideal id, ring r)
56 {
57  id_Test(id, r);
58 
59  if( id->rank != 1 ) return TRUE;
60 
61  if (rRing_has_Comp(r))
62  {
63  const int l = IDELEMS(id);
64 
65  for (int j=0; j<l; j++)
66  if (id->m[j] != NULL && p_GetComp(id->m[j], r) > 0)
67  return TRUE;
68 
69  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!
70  }
71 
72  return FALSE;
73 }
74 
75 
76 
77 
78 static inline void NoReturn(leftv& res)
79 {
80  res->rtyp = NONE;
81  res->data = NULL;
82 }
83 
84 /// wrapper around n_ClearContent
86 {
87  NoReturn(res);
88 
89  const char *usage = "'ClearContent' needs a (non-zero!) poly or vector argument...";
90 
91  if( h == NULL )
92  {
93  WarnS(usage);
94  return TRUE;
95  }
96 
97  assume( h != NULL );
98 
99  if( !( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD) )
100  {
101  WarnS(usage);
102  return TRUE;
103  }
104 
105  assume (h->Next() == NULL);
106 
107  poly ph = reinterpret_cast<poly>(h->Data());
108 
109  if( ph == NULL )
110  {
111  WarnS(usage);
112  return TRUE;
113  }
114 
115  const ring r = currRing;
116  assume( r != NULL ); assume( r->cf != NULL ); const coeffs C = r->cf;
117 
118  number n;
119 
120  // experimentall (recursive enumerator treatment) of alg. ext
121  CPolyCoeffsEnumerator itr(ph);
122  n_ClearContent(itr, n, C);
123 
124  res->data = n;
125  res->rtyp = NUMBER_CMD;
126 
127  return FALSE;
128 }
129 
130 /// wrapper around n_ClearDenominators
132 {
133  NoReturn(res);
134 
135  const char *usage = "'ClearDenominators' needs a (non-zero!) poly or vector argument...";
136 
137  if( h == NULL )
138  {
139  WarnS(usage);
140  return TRUE;
141  }
142 
143  assume( h != NULL );
144 
145  if( !( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD) )
146  {
147  WarnS(usage);
148  return TRUE;
149  }
150 
151  assume (h->Next() == NULL);
152 
153  poly ph = reinterpret_cast<poly>(h->Data());
154 
155  if( ph == NULL )
156  {
157  WarnS(usage);
158  return TRUE;
159  }
160 
161  const ring r = currRing;
162  assume( r != NULL ); assume( r->cf != NULL ); const coeffs C = r->cf;
163 
164  number n;
165 
166  // experimentall (recursive enumerator treatment) of alg. ext.
167  CPolyCoeffsEnumerator itr(ph);
168  n_ClearDenominators(itr, n, C);
169 
170  res->data = n;
171  res->rtyp = NUMBER_CMD;
172 
173  return FALSE;
174 }
175 
176 
177 /// try to get an optional (simple) integer argument out of h
178 /// or return the default value
179 static int getOptionalInteger(const leftv& h, const int _n)
180 {
181  if( h!= NULL && h->Typ() == INT_CMD )
182  {
183  int n = (int)(long)(h->Data());
184 
185  if( n < 0 )
186  Warn("Negative (%d) optional integer argument", n);
187 
188  return (n);
189  }
190 
191  return (_n);
192 }
193 
194 static inline number jjLONG2N(long d)
195 {
196  return n_Init(d, coeffs_BIGINT);
197 }
198 
199 static inline void view(const intvec* v)
200 {
201 #ifndef SING_NDEBUG
202  v->view();
203 #else
204  // This code duplication is only due to Hannes's #ifndef SING_NDEBUG!
205  Print ("intvec: {rows: %d, cols: %d, length: %d, Values: \n", v->rows(), v->cols(), v->length());
206 
207  for (int i = 0; i < v->rows(); i++)
208  {
209  Print ("Row[%3d]:", i);
210  for (int j = 0; j < v->cols(); j++)
211  Print (" %5d", (*v)[j + i * (v->cols())] );
212  PrintLn ();
213  }
214  PrintS ("}\n");
215 #endif
216 
217 }
218 
219 
220 
221 /// wrapper around p_Tail and id_Tail
223 {
224  NoReturn(res);
225 
226  if( h == NULL )
227  {
228  WarnS("Tail needs a poly/vector/ideal/module argument...");
229  return TRUE;
230  }
231 
232  assume( h != NULL );
233 
234  const ring r = currRing;
235 
236  if( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD)
237  {
238  res->data = p_Tail( (const poly)h->Data(), r );
239  res->rtyp = h->Typ();
240 
241  h = h->Next(); assume (h == NULL);
242 
243  return FALSE;
244  }
245 
246  if( h->Typ() == IDEAL_CMD || h->Typ() == MODUL_CMD)
247  {
248  res->data = id_Tail( (const ideal)h->Data(), r );
249  res->rtyp = h->Typ();
250 
251  h = h->Next(); assume (h == NULL);
252 
253  return FALSE;
254  }
255 
256  WarnS("Tail needs a single poly/vector/ideal/module argument...");
257  return TRUE;
258 }
259 
260 // proc SchreyerSyzygyNF(vector syz_lead, vector syz_2, def L, def T, list #)
262 {
264 
265 // const BOOLEAN OPT__SYZCHECK = attributes.OPT__SYZCHECK;
266 // const BOOLEAN OPT__LEAD2SYZ = attributes.OPT__LEAD2SYZ;
267  const BOOLEAN OPT__HYBRIDNF = attributes.OPT__HYBRIDNF;
268  const BOOLEAN OPT__TAILREDSYZ = attributes.OPT__TAILREDSYZ;
269 
270  const char* usage = "`SchreyerSyzygyNF(<vector>, <vector>, <ideal/module>, <ideal/module>[,<module>])` expected";
271  const ring r = attributes.m_rBaseRing;
272 
273  NoReturn(res);
274 
275  assume( OPT__HYBRIDNF ); // ???
276 
277  if ((h==NULL) || (h->Typ() != VECTOR_CMD) || (h->Data() == NULL))
278  {
279  WerrorS(usage);
280  return TRUE;
281  }
282 
283  const poly syz_lead = (poly) h->Data(); assume (syz_lead != NULL);
284 
285 
286  h = h->Next();
287  if ((h==NULL) || (h->Typ() != VECTOR_CMD) || (h->Data() == NULL))
288  {
289  WerrorS(usage);
290  return TRUE;
291  }
292 
293  const poly syz_2 = (poly) h->Data(); assume (syz_2 != NULL);
294 
295  h = h->Next();
296  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
297  {
298  WerrorS(usage);
299  return TRUE;
300  }
301 
302  const ideal L = (ideal) h->Data(); assume( IDELEMS(L) > 0 );
303 
304 
305  h = h->Next();
306  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
307  {
308  WerrorS(usage);
309  return TRUE;
310  }
311 
312  const ideal T = (ideal) h->Data();
313 
314  assume( IDELEMS(L) == IDELEMS(T) );
315 
316  ideal LS = NULL;
317 
318  h = h->Next();
319  if ((h != NULL) && (h->Typ() ==MODUL_CMD) && (h->Data() != NULL))
320  {
321  LS = (ideal)h->Data();
322  h = h->Next();
323  }
324 
325 #ifndef SING_NDEBUG
326  if( LIKELY( OPT__TAILREDSYZ) )
327  assume (LS != NULL);
328 #endif
329 
330  assume( h == NULL );
331 
332  res->rtyp = VECTOR_CMD;
333  res->data = SchreyerSyzygyNF(syz_lead,
334  (syz_2!=NULL)? p_Copy(syz_2, r): syz_2, L, T, LS, attributes);
335 
336  return FALSE;
337 }
338 
339 
340 
341 /// proc SSReduceTerm(poly m, def t, def syzterm, def L, def T, list #)
343 {
345 
346 // const BOOLEAN OPT__SYZCHECK = attributes.OPT__SYZCHECK;
347 // const BOOLEAN OPT__LEAD2SYZ = attributes.OPT__LEAD2SYZ;
348 // const BOOLEAN OPT__HYBRIDNF = attributes.OPT__HYBRIDNF;
349  const BOOLEAN OPT__TAILREDSYZ = attributes.OPT__TAILREDSYZ;
350 
351  const char* usage = "`ReduceTerm(<poly>, <poly/vector>, <vector/0>, <ideal/module>, <ideal/module>[,<module>])` expected";
352  const ring r = attributes.m_rBaseRing;
353 
354  NoReturn(res);
355 
356  if ((h==NULL) || (h->Typ() !=POLY_CMD) || (h->Data() == NULL))
357  {
358  WerrorS(usage);
359  return TRUE;
360  }
361 
362  const poly multiplier = (poly) h->Data(); assume (multiplier != NULL);
363 
364 
365  h = h->Next();
366  if ((h==NULL) || (h->Typ()!=VECTOR_CMD && h->Typ() !=POLY_CMD) || (h->Data() == NULL))
367  {
368  WerrorS(usage);
369  return TRUE;
370  }
371 
372  const poly term4reduction = (poly) h->Data(); assume( term4reduction != NULL );
373 
374 
375  poly syztermCheck = NULL;
376 
377  h = h->Next();
378  if ((h==NULL) || !((h->Typ()==VECTOR_CMD) || (h->Data() == NULL)) )
379  {
380  WerrorS(usage);
381  return TRUE;
382  }
383 
384  if(h->Typ()==VECTOR_CMD)
385  syztermCheck = (poly) h->Data();
386 
387 
388  h = h->Next();
389  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
390  {
391  WerrorS(usage);
392  return TRUE;
393  }
394 
395  const ideal L = (ideal) h->Data(); assume( IDELEMS(L) > 0 );
396 
397 
398  h = h->Next();
399  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
400  {
401  WerrorS(usage);
402  return TRUE;
403  }
404 
405  const ideal T = (ideal) h->Data();
406 
407  assume( IDELEMS(L) == IDELEMS(T) );
408 
409  ideal LS = NULL;
410 
411  h = h->Next();
412  if ((h != NULL) && (h->Typ() ==MODUL_CMD) && (h->Data() != NULL))
413  {
414  LS = (ideal)h->Data();
415  h = h->Next();
416  }
417 
418 #ifndef SING_NDEBUG
419  if( LIKELY( OPT__TAILREDSYZ) )
420  assume (LS != NULL);
421 #endif
422 
423  assume( h == NULL );
424 
425  res->rtyp = VECTOR_CMD;
426  res->data = ReduceTerm(multiplier, term4reduction, syztermCheck, L, T, LS, attributes);
427 
428  return FALSE;
429 }
430 
431 
432 
433 
434 // proc SSTraverseTail(poly m, def @tail, def L, def T, list #)
436 {
438 
439 // const BOOLEAN OPT__SYZCHECK = attributes.OPT__SYZCHECK;
440 // const BOOLEAN OPT__LEAD2SYZ = attributes.OPT__LEAD2SYZ;
441 // const BOOLEAN OPT__HYBRIDNF = attributes.OPT__HYBRIDNF;
442  const BOOLEAN OPT__TAILREDSYZ = attributes.OPT__TAILREDSYZ;
443 
444  const char* usage = "`TraverseTail(<poly>, <poly/vector>, <ideal/module>, <ideal/module>[,<module>])` expected";
445  const ring r = attributes.m_rBaseRing;
446 
447  NoReturn(res);
448 
449  if ((h==NULL) || (h->Typ() !=POLY_CMD) || (h->Data() == NULL))
450  {
451  WerrorS(usage);
452  return TRUE;
453  }
454 
455  const poly multiplier = (poly) h->Data(); assume (multiplier != NULL);
456 
457  h = h->Next();
458  if ((h==NULL) || (h->Typ()!=VECTOR_CMD && h->Typ() !=POLY_CMD))
459  {
460  WerrorS(usage);
461  return TRUE;
462  }
463 
464  const poly tail = (poly) h->Data();
465 
466  h = h->Next();
467 
468  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
469  {
470  WerrorS(usage);
471  return TRUE;
472  }
473 
474  const ideal L = (ideal) h->Data();
475 
476  assume( IDELEMS(L) > 0 );
477 
478  h = h->Next();
479  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
480  {
481  WerrorS(usage);
482  return TRUE;
483  }
484 
485  const ideal T = (ideal) h->Data();
486 
487  assume( IDELEMS(L) == IDELEMS(T) );
488 
489  h = h->Next();
490 
491  ideal LS = NULL;
492 
493  if ((h != NULL) && (h->Typ() ==MODUL_CMD) && (h->Data() != NULL))
494  {
495  LS = (ideal)h->Data();
496  h = h->Next();
497  }
498 
499 #ifndef SING_NDEBUG
500  if( LIKELY( OPT__TAILREDSYZ) )
501  assume (LS != NULL);
502 #endif
503 
504  assume( h == NULL );
505 
506  res->rtyp = VECTOR_CMD;
507  res->data = TraverseTail(multiplier, tail, L, T, LS, attributes);
508 
509  return FALSE;
510 }
511 
512 
514 {
516 
517  const char* usage = "`ComputeResolution(<ideal/module>, <same as before>, <same as before>[,int])` expected";
518  const ring r = attributes.m_rBaseRing;
519 
520  NoReturn(res);
521 
522  // input
523  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
524  {
525  WerrorS(usage);
526  return TRUE;
527  }
528 
529  const int type = h->Typ();
530  ideal M = (ideal)(h->CopyD()); // copy for resolution...!???
531  int size = IDELEMS(M);
532 
533  assume( size >= 0 );
534 
535  h = h->Next();
536 
537  // lead
538  if ((h==NULL) || (h->Typ()!=type) || (h->Data() == NULL))
539  {
540  WerrorS(usage);
541  return TRUE;
542  }
543 
544  ideal L = (ideal)(h->CopyD()); // no copy!
545  assume( IDELEMS(L) == size );
546 
547  h = h->Next();
548  if ((h==NULL) || (h->Typ()!=type) || (h->Data() == NULL))
549  {
550  WerrorS(usage);
551  return TRUE;
552  }
553 
554  ideal T = (ideal)(h->CopyD()); // no copy!
555  assume( IDELEMS(T) == size );
556 
557  h = h->Next();
558 
559  // length..?
560  long length = 0;
561 
562  if ((h!=NULL) && (h->Typ()==INT_CMD))
563  {
564  length = (long)(h->Data());
565  h = h->Next();
566  }
567 
568  assume( h == NULL );
569 
570  if( length <= 0 )
571  length = 1 + rVar(r);
572 
573  syStrategy _res=(syStrategy)omAlloc0(sizeof(ssyStrategy));
574 
575 // class ssyStrategy; typedef ssyStrategy * syStrategy;
576 // typedef ideal * resolvente;
577 
578  _res->length = length + 1; // index + 1;
579  _res->fullres = (resolvente)omAlloc0((_res->length+1)*sizeof(ideal));
580  int index = 0;
581  _res->fullres[index++] = M;
582 
583 // if (UNLIKELY(attributes.OPT__TREEOUTPUT))
584 // Print("{ \"RESOLUTION: HYBRIDNF:%d, TAILREDSYZ: %d, LEAD2SYZ: %d, IGNORETAILS: %d\": [\n", attributes.OPT__HYBRIDNF, attributes.OPT__TAILREDSYZ, attributes.OPT__LEAD2SYZ, attributes.OPT__IGNORETAILS);
585 
586  while( (!idIs0(L)) && (index < length))
587  {
588  attributes.nextSyzygyLayer();
589  ideal LL, TT;
590 
591  ComputeSyzygy(L, T, LL, TT, attributes);
592 
593  size = IDELEMS(LL);
594 
595  assume( size == IDELEMS(TT) );
596 
597  id_Delete(&L, r); id_Delete(&T, r);
598 
599  L = LL; T = TT;
600 
601  // id_Add(T, L, r);
602  M = idInit(size, 0);
603  for( int i = size-1; i >= 0; i-- )
604  {
605  M->m[i] = p_Add_q(p_Copy(T->m[i], r), p_Copy(L->m[i], r), r); // TODO: :(((
606  }
607  M->rank = id_RankFreeModule(M, r);
608 
609  _res->fullres[index++] = M; // ???
610  }
611 // if ( UNLIKELY(attributes.OPT__TREEOUTPUT) )
612 // PrintS("] }\n");
613 
614  id_Delete(&L, r); id_Delete(&T, r);
615 
616  res->data = _res;
617  res->rtyp = RESOLUTION_CMD;
618 
619 // omFreeSize(_res, sizeof(ssyStrategy));
620 
621  return FALSE;
622 
623 }
624 
625 
626 /// module (LL, TT) = SSComputeSyzygy(L, T);
627 /// Compute Syz(L ++ T) = N = LL ++ TT
628 // proc SSComputeSyzygy(def L, def T)
630 {
632 
633 // const BOOLEAN OPT__SYZCHECK = attributes.OPT__SYZCHECK;
634 // const BOOLEAN OPT__LEAD2SYZ = attributes.OPT__LEAD2SYZ;
635 // const BOOLEAN OPT__HYBRIDNF = attributes.OPT__HYBRIDNF;
636 // const BOOLEAN OPT__TAILREDSYZ = attributes.OPT__TAILREDSYZ;
637 
638  const char* usage = "`ComputeSyzygy(<ideal/module>, <ideal/module>)` expected";
639  const ring r = attributes.m_rBaseRing;
640 
641  NoReturn(res);
642 
643  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
644  {
645  WerrorS(usage);
646  return TRUE;
647  }
648 
649  const ideal L = (ideal) h->Data();
650 
651  assume( IDELEMS(L) > 0 );
652 
653  h = h->Next();
654  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
655  {
656  WerrorS(usage);
657  return TRUE;
658  }
659 
660  const ideal T = (ideal) h->Data();
661  assume( IDELEMS(L) == IDELEMS(T) );
662 
663 
664  h = h->Next(); assume( h == NULL );
665 
666  ideal LL, TT;
667 
668  ComputeSyzygy(L, T, LL, TT, attributes);
669 
670  lists l = (lists)omAllocBin(slists_bin); l->Init(2);
671 
672  l->m[0].rtyp = MODUL_CMD; l->m[0].data = reinterpret_cast<void *>(LL);
673 
674  l->m[1].rtyp = MODUL_CMD; l->m[1].data = reinterpret_cast<void *>(TT);
675 
676  res->data = l; res->rtyp = LIST_CMD;
677 
678  return FALSE;
679 
680 }
681 
682 /// Get leading component
684 {
685  NoReturn(res);
686 
687  if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD))
688  {
689  const ring r = currRing;
690 
691  const poly p = (poly)(h->Data());
692 
693  if (p != NULL )
694  {
695  assume( p != NULL );
696  p_LmTest(p, r);
697 
698  const unsigned long iComp = p_GetComp(p, r);
699 
700  // assume( iComp > 0 ); // p is a vector
701 
702  res->data = reinterpret_cast<void *>(jjLONG2N(iComp));
703  } else
704  res->data = reinterpret_cast<void *>(jjLONG2N(0));
705 
706 
707  res->rtyp = BIGINT_CMD;
708  return FALSE;
709  }
710 
711  WerrorS("`leadcomp(<poly/vector>)` expected");
712  return TRUE;
713 }
714 
715 /// Same for Induced Schreyer ordering (ordering on components is defined by sign!)
717 {
718 
719  NoReturn(res);
720 
721  int sign = 1;
722  if ((h!=NULL) && (h->Typ()==INT_CMD))
723  {
724  const int s = (int)((long)(h->Data()));
725 
726  if( s != -1 && s != 1 )
727  {
728  WerrorS("`MakeInducedSchreyerOrdering(<int>)` called with wrong integer argument (must be +-1)!");
729  return TRUE;
730  }
731 
732  sign = s;
733  }
734 
735  assume( sign == 1 || sign == -1 );
736  res->data = reinterpret_cast<void *>(rAssure_InducedSchreyerOrdering(currRing, TRUE, sign));
737  res->rtyp = RING_CMD; // return new ring!
738  // QRING_CMD?
739  return FALSE;
740 }
741 
742 
743 /// ?
745 {
746  NoReturn(res);
747 
748  const ring r = currRing;
749 
750  int p = 0; // which IS-block? p^th!
751 
752  if ((h!=NULL) && (h->Typ()==INT_CMD))
753  {
754  p = (int)((long)(h->Data())); h=h->next;
755  assume(p >= 0);
756  }
757 
758  const int pos = rGetISPos(p, r);
759 
760  if( /*(*/ -1 == pos /*)*/ )
761  {
762  WerrorS("`GetInducedData([int])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)");
763  return TRUE;
764  }
765 
766 
767  const int iLimit = r->typ[pos].data.is.limit;
768  const ideal F = r->typ[pos].data.is.F;
769 
770  ideal FF = id_Copy(F, r);
771 
773  l->Init(2);
774 
775  l->m[0].rtyp = INT_CMD;
776  l->m[0].data = reinterpret_cast<void *>(iLimit);
777 
778 
779  // l->m[1].rtyp = MODUL_CMD;
780 
781  if( id_IsModule(FF, r) ) // ???
782  {
783  l->m[1].rtyp = MODUL_CMD;
784 
785  // Print("before: %d\n", FF->nrows);
786  // FF->nrows = id_RankFreeModule(FF, r); // ???
787  // Print("after: %d\n", FF->nrows);
788  }
789  else
790  l->m[1].rtyp = IDEAL_CMD;
791 
792  l->m[1].data = reinterpret_cast<void *>(FF);
793 
794  res->rtyp = LIST_CMD; // list of int/module
795  res->data = reinterpret_cast<void *>(l);
796 
797  return FALSE;
798 
799 }
800 
801 /// Returns old SyzCompLimit, can set new limit
803 {
804  NoReturn(res);
805 
806  const ring r = currRing;
807 
808  if( !( (h!=NULL) && ( (h->Typ()==IDEAL_CMD) || (h->Typ()==MODUL_CMD))) )
809  {
810  WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` expected");
811  return TRUE;
812  }
813 
814  const ideal F = (ideal)h->Data(); ; // No copy!
815  h=h->next;
816 
817  int rank = 0;
818 
819  if ((h!=NULL) && (h->Typ()==INT_CMD))
820  {
821  rank = (int)((long)(h->Data())); h=h->next;
822  assume(rank >= 0);
823  } else
824  rank = id_RankFreeModule(F, r); // Starting syz-comp (1st: i+1)
825 
826  int p = 0; // which IS-block? p^th!
827 
828  if ((h!=NULL) && (h->Typ()==INT_CMD))
829  {
830  p = (int)((long)(h->Data())); h=h->next;
831  assume(p >= 0);
832  }
833 
834  const int posIS = rGetISPos(p, r);
835 
836  if( /*(*/ -1 == posIS /*)*/ )
837  {
838  WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)");
839  return TRUE;
840  }
841 
842 
843 
844  // F & componentWeights belong to that ordering block of currRing now:
845  rSetISReference(r, F, rank, p); // F will be copied!
846  return FALSE;
847 }
848 
849 
850 /// Get raw syzygies (idPrepare)
852 {
853  // extern int rGetISPos(const int p, const ring r);
854 
855  const ring r = currRing;
856 
857  const bool isSyz = rIsSyzIndexRing(r);
858  const int posIS = rGetISPos(0, r);
859 
860 
861  if ( !( (h!=NULL) && (h->Typ()==MODUL_CMD) && (h->Data() != NULL) ) )
862  {
863  WerrorS("`idPrepare(<module>)` expected");
864  return TRUE;
865  }
866 
867  const ideal I = reinterpret_cast<ideal>(h->Data());
868 
869  assume( I != NULL );
870  idTest(I);
871 
872  int iComp = -1;
873 
874  h=h->next;
875  if ( (h!=NULL) && (h->Typ()==INT_CMD) )
876  {
877  iComp = (int)((long)(h->Data()));
878  }
879  else
880  {
881  if( (!isSyz) && (-1 == posIS) )
882  {
883  WerrorS("`idPrepare(<...>)` called on incompatible ring (not created by 'MakeSyzCompOrdering' or 'MakeInducedSchreyerOrdering'!)");
884  return TRUE;
885  }
886 
887  if( isSyz )
888  iComp = rGetCurrSyzLimit(r);
889  else
890  iComp = id_RankFreeModule(r->typ[posIS].data.is.F, r); // ;
891  }
892 
893  assume(iComp >= 0);
894 
895 
896  intvec* w = reinterpret_cast<intvec *>(atGet(h, "isHomog", INTVEC_CMD));
897  tHomog hom = testHomog;
898 
899  // int add_row_shift = 0;
900  //
901  if (w!=NULL)
902  {
903  w = ivCopy(w);
904  // add_row_shift = ww->min_in();
905  //
906  // (*ww) -= add_row_shift;
907  //
908  // if (idTestHomModule(I, currRing->qideal, ww))
909  // {
910  hom = isHomog;
911  // w = ww;
912  // }
913  // else
914  // {
915  // //WarnS("wrong weights");
916  // delete ww;
917  // w = NULL;
918  // hom=testHomog;
919  // }
920  }
921 
922 
923  // computes syzygies of h1,
924  // works always in a ring with ringorder_s
925  // NOTE: rSetSyzComp(syzcomp) should better be called beforehand
926  // ideal idPrepare (ideal h1, tHomog hom, int syzcomp, intvec **w);
927 
928  ideal J = // idPrepare( I, hom, iComp, &w);
929  kStd(I, currRing->qideal, hom, &w, NULL, iComp);
930 
931  idTest(J);
932 
933  if (w!=NULL)
934  atSet(res, omStrDup("isHomog"), w, INTVEC_CMD);
935  // if (w!=NULL) delete w;
936 
937  res->rtyp = MODUL_CMD;
938  res->data = reinterpret_cast<void *>(J);
939  return FALSE;
940 }
941 
942 extern "C" int SI_MOD_INIT(syzextra)(SModulFunctions* psModulFunctions)
943 {
944 
945 #define ADD(C,D,E) \
946  psModulFunctions->iiAddCproc((currPack->libname? currPack->libname: ""), (char*)C, D, E);
947 
948 
949 // #define ADD(A,B,C,D,E) ADD0(iiAddCproc, "", C, D, E)
950 
951 //#define ADD0(A,B,C,D,E) A(B, (char*)C, D, E)
952 // #define ADD(A,B,C,D,E) ADD0(A->iiAddCproc, B, C, D, E)
953  ADD("ClearContent", FALSE, _ClearContent);
954  ADD("ClearDenominators", FALSE, _ClearDenominators);
955 
956  ADD("leadcomp", FALSE, leadcomp);
957 
958  ADD("SetInducedReferrence", FALSE, SetInducedReferrence);
959  ADD("GetInducedData", FALSE, GetInducedData);
960  ADD("MakeInducedSchreyerOrdering", FALSE, MakeInducedSchreyerOrdering);
961 
962  ADD("idPrepare", FALSE, idPrepare);
963 
964  ADD("Tail", FALSE, Tail);
965 
966  ADD("ReduceTerm", FALSE, _ReduceTerm);
967  ADD("TraverseTail", FALSE, _TraverseTail);
968 
969 
970  ADD("SchreyerSyzygyNF", FALSE, _SchreyerSyzygyNF);
971  ADD("ComputeSyzygy", FALSE, _ComputeSyzygy);
972 
973  ADD("ComputeResolution", FALSE, _ComputeResolution);
974 
975  // ADD("", FALSE, );
976 
977 #undef ADD
978  return MAX_TOK;
979 }
Concrete implementation of enumerators over polynomials.
void * atGet(idhdl root, const char *name, int t, void *defaultReturnValue)
Definition: attrib.cc:131
void atSet(idhdl root, char *name, void *data, int typ)
Definition: attrib.cc:152
int BOOLEAN
Definition: auxiliary.h:85
#define LIKELY
Definition: auxiliary.h:421
#define TRUE
Definition: auxiliary.h:98
#define FALSE
Definition: auxiliary.h:94
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
int l
Definition: cfEzgcd.cc:93
int i
Definition: cfEzgcd.cc:125
int p
Definition: cfModGcd.cc:4019
This is a polynomial enumerator for simple iteration over coefficients of polynomials.
Definition: intvec.h:21
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
Definition: lists.h:23
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:949
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:539
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:942
#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:55
CanonicalForm res
Definition: facAbsFact.cc:64
const CanonicalForm & w
Definition: facAbsFact.cc:55
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
int j
Definition: facHensel.cc:105
void WerrorS(const char *s)
Definition: feFopen.cc:24
@ IDEAL_CMD
Definition: grammar.cc:283
@ MODUL_CMD
Definition: grammar.cc:286
@ VECTOR_CMD
Definition: grammar.cc:290
@ RESOLUTION_CMD
Definition: grammar.cc:289
@ NUMBER_CMD
Definition: grammar.cc:287
@ POLY_CMD
Definition: grammar.cc:288
@ RING_CMD
Definition: grammar.cc:281
ideal id_Copy(ideal h1, const ring r)
copy an ideal
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
#define idTest(id)
Definition: ideals.h:47
ideal * resolvente
Definition: ideals.h:18
static BOOLEAN length(leftv result, leftv arg)
Definition: interval.cc:267
intvec * ivCopy(const intvec *o)
Definition: intvec.h:133
coeffs coeffs_BIGINT
Definition: ipid.cc:52
idhdl currRingHdl
Definition: ipid.cc:61
static Poly * h
Definition: janet.cc:972
static jList * T
Definition: janet.cc:31
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:2096
omBin slists_bin
Definition: lists.cc:23
#define assume(x)
Definition: mod2.h:390
#define p_GetComp(p, r)
Definition: monomials.h:71
#define rRing_has_Comp(r)
Definition: monomials.h:273
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 omAlloc0(size)
Definition: omAllocDecl.h:211
#define NULL
Definition: omList.c:10
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:592
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:892
#define p_LmTest(p, r)
Definition: p_polys.h:164
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:812
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:4751
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:4887
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:4919
static int sign(int x)
Definition: ring.cc:3328
static int rGetCurrSyzLimit(const ring r)
Definition: ring.h:714
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition: ring.h:711
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:583
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:37
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
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:24
#define id_Test(A, lR)
Definition: simpleideals.h:80
#define M
Definition: sirandom.c:24
Computation attribute storage.
Definition: syzextra.h:163
const int OPT__HYBRIDNF
Use the usual NF's S-poly reduction while dropping lower order terms 2 means - smart selection!
Definition: syzextra.h:187
const ring m_rBaseRing
global base ring
Definition: syzextra.h:214
const int OPT__TAILREDSYZ
Reduce syzygy tails wrt the leading syzygy terms.
Definition: syzextra.h:183
tHomog
Definition: structs.h:38
@ isHomog
Definition: structs.h:40
@ testHomog
Definition: structs.h:41
resolvente fullres
Definition: syz.h:57
ssyStrategy * syStrategy
Definition: syz.h:35
int length
Definition: syz.h:60
static BOOLEAN GetInducedData(leftv res, leftv h)
?
Definition: mod_main.cc:744
static BOOLEAN idPrepare(leftv res, leftv h)
Get raw syzygies (idPrepare)
Definition: mod_main.cc:851
#define ADD(C, D, E)
static BOOLEAN leadcomp(leftv res, leftv h)
Get leading component.
Definition: mod_main.cc:683
static void view(const intvec *v)
Definition: mod_main.cc:199
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:55
static BOOLEAN _SchreyerSyzygyNF(leftv res, leftv h)
Definition: mod_main.cc:261
int SI_MOD_INIT() syzextra(SModulFunctions *psModulFunctions)
Definition: mod_main.cc:942
static BOOLEAN _ClearDenominators(leftv res, leftv h)
wrapper around n_ClearDenominators
Definition: mod_main.cc:131
static BOOLEAN SetInducedReferrence(leftv res, leftv h)
Returns old SyzCompLimit, can set new limit.
Definition: mod_main.cc:802
static BOOLEAN MakeInducedSchreyerOrdering(leftv res, leftv h)
Same for Induced Schreyer ordering (ordering on components is defined by sign!)
Definition: mod_main.cc:716
static BOOLEAN _ComputeResolution(leftv res, leftv h)
Definition: mod_main.cc:513
static BOOLEAN _ClearContent(leftv res, leftv h)
wrapper around n_ClearContent
Definition: mod_main.cc:85
static BOOLEAN _TraverseTail(leftv res, leftv h)
Definition: mod_main.cc:435
static void NoReturn(leftv &res)
Definition: mod_main.cc:78
static number jjLONG2N(long d)
Definition: mod_main.cc:194
static BOOLEAN _ReduceTerm(leftv res, leftv h)
proc SSReduceTerm(poly m, def t, def syzterm, def L, def T, list #)
Definition: mod_main.cc:342
static BOOLEAN Tail(leftv res, leftv h)
wrapper around p_Tail and id_Tail
Definition: mod_main.cc:222
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:179
static BOOLEAN _ComputeSyzygy(leftv res, leftv h)
module (LL, TT) = SSComputeSyzygy(L, T); Compute Syz(L ++ T) = N = LL ++ TT
Definition: mod_main.cc:629
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:316
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:325
Computation of Syzygies.
static poly SchreyerSyzygyNF(poly syz_lead, poly syz_2, ideal L, ideal T, ideal LS, const SchreyerSyzygyComputationFlags A)
Definition: syzextra.h:549
static poly ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck, ideal L, ideal T, ideal LS, const SchreyerSyzygyComputationFlags A)
Definition: syzextra.h:541
static poly TraverseTail(poly multiplier, poly tail, ideal L, ideal T, ideal LS, const SchreyerSyzygyComputationFlags A)
Definition: syzextra.h:534
static void ComputeSyzygy(const ideal L, const ideal T, ideal &LL, ideal &TT, const SchreyerSyzygyComputationFlags A)
Definition: syzextra.h:502
@ 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:215
#define NONE
Definition: tok.h:218