ipshell.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /*
5 * ABSTRACT:
6 */
7 
8 #include <kernel/mod2.h>
9 
10 #include <omalloc/omalloc.h>
11 
12 #include <factory/factory.h>
13 
14 #include <misc/auxiliary.h>
15 #include <misc/options.h>
16 #include <misc/mylimits.h>
17 #include <misc/intvec.h>
18 
19 #include <coeffs/numbers.h>
20 #include <coeffs/coeffs.h>
21 
22 #include <coeffs/rmodulon.h>
23 #include <coeffs/longrat.h>
24 
25 #include <polys/monomials/ring.h>
26 #include <polys/monomials/maps.h>
27 
28 #include <polys/prCopy.h>
29 #include <polys/matpol.h>
30 
31 #include <polys/weight.h>
32 #include <polys/clapsing.h>
33 
34 
37 
38 #include <kernel/polys.h>
39 #include <kernel/ideals.h>
40 
43 
44 #include <kernel/GBEngine/syz.h>
45 #include <kernel/GBEngine/kstd1.h>
46 #include <kernel/GBEngine/kutil.h> // denominator_list
47 
50 
51 #include <kernel/spectrum/semic.h>
52 #include <kernel/spectrum/splist.h>
54 
56 
57 #include <Singular/lists.h>
58 #include <Singular/attrib.h>
59 #include <Singular/ipconv.h>
60 #include <Singular/links/silink.h>
61 #include <Singular/ipshell.h>
62 #include <Singular/maps_ip.h>
63 #include <Singular/tok.h>
64 #include <Singular/ipid.h>
65 #include <Singular/subexpr.h>
66 #include <Singular/fevoices.h>
67 
68 #include <math.h>
69 #include <ctype.h>
70 
71 // define this if you want to use the fast_map routine for mapping ideals
72 #define FAST_MAP
73 
74 #ifdef FAST_MAP
75 #include <kernel/maps/fast_maps.h>
76 #endif
77 
78 #ifdef SINGULAR_4_1
79 #include <Singular/number2.h>
80 #include <coeffs/bigintmat.h>
81 #endif
84 const char *lastreserved=NULL;
85 
87 
88 /*0 implementation*/
89 
90 const char * iiTwoOps(int t)
91 {
92  if (t<127)
93  {
94  static char ch[2];
95  switch (t)
96  {
97  case '&':
98  return "and";
99  case '|':
100  return "or";
101  default:
102  ch[0]=t;
103  ch[1]='\0';
104  return ch;
105  }
106  }
107  switch (t)
108  {
109  case COLONCOLON: return "::";
110  case DOTDOT: return "..";
111  //case PLUSEQUAL: return "+=";
112  //case MINUSEQUAL: return "-=";
113  case MINUSMINUS: return "--";
114  case PLUSPLUS: return "++";
115  case EQUAL_EQUAL: return "==";
116  case LE: return "<=";
117  case GE: return ">=";
118  case NOTEQUAL: return "<>";
119  default: return Tok2Cmdname(t);
120  }
121 }
122 
123 int iiOpsTwoChar(const char *s)
124 {
125 /* not handling: &&, ||, ** */
126  if (s[1]=='\0') return s[0];
127  else if (s[2]!='\0') return 0;
128  switch(s[0])
129  {
130  case '.': if (s[1]=='.') return DOTDOT;
131  else return 0;
132  case ':': if (s[1]==':') return COLONCOLON;
133  else return 0;
134  case '-': if (s[1]=='-') return COLONCOLON;
135  else return 0;
136  case '+': if (s[1]=='+') return PLUSPLUS;
137  else return 0;
138  case '=': if (s[1]=='=') return EQUAL_EQUAL;
139  else return 0;
140  case '<': if (s[1]=='=') return LE;
141  else if (s[1]=='>') return NOTEQUAL;
142  else return 0;
143  case '>': if (s[1]=='=') return GE;
144  else return 0;
145  case '!': if (s[1]=='=') return NOTEQUAL;
146  else return 0;
147  }
148  return 0;
149 }
150 
151 static void list1(const char* s, idhdl h,BOOLEAN c, BOOLEAN fullname)
152 {
153  char buffer[22];
154  int l;
155  char buf2[128];
156 
157  if(fullname) sprintf(buf2, "%s::%s", "", IDID(h));
158  else sprintf(buf2, "%s", IDID(h));
159 
160  Print("%s%-30.30s [%d] ",s,buf2,IDLEV(h));
161  if (h == currRingHdl) PrintS("*");
162  PrintS(Tok2Cmdname((int)IDTYP(h)));
163 
164  ipListFlag(h);
165  switch(IDTYP(h))
166  {
167  case INT_CMD: Print(" %d",IDINT(h)); break;
168  case INTVEC_CMD:Print(" (%d)",IDINTVEC(h)->length()); break;
169  case INTMAT_CMD:Print(" %d x %d",IDINTVEC(h)->rows(),IDINTVEC(h)->cols());
170  break;
171  case POLY_CMD:
172  case VECTOR_CMD:if (c)
173  {
174  PrintS(" ");wrp(IDPOLY(h));
175  if(IDPOLY(h) != NULL)
176  {
177  Print(", %d monomial(s)",pLength(IDPOLY(h)));
178  }
179  }
180  break;
181  case MODUL_CMD: Print(", rk %d", (int)(IDIDEAL(h)->rank));
182  case IDEAL_CMD: Print(", %u generator(s)",
183  IDELEMS(IDIDEAL(h))); break;
184  case MAP_CMD:
185  Print(" from %s",IDMAP(h)->preimage); break;
186  case MATRIX_CMD:Print(" %u x %u"
187  ,MATROWS(IDMATRIX(h))
188  ,MATCOLS(IDMATRIX(h))
189  );
190  break;
191  case PACKAGE_CMD:
192  paPrint(IDID(h),IDPACKAGE(h));
193  break;
194  case PROC_CMD: if((IDPROC(h)->libname!=NULL)
195  && (strlen(IDPROC(h)->libname)>0))
196  Print(" from %s",IDPROC(h)->libname);
197  if(IDPROC(h)->is_static)
198  PrintS(" (static)");
199  break;
200  case STRING_CMD:
201  {
202  char *s;
203  l=strlen(IDSTRING(h));
204  memset(buffer,0,22);
205  strncpy(buffer,IDSTRING(h),si_min(l,20));
206  if ((s=strchr(buffer,'\n'))!=NULL)
207  {
208  *s='\0';
209  }
210  PrintS(" ");
211  PrintS(buffer);
212  if((s!=NULL) ||(l>20))
213  {
214  Print("..., %d char(s)",l);
215  }
216  break;
217  }
218  case LIST_CMD: Print(", size: %d",IDLIST(h)->nr+1);
219  break;
220  case QRING_CMD:
221  case RING_CMD:
222  if ((IDRING(h)==currRing) && (currRingHdl!=h))
223  PrintS("(*)"); /* this is an alias to currRing */
224 #ifdef RDEBUG
226  Print(" <%lx>",(long)(IDRING(h)));
227 #endif
228  break;
229 #ifdef SINGULAR_4_1
230  case CNUMBER_CMD:
231  { number2 n=(number2)IDDATA(h);
232  Print(" (%s)",nCoeffName(n->cf));
233  break;
234  }
235  case CMATRIX_CMD:
236  { bigintmat *b=(bigintmat*)IDDATA(h);
237  Print(" %d x %d (%s)",
238  b->rows(),b->cols(),
239  nCoeffName(b->basecoeffs()));
240  break;
241  }
242 #endif
243  /*default: break;*/
244  }
245  PrintLn();
246 }
247 
249 {
250  BOOLEAN oldShortOut = FALSE;
251 
252  if (currRing != NULL)
253  {
254  oldShortOut = currRing->ShortOut;
255  currRing->ShortOut = 1;
256  }
257  int t=v->Typ();
258  Print("// %s %s ",v->Name(),Tok2Cmdname(t));
259  switch (t)
260  {
261  case MAP_CMD:Print(" from %s\n",((map)(v->Data()))->preimage); break;
262  case INTMAT_CMD: Print(" %d x %d\n",((intvec*)(v->Data()))->rows(),
263  ((intvec*)(v->Data()))->cols()); break;
264  case MATRIX_CMD:Print(" %u x %u\n" ,
265  MATROWS((matrix)(v->Data())),
266  MATCOLS((matrix)(v->Data())));break;
267  case MODUL_CMD: Print(", rk %d\n", (int)(((ideal)(v->Data()))->rank));break;
268  case LIST_CMD: Print(", size %d\n",((lists)(v->Data()))->nr+1); break;
269 
270  case PROC_CMD:
271  case RING_CMD:
272  case IDEAL_CMD:
273  case QRING_CMD: PrintLn(); break;
274 
275  //case INT_CMD:
276  //case STRING_CMD:
277  //case INTVEC_CMD:
278  //case POLY_CMD:
279  //case VECTOR_CMD:
280  //case PACKAGE_CMD:
281 
282  default:
283  break;
284  }
285  v->Print();
286  if (currRing != NULL)
287  currRing->ShortOut = oldShortOut;
288 }
289 
290 static void killlocals0(int v, idhdl * localhdl, const ring r)
291 {
292  idhdl h = *localhdl;
293  while (h!=NULL)
294  {
295  int vv;
296  //Print("consider %s, lev: %d:",IDID(h),IDLEV(h));
297  if ((vv=IDLEV(h))>0)
298  {
299  if (vv < v)
300  {
301  if (iiNoKeepRing)
302  {
303  //PrintS(" break\n");
304  return;
305  }
306  h = IDNEXT(h);
307  //PrintLn();
308  }
309  else //if (vv >= v)
310  {
311  idhdl nexth = IDNEXT(h);
312  killhdl2(h,localhdl,r);
313  h = nexth;
314  //PrintS("kill\n");
315  }
316  }
317  else
318  {
319  h = IDNEXT(h);
320  //PrintLn();
321  }
322  }
323 }
324 
325 void killlocals_rec(idhdl *root,int v, ring r)
326 {
327  idhdl h=*root;
328  while (h!=NULL)
329  {
330  if (IDLEV(h)>=v)
331  {
332 // Print("kill %s, lev %d for lev %d\n",IDID(h),IDLEV(h),v);
333  idhdl n=IDNEXT(h);
334  killhdl2(h,root,r);
335  h=n;
336  }
337  else if (IDTYP(h)==PACKAGE_CMD)
338  {
339  // Print("into pack %s, lev %d for lev %d\n",IDID(h),IDLEV(h),v);
340  if (IDPACKAGE(h)!=basePack)
341  killlocals_rec(&(IDRING(h)->idroot),v,r);
342  h=IDNEXT(h);
343  }
344  else if ((IDTYP(h)==RING_CMD)
345  ||(IDTYP(h)==QRING_CMD))
346  {
347  if ((IDRING(h)!=NULL) && (IDRING(h)->idroot!=NULL))
348  // we have to test IDRING(h)!=NULL: qring Q=groebner(...): killlocals
349  {
350  // Print("into ring %s, lev %d for lev %d\n",IDID(h),IDLEV(h),v);
351  killlocals_rec(&(IDRING(h)->idroot),v,IDRING(h));
352  }
353  h=IDNEXT(h);
354  }
355  else
356  {
357 // Print("skip %s lev %d for lev %d\n",IDID(h),IDLEV(h),v);
358  h=IDNEXT(h);
359  }
360  }
361 }
363 {
364  if (L==NULL) return FALSE;
365  BOOLEAN changed=FALSE;
366  int n=L->nr;
367  for(;n>=0;n--)
368  {
369  leftv h=&(L->m[n]);
370  void *d=h->data;
371  if (((h->rtyp==RING_CMD) || (h->rtyp==QRING_CMD))
372  && (((ring)d)->idroot!=NULL))
373  {
374  if (d!=currRing) {changed=TRUE;rChangeCurrRing((ring)d);}
375  killlocals0(v,&(((ring)h->data)->idroot),(ring)h->data);
376  }
377  else if (h->rtyp==LIST_CMD)
378  changed|=killlocals_list(v,(lists)d);
379  }
380  return changed;
381 }
382 void killlocals(int v)
383 {
384  BOOLEAN changed=FALSE;
385  idhdl sh=currRingHdl;
386  ring cr=currRing;
387  if (sh!=NULL) changed=((IDLEV(sh)<v) || (IDRING(sh)->ref>0));
388  //if (changed) Print("currRing=%s(%x), lev=%d,ref=%d\n",IDID(sh),IDRING(sh),IDLEV(sh),IDRING(sh)->ref);
389 
390  killlocals_rec(&(basePack->idroot),v,currRing);
391 
393  {
394  int t=iiRETURNEXPR.Typ();
395  if ((/*iiRETURNEXPR.Typ()*/ t==RING_CMD)
396  || (/*iiRETURNEXPR.Typ()*/ t==QRING_CMD))
397  {
399  if (((ring)h->data)->idroot!=NULL)
400  killlocals0(v,&(((ring)h->data)->idroot),(ring)h->data);
401  }
402  else if (/*iiRETURNEXPR.Typ()*/ t==LIST_CMD)
403  {
405  changed |=killlocals_list(v,(lists)h->data);
406  }
407  }
408  if (changed)
409  {
411  if (currRingHdl==NULL)
412  currRing=NULL;
413  else if(cr!=currRing)
414  rChangeCurrRing(cr);
415  }
416 
417  if (myynest<=1) iiNoKeepRing=TRUE;
418  //Print("end killlocals >= %d\n",v);
419  //listall();
420 }
421 
422 void list_cmd(int typ, const char* what, const char *prefix,BOOLEAN iterate, BOOLEAN fullname)
423 {
424  package savePack=currPack;
425  idhdl h,start;
426  BOOLEAN all = typ<0;
427  BOOLEAN really_all=FALSE;
428 
429  if ( typ==0 )
430  {
431  if (strcmp(what,"all")==0)
432  {
433  if (currPack!=basePack)
434  list_cmd(-1,NULL,prefix,iterate,fullname); // list current package
435  really_all=TRUE;
436  h=basePack->idroot;
437  }
438  else
439  {
440  h = ggetid(what);
441  if (h!=NULL)
442  {
443  if (iterate) list1(prefix,h,TRUE,fullname);
444  if (IDTYP(h)==ALIAS_CMD) PrintS("A");
445  if ((IDTYP(h)==RING_CMD)
446  || (IDTYP(h)==QRING_CMD)
447  //|| (IDTYP(h)==PACKE_CMD)
448  )
449  {
450  h=IDRING(h)->idroot;
451  }
452  else if(IDTYP(h)==PACKAGE_CMD)
453  {
454  currPack=IDPACKAGE(h);
455  //Print("list_cmd:package\n");
456  all=TRUE;typ=PROC_CMD;fullname=TRUE;really_all=TRUE;
457  h=IDPACKAGE(h)->idroot;
458  }
459  else
460  {
461  currPack=savePack;
462  return;
463  }
464  }
465  else
466  {
467  Werror("%s is undefined",what);
468  currPack=savePack;
469  return;
470  }
471  }
472  all=TRUE;
473  }
474  else if (RingDependend(typ))
475  {
476  h = currRing->idroot;
477  }
478  else
479  h = IDROOT;
480  start=h;
481  while (h!=NULL)
482  {
483  if ((all
484  && (IDTYP(h)!=PROC_CMD)
485  &&(IDTYP(h)!=PACKAGE_CMD)
486  && (IDTYP(h)!=CRING_CMD))
487  || (typ == IDTYP(h))
488  || ((typ==RING_CMD) &&(IDTYP(h)==CRING_CMD))
489  || ((IDTYP(h)==QRING_CMD) && (typ==RING_CMD)))
490  {
491  list1(prefix,h,start==currRingHdl, fullname);
492  if (((IDTYP(h)==RING_CMD)||(IDTYP(h)==QRING_CMD))
493  && (really_all || (all && (h==currRingHdl)))
494  && ((IDLEV(h)==0)||(IDLEV(h)==myynest)))
495  {
496  list_cmd(0,IDID(h),"// ",FALSE);
497  }
498  if (IDTYP(h)==PACKAGE_CMD && really_all)
499  {
500  package save_p=currPack;
501  currPack=IDPACKAGE(h);
502  list_cmd(0,IDID(h),"// ",FALSE);
503  currPack=save_p;
504  }
505  }
506  h = IDNEXT(h);
507  }
508  currPack=savePack;
509 }
510 
511 void test_cmd(int i)
512 {
513  int ii;
514 
515  if (i<0)
516  {
517  ii= -i;
518  if (ii < 32)
519  {
520  si_opt_1 &= ~Sy_bit(ii);
521  }
522  else if (ii < 64)
523  {
524  si_opt_2 &= ~Sy_bit(ii-32);
525  }
526  else
527  WerrorS("out of bounds\n");
528  }
529  else if (i<32)
530  {
531  ii=i;
532  if (Sy_bit(ii) & kOptions)
533  {
534  Warn("Gerhard, use the option command");
535  si_opt_1 |= Sy_bit(ii);
536  }
537  else if (Sy_bit(ii) & validOpts)
538  si_opt_1 |= Sy_bit(ii);
539  }
540  else if (i<64)
541  {
542  ii=i-32;
543  si_opt_2 |= Sy_bit(ii);
544  }
545  else
546  WerrorS("out of bounds\n");
547 }
548 
550 {
551  int rc = 0;
552  while (v!=NULL)
553  {
554  switch (v->Typ())
555  {
556  case INT_CMD:
557  case POLY_CMD:
558  case VECTOR_CMD:
559  case NUMBER_CMD:
560  rc++;
561  break;
562  case INTVEC_CMD:
563  case INTMAT_CMD:
564  rc += ((intvec *)(v->Data()))->length();
565  break;
566  case MATRIX_CMD:
567  case IDEAL_CMD:
568  case MODUL_CMD:
569  {
570  matrix mm = (matrix)(v->Data());
571  rc += mm->rows() * mm->cols();
572  }
573  break;
574  case LIST_CMD:
575  rc+=((lists)v->Data())->nr+1;
576  break;
577  default:
578  rc++;
579  }
580  v = v->next;
581  }
582  return rc;
583 }
584 
585 int iiIsPrime0(unsigned p) /* brute force !!!! */
586 {
587  unsigned i,j=0 /*only to avoid compiler warnings*/;
588  if (p<=32749) // max. small prime in factory
589  {
590  int a=0;
591  int e=cf_getNumSmallPrimes()-1;
592  i=e/2;
593  do
594  {
595  j=cf_getSmallPrime(i);
596  if (p==j) return p;
597  if (p<j) e=i-1;
598  else a=i+1;
599  i=a+(e-a)/2;
600  } while ( a<= e);
601  if (p>j) return j;
602  else return cf_getSmallPrime(i-1);
603  }
604  unsigned end_i=cf_getNumSmallPrimes()-1;
605  unsigned end_p=(unsigned)sqrt((double)p);
606 restart:
607  for (i=0; i<end_i; i++)
608  {
609  j=cf_getSmallPrime(i);
610  if ((p%j) == 0)
611  {
612  if (p<=32751) return iiIsPrime0(p-2);
613  p-=2;
614  goto restart;
615  }
616  if (j > end_p) return p;
617  }
618  if (i>=end_i)
619  {
620  while(j<=end_p)
621  {
622  j+=2;
623  if ((p%j) == 0)
624  {
625  if (p<=32751) return iiIsPrime0(p-2);
626  p-=2;
627  goto restart;
628  }
629  }
630  }
631  return p;
632 }
633 int IsPrime(int p) /* brute force !!!! */
634 {
635  if (p == 0) return 0;
636  else if (p == 1) return 1/*1*/;
637  else if ((p == 2)||(p==3)) return p;
638  else if (p < 0) return 2; //(iiIsPrime0((unsigned)(-p)));
639  else if ((p & 1)==0) return iiIsPrime0((unsigned)(p-1));
640  return iiIsPrime0((unsigned)(p));
641 }
642 
644 {
645  sleftv vf;
646  if (iiConvert(v->Typ(),LINK_CMD,iiTestConvert(v->Typ(),LINK_CMD),v,&vf))
647  {
648  WerrorS("link expected");
649  return TRUE;
650  }
651  si_link l=(si_link)vf.Data();
652  if (vf.next == NULL)
653  {
654  WerrorS("write: need at least two arguments");
655  return TRUE;
656  }
657 
658  BOOLEAN b=slWrite(l,vf.next); /* iiConvert preserves next */
659  if (b)
660  {
661  const char *s;
662  if ((l!=NULL)&&(l->name!=NULL)) s=l->name;
663  else s=sNoName;
664  Werror("cannot write to %s",s);
665  }
666  vf.CleanUp();
667  return b;
668 }
669 
670 leftv iiMap(map theMap, const char * what)
671 {
672  idhdl w,r;
673  leftv v;
674  int i;
675  nMapFunc nMap;
676 
677  r=IDROOT->get(theMap->preimage,myynest);
678  if ((currPack!=basePack)
679  &&((r==NULL) || ((r->typ != RING_CMD) && (r->typ != QRING_CMD))))
680  r=basePack->idroot->get(theMap->preimage,myynest);
681  if ((r==NULL) && (currRingHdl!=NULL)
682  && (strcmp(theMap->preimage,IDID(currRingHdl))==0))
683  {
684  r=currRingHdl;
685  }
686  if ((r!=NULL) && ((r->typ == RING_CMD) || (r->typ== QRING_CMD)))
687  {
688  ring src_ring=IDRING(r);
689  if ((nMap=n_SetMap(src_ring->cf, currRing->cf))==NULL)
690  {
691  Werror("can not map from ground field of %s to current ground field",
692  theMap->preimage);
693  return NULL;
694  }
695  if (IDELEMS(theMap)<src_ring->N)
696  {
697  theMap->m=(polyset)omReallocSize((ADDRESS)theMap->m,
698  IDELEMS(theMap)*sizeof(poly),
699  (src_ring->N)*sizeof(poly));
700  for(i=IDELEMS(theMap);i<src_ring->N;i++)
701  theMap->m[i]=NULL;
702  IDELEMS(theMap)=src_ring->N;
703  }
704  if (what==NULL)
705  {
706  WerrorS("argument of a map must have a name");
707  }
708  else if ((w=src_ring->idroot->get(what,myynest))!=NULL)
709  {
710  char *save_r=NULL;
712  sleftv tmpW;
713  memset(&tmpW,0,sizeof(sleftv));
714  tmpW.rtyp=IDTYP(w);
715  if (tmpW.rtyp==MAP_CMD)
716  {
717  tmpW.rtyp=IDEAL_CMD;
718  save_r=IDMAP(w)->preimage;
719  IDMAP(w)->preimage=0;
720  }
721  tmpW.data=IDDATA(w);
722  // check overflow
723  BOOLEAN overflow=FALSE;
724  if ((tmpW.rtyp==IDEAL_CMD)
725  || (tmpW.rtyp==MODUL_CMD)
726  || (tmpW.rtyp==MAP_CMD))
727  {
728  ideal id=(ideal)tmpW.data;
729  for(int j=IDELEMS(theMap)-1;j>=0 && !overflow;j--)
730  {
731  if (theMap->m[j]!=NULL)
732  {
733  long deg_monexp=pTotaldegree(theMap->m[j]);
734  for(int i=IDELEMS(id)-1;i>=0;i--)
735  {
736  poly p=id->m[i];
737  if ((p!=NULL) && (p_Totaldegree(p,src_ring)!=0) &&
738  ((unsigned long)deg_monexp > (currRing->bitmask / (unsigned long)p_Totaldegree(p,src_ring)/2)))
739  {
740  overflow=TRUE;
741  break;
742  }
743  }
744  }
745  }
746  }
747  else if (tmpW.rtyp==POLY_CMD)
748  {
749  for(int j=IDELEMS(theMap)-1;j>=0 && !overflow;j--)
750  {
751  if (theMap->m[j]!=NULL)
752  {
753  long deg_monexp=pTotaldegree(theMap->m[j]);
754  poly p=(poly)tmpW.data;
755  if ((p!=NULL) && (p_Totaldegree(p,src_ring)!=0) &&
756  ((unsigned long)deg_monexp > (currRing->bitmask / (unsigned long)p_Totaldegree(p,src_ring)/2)))
757  {
758  overflow=TRUE;
759  break;
760  }
761  }
762  }
763  }
764  if (overflow)
765  Warn("possible OVERFLOW in map, max exponent is %ld",currRing->bitmask/2);
766 #if 0
767  if (((tmpW.rtyp==IDEAL_CMD)||(tmpW.rtyp==MODUL_CMD)) && idIs0(IDIDEAL(w)))
768  {
769  v->rtyp=tmpW.rtyp;
770  v->data=idInit(IDELEMS(IDIDEAL(w)),IDIDEAL(w)->rank);
771  }
772  else
773 #endif
774  {
775 #ifdef FAST_MAP
776  if ((tmpW.rtyp==IDEAL_CMD) && (nMap == ndCopyMap)
777 #ifdef HAVE_PLURAL
778  && (!rIsPluralRing(currRing))
779 #endif
780  )
781  {
782  v->rtyp=IDEAL_CMD;
783  v->data=fast_map(IDIDEAL(w), src_ring, (ideal)theMap, currRing);
784  }
785  else
786 #endif
787  if (maApplyFetch(MAP_CMD,theMap,v,&tmpW,src_ring,NULL,NULL,0,nMap))
788  {
789  Werror("cannot map %s(%d)",Tok2Cmdname(w->typ),w->typ);
791  if (save_r!=NULL) IDMAP(w)->preimage=save_r;
792  return NULL;
793  }
794  }
795  if (save_r!=NULL)
796  {
797  IDMAP(w)->preimage=save_r;
798  IDMAP((idhdl)v)->preimage=omStrDup(save_r);
799  v->rtyp=MAP_CMD;
800  }
801  return v;
802  }
803  else
804  {
805  Werror("%s undefined in %s",what,theMap->preimage);
806  }
807  }
808  else
809  {
810  Werror("cannot find preimage %s",theMap->preimage);
811  }
812  return NULL;
813 }
814 
815 #ifdef OLD_RES
816 void iiMakeResolv(resolvente r, int length, int rlen, char * name, int typ0,
817  intvec ** weights)
818 {
819  lists L=liMakeResolv(r,length,rlen,typ0,weights);
820  int i=0;
821  idhdl h;
822  char * s=(char *)omAlloc(strlen(name)+5);
823 
824  while (i<=L->nr)
825  {
826  sprintf(s,"%s(%d)",name,i+1);
827  if (i==0)
828  h=enterid(s,myynest,typ0,&(currRing->idroot), FALSE);
829  else
830  h=enterid(s,myynest,MODUL_CMD,&(currRing->idroot), FALSE);
831  if (h!=NULL)
832  {
833  h->data.uideal=(ideal)L->m[i].data;
834  h->attribute=L->m[i].attribute;
836  Print("//defining: %s as %d-th syzygy module\n",s,i+1);
837  }
838  else
839  {
840  idDelete((ideal *)&(L->m[i].data));
841  Warn("cannot define %s",s);
842  }
843  //L->m[i].data=NULL;
844  //L->m[i].rtyp=0;
845  //L->m[i].attribute=NULL;
846  i++;
847  }
848  omFreeSize((ADDRESS)L->m,(L->nr+1)*sizeof(sleftv));
850  omFreeSize((ADDRESS)s,strlen(name)+5);
851 }
852 #endif
853 
854 //resolvente iiFindRes(char * name, int * len, int *typ0)
855 //{
856 // char *s=(char *)omAlloc(strlen(name)+5);
857 // int i=-1;
858 // resolvente r;
859 // idhdl h;
860 //
861 // do
862 // {
863 // i++;
864 // sprintf(s,"%s(%d)",name,i+1);
865 // h=currRing->idroot->get(s,myynest);
866 // } while (h!=NULL);
867 // *len=i-1;
868 // if (*len<=0)
869 // {
870 // Werror("no objects %s(1),.. found",name);
871 // omFreeSize((ADDRESS)s,strlen(name)+5);
872 // return NULL;
873 // }
874 // r=(ideal *)omAlloc(/*(len+1)*/ i*sizeof(ideal));
875 // memset(r,0,(*len)*sizeof(ideal));
876 // i=-1;
877 // *typ0=MODUL_CMD;
878 // while (i<(*len))
879 // {
880 // i++;
881 // sprintf(s,"%s(%d)",name,i+1);
882 // h=currRing->idroot->get(s,myynest);
883 // if (h->typ != MODUL_CMD)
884 // {
885 // if ((i!=0) || (h->typ!=IDEAL_CMD))
886 // {
887 // Werror("%s is not of type module",s);
888 // omFreeSize((ADDRESS)r,(*len)*sizeof(ideal));
889 // omFreeSize((ADDRESS)s,strlen(name)+5);
890 // return NULL;
891 // }
892 // *typ0=IDEAL_CMD;
893 // }
894 // if ((i>0) && (idIs0(r[i-1])))
895 // {
896 // *len=i-1;
897 // break;
898 // }
899 // r[i]=IDIDEAL(h);
900 // }
901 // omFreeSize((ADDRESS)s,strlen(name)+5);
902 // return r;
903 //}
904 
906 {
907  int i;
908  resolvente res=(ideal *)omAlloc0((l+1)*sizeof(ideal));
909 
910  for (i=0; i<l; i++)
911  res[i]=idCopy(r[i]);
912  return res;
913 }
914 
916 {
917  int len=0;
918  int typ0;
919  lists L=(lists)v->Data();
920  intvec *weights=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
921  int add_row_shift = 0;
922  if (weights==NULL)
923  weights=(intvec*)atGet(&(L->m[0]),"isHomog",INTVEC_CMD);
924  if (weights!=NULL) add_row_shift=weights->min_in();
925  resolvente rr=liFindRes(L,&len,&typ0);
926  if (rr==NULL) return TRUE;
927  resolvente r=iiCopyRes(rr,len);
928 
929  syMinimizeResolvente(r,len,0);
930  omFreeSize((ADDRESS)rr,len*sizeof(ideal));
931  len++;
932  res->data=(char *)liMakeResolv(r,len,-1,typ0,NULL,add_row_shift);
933  return FALSE;
934 }
935 
937 {
938  sleftv tmp;
939  memset(&tmp,0,sizeof(tmp));
940  tmp.rtyp=INT_CMD;
941  tmp.data=(void *)1;
942  if ((u->Typ()==IDEAL_CMD)
943  || (u->Typ()==MODUL_CMD))
944  return jjBETTI2_ID(res,u,&tmp);
945  else
946  return jjBETTI2(res,u,&tmp);
947 }
948 
950 {
952  l->Init(1);
953  l->m[0].rtyp=u->Typ();
954  l->m[0].data=u->Data();
955  attr *a=u->Attribute();
956  if (a!=NULL)
957  l->m[0].attribute=*a;
958  sleftv tmp2;
959  memset(&tmp2,0,sizeof(tmp2));
960  tmp2.rtyp=LIST_CMD;
961  tmp2.data=(void *)l;
962  BOOLEAN r=jjBETTI2(res,&tmp2,v);
963  l->m[0].data=NULL;
964  l->m[0].attribute=NULL;
965  l->m[0].rtyp=DEF_CMD;
966  l->Clean();
967  return r;
968 }
969 
971 {
972  resolvente r;
973  int len;
974  int reg,typ0;
975  lists l=(lists)u->Data();
976 
977  intvec *weights=NULL;
978  int add_row_shift=0;
979  intvec *ww=(intvec *)atGet(&(l->m[0]),"isHomog",INTVEC_CMD);
980  if (ww!=NULL)
981  {
982  weights=ivCopy(ww);
983  add_row_shift = ww->min_in();
984  (*weights) -= add_row_shift;
985  }
986  //Print("attr:%x\n",weights);
987 
988  r=liFindRes(l,&len,&typ0);
989  if (r==NULL) return TRUE;
990  res->data=(char *)syBetti(r,len,&reg,weights,(int)(long)v->Data());
991  omFreeSize((ADDRESS)r,(len)*sizeof(ideal));
992  atSet(res,omStrDup("rowShift"),(void*)(long)add_row_shift,INT_CMD);
993  if (weights!=NULL) delete weights;
994  return FALSE;
995 }
996 
998 {
999  int len,reg,typ0;
1000 
1001  resolvente r=liFindRes(L,&len,&typ0);
1002 
1003  if (r==NULL)
1004  return -2;
1005  intvec *weights=NULL;
1006  int add_row_shift=0;
1007  intvec *ww=(intvec *)atGet(&(L->m[0]),"isHomog",INTVEC_CMD);
1008  if (ww!=NULL)
1009  {
1010  weights=ivCopy(ww);
1011  add_row_shift = ww->min_in();
1012  (*weights) -= add_row_shift;
1013  }
1014  //Print("attr:%x\n",weights);
1015 
1016  intvec *dummy=syBetti(r,len,&reg,weights);
1017  if (weights!=NULL) delete weights;
1018  delete dummy;
1019  omFreeSize((ADDRESS)r,len*sizeof(ideal));
1020  return reg+1+add_row_shift;
1021 }
1022 
1024 #define BREAK_LINE_LENGTH 80
1025 void iiDebug()
1026 {
1027  Print("\n-- break point in %s --\n",VoiceName());
1028  if (iiDebugMarker) VoiceBackTrack();
1029  char * s;
1030  iiDebugMarker=FALSE;
1031  s = (char *)omAlloc(BREAK_LINE_LENGTH+4);
1032  loop
1033  {
1034  memset(s,0,80);
1036  if (s[BREAK_LINE_LENGTH-1]!='\0')
1037  {
1038  Print("line too long, max is %d chars\n",BREAK_LINE_LENGTH);
1039  }
1040  else
1041  break;
1042  }
1043  if (*s=='\n')
1044  {
1045  iiDebugMarker=TRUE;
1046  }
1047 #if MDEBUG
1048  else if(strncmp(s,"cont;",5)==0)
1049  {
1050  iiDebugMarker=TRUE;
1051  }
1052 #endif /* MDEBUG */
1053  else
1054  {
1055  strcat( s, "\n;~\n");
1056  newBuffer(s,BT_execute);
1057  }
1058 }
1059 
1061 {
1062  int i;
1063  indset save;
1065 
1066  hexist = hInit(S, Q, &hNexist, currRing);
1067  if (hNexist == 0)
1068  {
1069  intvec *iv=new intvec(rVar(currRing));
1070  for(i=0; i<rVar(currRing); i++) (*iv)[i]=1;
1071  res->Init(1);
1072  res->m[0].rtyp=INTVEC_CMD;
1073  res->m[0].data=(intvec*)iv;
1074  return res;
1075  }
1076  else if (hisModule!=0)
1077  {
1078  res->Init(0);
1079  return res;
1080  }
1081  save = ISet = (indset)omAlloc0Bin(indlist_bin);
1082  hMu = 0;
1083  hwork = (scfmon)omAlloc(hNexist * sizeof(scmon));
1084  hvar = (varset)omAlloc((rVar(currRing) + 1) * sizeof(int));
1085  hpure = (scmon)omAlloc((1 + (rVar(currRing) * rVar(currRing))) * sizeof(long));
1086  hrad = hexist;
1087  hNrad = hNexist;
1088  radmem = hCreate(rVar(currRing) - 1);
1089  hCo = rVar(currRing) + 1;
1090  hNvar = rVar(currRing);
1091  hRadical(hrad, &hNrad, hNvar);
1092  hSupp(hrad, hNrad, hvar, &hNvar);
1093  if (hNvar)
1094  {
1095  hCo = hNvar;
1096  memset(hpure, 0, (rVar(currRing) + 1) * sizeof(long));
1097  hPure(hrad, 0, &hNrad, hvar, hNvar, hpure, &hNpure);
1098  hLexR(hrad, hNrad, hvar, hNvar);
1100  }
1101  if (hCo && (hCo < rVar(currRing)))
1102  {
1104  }
1105  if (hMu!=0)
1106  {
1107  ISet = save;
1108  hMu2 = 0;
1109  if (all && (hCo+1 < rVar(currRing)))
1110  {
1113  i=hMu+hMu2;
1114  res->Init(i);
1115  if (hMu2 == 0)
1116  {
1118  }
1119  }
1120  else
1121  {
1122  res->Init(hMu);
1123  }
1124  for (i=0;i<hMu;i++)
1125  {
1126  res->m[i].data = (void *)save->set;
1127  res->m[i].rtyp = INTVEC_CMD;
1128  ISet = save;
1129  save = save->nx;
1131  }
1132  omFreeBin((ADDRESS)save, indlist_bin);
1133  if (hMu2 != 0)
1134  {
1135  save = JSet;
1136  for (i=hMu;i<hMu+hMu2;i++)
1137  {
1138  res->m[i].data = (void *)save->set;
1139  res->m[i].rtyp = INTVEC_CMD;
1140  JSet = save;
1141  save = save->nx;
1143  }
1144  omFreeBin((ADDRESS)save, indlist_bin);
1145  }
1146  }
1147  else
1148  {
1149  res->Init(0);
1151  }
1152  hKill(radmem, rVar(currRing) - 1);
1153  omFreeSize((ADDRESS)hpure, (1 + (rVar(currRing) * rVar(currRing))) * sizeof(long));
1154  omFreeSize((ADDRESS)hvar, (rVar(currRing) + 1) * sizeof(int));
1155  omFreeSize((ADDRESS)hwork, hNexist * sizeof(scmon));
1157  return res;
1158 }
1159 
1160 int iiDeclCommand(leftv sy, leftv name, int lev,int t, idhdl* root,BOOLEAN isring, BOOLEAN init_b)
1161 {
1162  BOOLEAN res=FALSE;
1163  const char *id = name->name;
1164 
1165  memset(sy,0,sizeof(sleftv));
1166  if ((name->name==NULL)||(isdigit(name->name[0])))
1167  {
1168  WerrorS("object to declare is not a name");
1169  res=TRUE;
1170  }
1171  else
1172  {
1173  if (TEST_V_ALLWARN
1174  && (name->rtyp!=0)
1175  && (name->rtyp!=IDHDL)
1176  && (currRingHdl!=NULL) && (IDLEV(currRingHdl)==myynest))
1177  {
1178  Warn("`%s` is %s in %s:%d:%s",name->name,Tok2Cmdname(name->rtyp),
1180  }
1181  {
1182  sy->data = (char *)enterid(id,lev,t,root,init_b);
1183  }
1184  if (sy->data!=NULL)
1185  {
1186  sy->rtyp=IDHDL;
1187  currid=sy->name=IDID((idhdl)sy->data);
1188  // name->name=NULL; /* used in enterid */
1189  //sy->e = NULL;
1190  if (name->next!=NULL)
1191  {
1193  res=iiDeclCommand(sy->next,name->next,lev,t,root, isring);
1194  }
1195  }
1196  else res=TRUE;
1197  }
1198  name->CleanUp();
1199  return res;
1200 }
1201 
1203 {
1204  attr at=NULL;
1205  if (iiCurrProc!=NULL)
1206  at=iiCurrProc->attribute->get("default_arg");
1207  if (at==NULL)
1208  return FALSE;
1209  sleftv tmp;
1210  memset(&tmp,0,sizeof(sleftv));
1211  tmp.rtyp=at->atyp;
1212  tmp.data=at->CopyA();
1213  return iiAssign(p,&tmp);
1214 }
1216 {
1217  // <string1...stringN>,<proc>
1218  // known: args!=NULL, l>=1
1219  int l=args->listLength();
1220  int ll=0;
1221  if (iiCurrArgs!=NULL) ll=iiCurrArgs->listLength();
1222  if (ll!=(l-1)) return FALSE;
1223  leftv h=args;
1224  short *t=(short*)omAlloc(l*sizeof(short));
1225  t[0]=l-1;
1226  int b;
1227  int i;
1228  for(i=1;i<l;i++,h=h->next)
1229  {
1230  if (h->Typ()!=STRING_CMD)
1231  {
1232  omFree(t);
1233  Werror("arg %d is not a string",i);
1234  return TRUE;
1235  }
1236  int tt;
1237  b=IsCmd((char *)h->Data(),tt);
1238  if(b) t[i]=tt;
1239  else
1240  {
1241  omFree(t);
1242  Werror("arg %d is not a type name",i);
1243  return TRUE;
1244  }
1245  }
1246  if (h->Typ()!=PROC_CMD)
1247  {
1248  omFree(t);
1249  Werror("last arg (%d) is not a proc",i);
1250  return TRUE;
1251  }
1252  b=iiCheckTypes(iiCurrArgs,t,0);
1253  omFree(t);
1254  if (b && (h->rtyp==IDHDL) && (h->e==NULL))
1255  {
1256  BOOLEAN err;
1257  //Print("branchTo: %s\n",h->Name());
1258  iiCurrProc=(idhdl)h->data;
1259  procinfo * pi=IDPROC(iiCurrProc);
1260  if( pi->data.s.body==NULL )
1261  {
1263  if (pi->data.s.body==NULL) return TRUE;
1264  }
1265  if ((pi->pack!=NULL)&&(currPack!=pi->pack))
1266  {
1267  currPack=pi->pack;
1270  //Print("set pack=%s\n",IDID(currPackHdl));
1271  }
1272  err=iiAllStart(pi,pi->data.s.body,BT_proc,pi->data.s.body_lineno-(iiCurrArgs==NULL));
1274  if (iiCurrArgs!=NULL)
1275  {
1276  if (!err) Warn("too many arguments for %s",IDID(iiCurrProc));
1277  iiCurrArgs->CleanUp();
1278  omFreeBin((ADDRESS)iiCurrArgs, sleftv_bin);
1279  iiCurrArgs=NULL;
1280  }
1281  return 2-err;
1282  }
1283  return FALSE;
1284 }
1286 {
1287  if (iiCurrArgs==NULL)
1288  {
1289  if (strcmp(p->name,"#")==0)
1290  return iiDefaultParameter(p);
1291  Werror("not enough arguments for proc %s",VoiceName());
1292  p->CleanUp();
1293  return TRUE;
1294  }
1295  leftv h=iiCurrArgs;
1296  leftv rest=h->next; /*iiCurrArgs is not NULL here*/
1297  BOOLEAN is_default_list=FALSE;
1298  if (strcmp(p->name,"#")==0)
1299  {
1300  is_default_list=TRUE;
1301  rest=NULL;
1302  }
1303  else
1304  {
1305  h->next=NULL;
1306  }
1307  BOOLEAN res=iiAssign(p,h);
1308  if (is_default_list)
1309  {
1310  iiCurrArgs=NULL;
1311  }
1312  else
1313  {
1314  iiCurrArgs=rest;
1315  }
1316  h->CleanUp();
1318  return res;
1319 }
1321 {
1322  if (iiCurrArgs==NULL)
1323  {
1324  Werror("not enough arguments for proc %s",VoiceName());
1325  p->CleanUp();
1326  return TRUE;
1327  }
1328  leftv h=iiCurrArgs;
1329  iiCurrArgs=h->next;
1330  h->next=NULL;
1331  if (h->rtyp!=IDHDL)
1332  {
1333  BOOLEAN res=iiAssign(p,h);
1334  h->CleanUp();
1336  return res;
1337  }
1338  if (h->Typ()!=p->Typ())
1339  {
1340  WerrorS("type mismatch");
1341  return TRUE;
1342  }
1343  idhdl pp=(idhdl)p->data;
1344  switch(pp->typ)
1345  {
1346 #ifdef SINGULAR_4_1
1347  case CRING_CMD:
1348  nKillChar((coeffs)pp);
1349  break;
1350 #endif
1351  case INT_CMD:
1352  break;
1353  case INTVEC_CMD:
1354  case INTMAT_CMD:
1355  delete IDINTVEC(pp);
1356  break;
1357  case NUMBER_CMD:
1358  nDelete(&IDNUMBER(pp));
1359  break;
1360  case BIGINT_CMD:
1362  break;
1363  case MAP_CMD:
1364  {
1365  map im = IDMAP(pp);
1366  omFree((ADDRESS)im->preimage);
1367  }
1368  // continue as ideal:
1369  case IDEAL_CMD:
1370  case MODUL_CMD:
1371  case MATRIX_CMD:
1372  idDelete(&IDIDEAL(pp));
1373  break;
1374  case PROC_CMD:
1375  case RESOLUTION_CMD:
1376  case STRING_CMD:
1377  omFree((ADDRESS)IDSTRING(pp));
1378  break;
1379  case LIST_CMD:
1380  IDLIST(pp)->Clean();
1381  break;
1382  case LINK_CMD:
1384  break;
1385  // case ring: cannot happen
1386  default:
1387  Werror("unknown type %d",p->Typ());
1388  return TRUE;
1389  }
1390  pp->typ=ALIAS_CMD;
1391  IDDATA(pp)=(char*)h->data;
1392  h->CleanUp();
1394  return FALSE;
1395 }
1396 
1397 static BOOLEAN iiInternalExport (leftv v, int toLev)
1398 {
1399  idhdl h=(idhdl)v->data;
1400  //Print("iiInternalExport('%s',%d)%s\n", v->name, toLev,"");
1401  if (IDLEV(h)==0)
1402  {
1403  if (BVERBOSE(V_REDEFINE)) Warn("`%s` is already global",IDID(h));
1404  }
1405  else
1406  {
1407  h=IDROOT->get(v->name,toLev);
1408  idhdl *root=&IDROOT;
1409  if ((h==NULL)&&(currRing!=NULL))
1410  {
1411  h=currRing->idroot->get(v->name,toLev);
1412  root=&currRing->idroot;
1413  }
1414  BOOLEAN keepring=FALSE;
1415  if ((h!=NULL)&&(IDLEV(h)==toLev))
1416  {
1417  if (IDTYP(h)==v->Typ())
1418  {
1419  if (((IDTYP(h)==RING_CMD)||(IDTYP(h)==QRING_CMD))
1420  && (v->Data()==IDDATA(h)))
1421  {
1422  IDRING(h)->ref++;
1423  keepring=TRUE;
1424  IDLEV(h)=toLev;
1425  //WarnS("keepring");
1426  return FALSE;
1427  }
1428  if (BVERBOSE(V_REDEFINE))
1429  {
1430  Warn("redefining %s",IDID(h));
1431  }
1432 #ifdef USE_IILOCALRING
1433  if (iiLocalRing[0]==IDRING(h) && (!keepring)) iiLocalRing[0]=NULL;
1434 #else
1436  while (p->next!=NULL) p=p->next;
1437  if ((p->cRing==IDRING(h)) && (!keepring))
1438  {
1439  p->cRing=NULL;
1440  p->cRingHdl=NULL;
1441  }
1442 #endif
1443  killhdl2(h,root,currRing);
1444  }
1445  else
1446  {
1447  return TRUE;
1448  }
1449  }
1450  h=(idhdl)v->data;
1451  IDLEV(h)=toLev;
1452  if (keepring) IDRING(h)->ref--;
1454  //Print("export %s\n",IDID(h));
1455  }
1456  return FALSE;
1457 }
1458 
1459 BOOLEAN iiInternalExport (leftv v, int toLev, package rootpack)
1460 {
1461  idhdl h=(idhdl)v->data;
1462  if(h==NULL)
1463  {
1464  Warn("'%s': no such identifier\n", v->name);
1465  return FALSE;
1466  }
1467  package frompack=v->req_packhdl;
1468  if (frompack==NULL) frompack=currPack;
1469  if ((RingDependend(IDTYP(h)))
1470  || ((IDTYP(h)==LIST_CMD)
1471  && (lRingDependend(IDLIST(h)))
1472  )
1473  )
1474  {
1475  //Print("// ==> Ringdependent set nesting to 0\n");
1476  return (iiInternalExport(v, toLev));
1477  }
1478  else
1479  {
1480  IDLEV(h)=toLev;
1481  v->req_packhdl=rootpack;
1482  if (h==frompack->idroot)
1483  {
1484  frompack->idroot=h->next;
1485  }
1486  else
1487  {
1488  idhdl hh=frompack->idroot;
1489  while ((hh!=NULL) && (hh->next!=h))
1490  hh=hh->next;
1491  if ((hh!=NULL) && (hh->next==h))
1492  hh->next=h->next;
1493  else
1494  {
1495  Werror("`%s` not found",v->Name());
1496  return TRUE;
1497  }
1498  }
1499  h->next=rootpack->idroot;
1500  rootpack->idroot=h;
1501  }
1502  return FALSE;
1503 }
1504 
1505 BOOLEAN iiExport (leftv v, int toLev)
1506 {
1507  BOOLEAN nok=FALSE;
1508  leftv r=v;
1509  while (v!=NULL)
1510  {
1511  if ((v->name==NULL)||(v->rtyp==0)||(v->e!=NULL))
1512  {
1513  Werror("cannot export:%s of internal type %d",v->name,v->rtyp);
1514  nok=TRUE;
1515  }
1516  else
1517  {
1518  if(iiInternalExport(v, toLev))
1519  {
1520  r->CleanUp();
1521  return TRUE;
1522  }
1523  }
1524  v=v->next;
1525  }
1526  r->CleanUp();
1527  return nok;
1528 }
1529 
1530 /*assume root!=idroot*/
1531 BOOLEAN iiExport (leftv v, int toLev, package pack)
1532 {
1533 #ifdef SINGULAR_4_1
1534  if ((pack==basePack)&&(pack!=currPack))
1535  { Warn("'exportto' to Top is depreciated in >>%s<<",my_yylinebuf);}
1536 #endif
1537  BOOLEAN nok=FALSE;
1538  leftv rv=v;
1539  while (v!=NULL)
1540  {
1541  if ((v->name==NULL)||(v->rtyp==0)||(v->e!=NULL)
1542  )
1543  {
1544  Werror("cannot export:%s of internal type %d",v->name,v->rtyp);
1545  nok=TRUE;
1546  }
1547  else
1548  {
1549  idhdl old=pack->idroot->get( v->name,toLev);
1550  if (old!=NULL)
1551  {
1552  if ((pack==currPack) && (old==(idhdl)v->data))
1553  {
1554  if (BVERBOSE(V_REDEFINE)) Warn("`%s` is already global",IDID(old));
1555  break;
1556  }
1557  else if (IDTYP(old)==v->Typ())
1558  {
1559  if (BVERBOSE(V_REDEFINE))
1560  {
1561  Warn("redefining %s",IDID(old));
1562  }
1563  v->name=omStrDup(v->name);
1564  killhdl2(old,&(pack->idroot),currRing);
1565  }
1566  else
1567  {
1568  rv->CleanUp();
1569  return TRUE;
1570  }
1571  }
1572  //Print("iiExport: pack=%s\n",IDID(root));
1573  if(iiInternalExport(v, toLev, pack))
1574  {
1575  rv->CleanUp();
1576  return TRUE;
1577  }
1578  }
1579  v=v->next;
1580  }
1581  rv->CleanUp();
1582  return nok;
1583 }
1584 
1586 {
1587  if (currRing==NULL)
1588  {
1589  #ifdef SIQ
1590  if (siq<=0)
1591  {
1592  #endif
1593  if (RingDependend(i))
1594  {
1595  WerrorS("no ring active");
1596  return TRUE;
1597  }
1598  #ifdef SIQ
1599  }
1600  #endif
1601  }
1602  return FALSE;
1603 }
1604 
1606 {
1607  int i;
1608  if(!idIsZeroDim(I)) return NULL; // not zero-dim.
1609  poly po=NULL;
1611  {
1612  scComputeHC(I,currRing->qideal,ak,po);
1613  if (po!=NULL)
1614  {
1615  pGetCoeff(po)=nInit(1);
1616  for (i=rVar(currRing); i>0; i--)
1617  {
1618  if (pGetExp(po, i) > 0) pDecrExp(po,i);
1619  }
1620  pSetComp(po,ak);
1621  pSetm(po);
1622  }
1623  }
1624  else
1625  po=pOne();
1626  return po;
1627 }
1628 
1630 {
1631  if (p==basePack) return;
1632 
1633  idhdl t=basePack->idroot;
1634 
1635  while ((t!=NULL) && (IDTYP(t)!=PACKAGE_CMD) && (IDPACKAGE(t)!=p)) t=t->next;
1636 
1637  if (t==NULL)
1638  {
1639  WarnS("package not found\n");
1640  p=basePack;
1641  }
1642  return;
1643 }
1644 
1645 idhdl rDefault(const char *s)
1646 {
1647  idhdl tmp=NULL;
1648 
1649  if (s!=NULL) tmp = enterid(s, myynest, RING_CMD, &IDROOT);
1650  if (tmp==NULL) return NULL;
1651 
1652 // if ((currRing->ppNoether)!=NULL) pDelete(&(currRing->ppNoether));
1654  {
1656  memset(&sLastPrinted,0,sizeof(sleftv));
1657  }
1658 
1659  ring r = IDRING(tmp);
1660 
1661  r->cf = nInitChar(n_Zp, (void*)32003); // r->cf->ch = 32003;
1662  r->N = 3;
1663  /*r->P = 0; Alloc0 in idhdl::set, ipid.cc*/
1664  /*names*/
1665  r->names = (char **) omAlloc0(3 * sizeof(char_ptr));
1666  r->names[0] = omStrDup("x");
1667  r->names[1] = omStrDup("y");
1668  r->names[2] = omStrDup("z");
1669  /*weights: entries for 3 blocks: NULL*/
1670  r->wvhdl = (int **)omAlloc0(3 * sizeof(int_ptr));
1671  /*order: dp,C,0*/
1672  r->order = (int *) omAlloc(3 * sizeof(int *));
1673  r->block0 = (int *)omAlloc0(3 * sizeof(int *));
1674  r->block1 = (int *)omAlloc0(3 * sizeof(int *));
1675  /* ringorder dp for the first block: var 1..3 */
1676  r->order[0] = ringorder_dp;
1677  r->block0[0] = 1;
1678  r->block1[0] = 3;
1679  /* ringorder C for the second block: no vars */
1680  r->order[1] = ringorder_C;
1681  /* the last block: everything is 0 */
1682  r->order[2] = 0;
1683 
1684  /* complete ring intializations */
1685  rComplete(r);
1686  rSetHdl(tmp);
1687  return currRingHdl;
1688 }
1689 
1691 {
1692  idhdl h=rSimpleFindHdl(r,IDROOT,n);
1693  if (h!=NULL) return h;
1694  if (IDROOT!=basePack->idroot) h=rSimpleFindHdl(r,basePack->idroot,n);
1695  if (h!=NULL) return h;
1697  while(p!=NULL)
1698  {
1699  if ((p->cPack!=basePack)
1700  && (p->cPack!=currPack))
1701  h=rSimpleFindHdl(r,p->cPack->idroot,n);
1702  if (h!=NULL) return h;
1703  p=p->next;
1704  }
1705  idhdl tmp=basePack->idroot;
1706  while (tmp!=NULL)
1707  {
1708  if (IDTYP(tmp)==PACKAGE_CMD)
1709  h=rSimpleFindHdl(r,IDPACKAGE(tmp)->idroot,n);
1710  if (h!=NULL) return h;
1711  tmp=IDNEXT(tmp);
1712  }
1713  return NULL;
1714 }
1715 
1716 void rDecomposeCF(leftv h,const ring r,const ring R)
1717 {
1719  L->Init(4);
1720  h->rtyp=LIST_CMD;
1721  h->data=(void *)L;
1722  // 0: char/ cf - ring
1723  // 1: list (var)
1724  // 2: list (ord)
1725  // 3: qideal
1726  // ----------------------------------------
1727  // 0: char/ cf - ring
1728  L->m[0].rtyp=INT_CMD;
1729  L->m[0].data=(void *)(long)r->cf->ch;
1730  // ----------------------------------------
1731  // 1: list (var)
1733  LL->Init(r->N);
1734  int i;
1735  for(i=0; i<r->N; i++)
1736  {
1737  LL->m[i].rtyp=STRING_CMD;
1738  LL->m[i].data=(void *)omStrDup(r->names[i]);
1739  }
1740  L->m[1].rtyp=LIST_CMD;
1741  L->m[1].data=(void *)LL;
1742  // ----------------------------------------
1743  // 2: list (ord)
1745  i=rBlocks(r)-1;
1746  LL->Init(i);
1747  i--;
1748  lists LLL;
1749  for(; i>=0; i--)
1750  {
1751  intvec *iv;
1752  int j;
1753  LL->m[i].rtyp=LIST_CMD;
1755  LLL->Init(2);
1756  LLL->m[0].rtyp=STRING_CMD;
1757  LLL->m[0].data=(void *)omStrDup(rSimpleOrdStr(r->order[i]));
1758  if (r->block1[i]-r->block0[i] >=0 )
1759  {
1760  j=r->block1[i]-r->block0[i];
1761  if(r->order[i]==ringorder_M) j=(j+1)*(j+1)-1;
1762  iv=new intvec(j+1);
1763  if ((r->wvhdl!=NULL) && (r->wvhdl[i]!=NULL))
1764  {
1765  for(;j>=0; j--) (*iv)[j]=r->wvhdl[i][j];
1766  }
1767  else switch (r->order[i])
1768  {
1769  case ringorder_dp:
1770  case ringorder_Dp:
1771  case ringorder_ds:
1772  case ringorder_Ds:
1773  case ringorder_lp:
1774  for(;j>=0; j--) (*iv)[j]=1;
1775  break;
1776  default: /* do nothing */;
1777  }
1778  }
1779  else
1780  {
1781  iv=new intvec(1);
1782  }
1783  LLL->m[1].rtyp=INTVEC_CMD;
1784  LLL->m[1].data=(void *)iv;
1785  LL->m[i].data=(void *)LLL;
1786  }
1787  L->m[2].rtyp=LIST_CMD;
1788  L->m[2].data=(void *)LL;
1789  // ----------------------------------------
1790  // 3: qideal
1791  L->m[3].rtyp=IDEAL_CMD;
1792  if (nCoeff_is_transExt(R->cf))
1793  L->m[3].data=(void *)idInit(1,1);
1794  else
1795  {
1796  ideal q=idInit(IDELEMS(r->qideal));
1797  q->m[0]=p_Init(R);
1798  pSetCoeff0(q->m[0],(number)(r->qideal->m[0]));
1799  L->m[3].data=(void *)q;
1800 // I->m[0] = pNSet(R->minpoly);
1801  }
1802  // ----------------------------------------
1803 }
1804 void rDecomposeC(leftv h,const ring R)
1805 /* field is R or C */
1806 {
1808  if (rField_is_long_C(R)) L->Init(3);
1809  else L->Init(2);
1810  h->rtyp=LIST_CMD;
1811  h->data=(void *)L;
1812  // 0: char/ cf - ring
1813  // 1: list (var)
1814  // 2: list (ord)
1815  // ----------------------------------------
1816  // 0: char/ cf - ring
1817  L->m[0].rtyp=INT_CMD;
1818  L->m[0].data=(void *)0;
1819  // ----------------------------------------
1820  // 1:
1822  LL->Init(2);
1823  LL->m[0].rtyp=INT_CMD;
1824  LL->m[0].data=(void *)(long)si_max(R->cf->float_len,SHORT_REAL_LENGTH/2);
1825  LL->m[1].rtyp=INT_CMD;
1826  LL->m[1].data=(void *)(long)si_max(R->cf->float_len2,SHORT_REAL_LENGTH);
1827  L->m[1].rtyp=LIST_CMD;
1828  L->m[1].data=(void *)LL;
1829  // ----------------------------------------
1830  // 2: list (par)
1831  if (rField_is_long_C(R))
1832  {
1833  L->m[2].rtyp=STRING_CMD;
1834  L->m[2].data=(void *)omStrDup(*rParameter(R));
1835  }
1836  // ----------------------------------------
1837 }
1838 
1839 #ifdef HAVE_RINGS
1840 void rDecomposeRing(leftv h,const ring R)
1841 /* field is R or C */
1842 {
1844  if (rField_is_Ring_Z(R)) L->Init(1);
1845  else L->Init(2);
1846  h->rtyp=LIST_CMD;
1847  h->data=(void *)L;
1848  // 0: char/ cf - ring
1849  // 1: list (module)
1850  // ----------------------------------------
1851  // 0: char/ cf - ring
1852  L->m[0].rtyp=STRING_CMD;
1853  L->m[0].data=(void *)omStrDup("integer");
1854  // ----------------------------------------
1855  // 1: module
1856  if (rField_is_Ring_Z(R)) return;
1858  LL->Init(2);
1859  LL->m[0].rtyp=BIGINT_CMD;
1860  LL->m[0].data=nlMapGMP((number) R->cf->modBase, R->cf, R->cf); // TODO: what is this?? // extern number nlMapGMP(number from, const coeffs src, const coeffs dst); // FIXME: replace with n_InitMPZ(R->cf->modBase, coeffs_BIGINT); ?
1861  LL->m[1].rtyp=INT_CMD;
1862  LL->m[1].data=(void *) R->cf->modExponent;
1863  L->m[1].rtyp=LIST_CMD;
1864  L->m[1].data=(void *)LL;
1865 }
1866 #endif
1867 
1868 
1869 lists rDecompose(const ring r)
1870 {
1871  assume( r != NULL );
1872  const coeffs C = r->cf;
1873  assume( C != NULL );
1874 
1875  // sanity check: require currRing==r for rings with polynomial data
1876  if ( (r!=currRing) && (
1877  (nCoeff_is_algExt(C) && (C != currRing->cf))
1878  || (r->qideal != NULL)
1879 #ifdef HAVE_PLURAL
1880  || (rIsPluralRing(r))
1881 #endif
1882  )
1883  )
1884  {
1885  WerrorS("ring with polynomial data must be the base ring or compatible");
1886  return NULL;
1887  }
1888  // 0: char/ cf - ring
1889  // 1: list (var)
1890  // 2: list (ord)
1891  // 3: qideal
1892  // possibly:
1893  // 4: C
1894  // 5: D
1896  if (rIsPluralRing(r))
1897  L->Init(6);
1898  else
1899  L->Init(4);
1900  // ----------------------------------------
1901  // 0: char/ cf - ring
1902 #ifdef SINGULAR_4_1
1903  // 0: char/ cf - ring
1904  L->m[0].rtyp=CRING_CMD;
1905  L->m[0].data=(char*)r->cf; r->cf->ref++;
1906 #else
1907  if (rField_is_numeric(r))
1908  {
1909  rDecomposeC(&(L->m[0]),r);
1910  }
1911 #ifdef HAVE_RINGS
1912  else if (rField_is_Ring(r))
1913  {
1914  rDecomposeRing(&(L->m[0]),r);
1915  }
1916 #endif
1917  else if ( r->cf->extRing!=NULL )// nCoeff_is_algExt(r->cf))
1918  {
1919  rDecomposeCF(&(L->m[0]), r->cf->extRing, r);
1920  }
1921  else if(rField_is_GF(r))
1922  {
1924  Lc->Init(4);
1925  // char:
1926  Lc->m[0].rtyp=INT_CMD;
1927  Lc->m[0].data=(void*)(long)r->cf->m_nfCharQ;
1928  // var:
1930  Lv->Init(1);
1931  Lv->m[0].rtyp=STRING_CMD;
1932  Lv->m[0].data=(void *)omStrDup(*rParameter(r));
1933  Lc->m[1].rtyp=LIST_CMD;
1934  Lc->m[1].data=(void*)Lv;
1935  // ord:
1937  Lo->Init(1);
1939  Loo->Init(2);
1940  Loo->m[0].rtyp=STRING_CMD;
1941  Loo->m[0].data=(void *)omStrDup(rSimpleOrdStr(ringorder_lp));
1942 
1943  intvec *iv=new intvec(1); (*iv)[0]=1;
1944  Loo->m[1].rtyp=INTVEC_CMD;
1945  Loo->m[1].data=(void *)iv;
1946 
1947  Lo->m[0].rtyp=LIST_CMD;
1948  Lo->m[0].data=(void*)Loo;
1949 
1950  Lc->m[2].rtyp=LIST_CMD;
1951  Lc->m[2].data=(void*)Lo;
1952  // q-ideal:
1953  Lc->m[3].rtyp=IDEAL_CMD;
1954  Lc->m[3].data=(void *)idInit(1,1);
1955  // ----------------------
1956  L->m[0].rtyp=LIST_CMD;
1957  L->m[0].data=(void*)Lc;
1958  }
1959  else
1960  {
1961  L->m[0].rtyp=INT_CMD;
1962  L->m[0].data=(void *)(long)r->cf->ch;
1963  }
1964 #endif
1965  // ----------------------------------------
1966  // 1: list (var)
1968  LL->Init(r->N);
1969  int i;
1970  for(i=0; i<r->N; i++)
1971  {
1972  LL->m[i].rtyp=STRING_CMD;
1973  LL->m[i].data=(void *)omStrDup(r->names[i]);
1974  }
1975  L->m[1].rtyp=LIST_CMD;
1976  L->m[1].data=(void *)LL;
1977  // ----------------------------------------
1978  // 2: list (ord)
1980  i=rBlocks(r)-1;
1981  LL->Init(i);
1982  i--;
1983  lists LLL;
1984  for(; i>=0; i--)
1985  {
1986  intvec *iv;
1987  int j;
1988  LL->m[i].rtyp=LIST_CMD;
1990  LLL->Init(2);
1991  LLL->m[0].rtyp=STRING_CMD;
1992  LLL->m[0].data=(void *)omStrDup(rSimpleOrdStr(r->order[i]));
1993 
1994  if(r->order[i] == ringorder_IS) // || r->order[i] == ringorder_s || r->order[i] == ringorder_S)
1995  {
1996  assume( r->block0[i] == r->block1[i] );
1997  const int s = r->block0[i];
1998  assume( -2 < s && s < 2);
1999 
2000  iv=new intvec(1);
2001  (*iv)[0] = s;
2002  }
2003  else if (r->block1[i]-r->block0[i] >=0 )
2004  {
2005  int bl=j=r->block1[i]-r->block0[i];
2006  if (r->order[i]==ringorder_M)
2007  {
2008  j=(j+1)*(j+1)-1;
2009  bl=j+1;
2010  }
2011  else if (r->order[i]==ringorder_am)
2012  {
2013  j+=r->wvhdl[i][bl+1];
2014  }
2015  iv=new intvec(j+1);
2016  if ((r->wvhdl!=NULL) && (r->wvhdl[i]!=NULL))
2017  {
2018  for(;j>=0; j--) (*iv)[j]=r->wvhdl[i][j+(j>bl)];
2019  }
2020  else switch (r->order[i])
2021  {
2022  case ringorder_dp:
2023  case ringorder_Dp:
2024  case ringorder_ds:
2025  case ringorder_Ds:
2026  case ringorder_lp:
2027  for(;j>=0; j--) (*iv)[j]=1;
2028  break;
2029  default: /* do nothing */;
2030  }
2031  }
2032  else
2033  {
2034  iv=new intvec(1);
2035  }
2036  LLL->m[1].rtyp=INTVEC_CMD;
2037  LLL->m[1].data=(void *)iv;
2038  LL->m[i].data=(void *)LLL;
2039  }
2040  L->m[2].rtyp=LIST_CMD;
2041  L->m[2].data=(void *)LL;
2042  // ----------------------------------------
2043  // 3: qideal
2044  L->m[3].rtyp=IDEAL_CMD;
2045  if (r->qideal==NULL)
2046  L->m[3].data=(void *)idInit(1,1);
2047  else
2048  L->m[3].data=(void *)idCopy(r->qideal);
2049  // ----------------------------------------
2050 #ifdef HAVE_PLURAL // NC! in rDecompose
2051  if (rIsPluralRing(r))
2052  {
2053  L->m[4].rtyp=MATRIX_CMD;
2054  L->m[4].data=(void *)mp_Copy(r->GetNC()->C, r, r);
2055  L->m[5].rtyp=MATRIX_CMD;
2056  L->m[5].data=(void *)mp_Copy(r->GetNC()->D, r, r);
2057  }
2058 #endif
2059  return L;
2060 }
2061 
2062 void rComposeC(lists L, ring R)
2063 /* field is R or C */
2064 {
2065  // ----------------------------------------
2066  // 0: char/ cf - ring
2067  if ((L->m[0].rtyp!=INT_CMD) || (L->m[0].data!=(char *)0))
2068  {
2069  Werror("invald coeff. field description, expecting 0");
2070  return;
2071  }
2072 // R->cf->ch=0;
2073  // ----------------------------------------
2074  // 1:
2075  if (L->m[1].rtyp!=LIST_CMD)
2076  Werror("invald coeff. field description, expecting precision list");
2077  lists LL=(lists)L->m[1].data;
2078  int r1=(int)(long)LL->m[0].data;
2079  int r2=(int)(long)LL->m[1].data;
2080  if (L->nr==2) // complex
2081  R->cf = nInitChar(n_long_C, NULL);
2082  else if ((r1<=SHORT_REAL_LENGTH)
2083  && (r2=SHORT_REAL_LENGTH))
2084  R->cf = nInitChar(n_R, NULL);
2085  else
2086  {
2088  p->float_len=r1;
2089  p->float_len2=r2;
2090  R->cf = nInitChar(n_long_R, NULL);
2091  }
2092 
2093  if ((r1<=SHORT_REAL_LENGTH) // should go into nInitChar
2094  && (r2=SHORT_REAL_LENGTH))
2095  {
2096  R->cf->float_len=SHORT_REAL_LENGTH/2;
2097  R->cf->float_len2=SHORT_REAL_LENGTH;
2098  }
2099  else
2100  {
2101  R->cf->float_len=si_min(r1,32767);
2102  R->cf->float_len2=si_min(r2,32767);
2103  }
2104  // ----------------------------------------
2105  // 2: list (par)
2106  if (L->nr==2)
2107  {
2108  //R->cf->extRing->N=1;
2109  if (L->m[2].rtyp!=STRING_CMD)
2110  {
2111  Werror("invald coeff. field description, expecting parameter name");
2112  return;
2113  }
2114  //(rParameter(R))=(char**)omAlloc0(rPar(R)*sizeof(char_ptr));
2115  rParameter(R)[0]=omStrDup((char *)L->m[2].data);
2116  }
2117  // ----------------------------------------
2118 }
2119 
2120 #ifdef HAVE_RINGS
2121 void rComposeRing(lists L, ring R)
2122 /* field is R or C */
2123 {
2124  // ----------------------------------------
2125  // 0: string: integer
2126  // no further entries --> Z
2127  mpz_ptr modBase = NULL;
2128  unsigned int modExponent = 1;
2129 
2130  modBase = (mpz_ptr) omAlloc(sizeof(mpz_t));
2131  if (L->nr == 0)
2132  {
2133  mpz_init_set_ui(modBase,0);
2134  modExponent = 1;
2135  }
2136  // ----------------------------------------
2137  // 1:
2138  else
2139  {
2140  if (L->m[1].rtyp!=LIST_CMD) Werror("invald data, expecting list of numbers");
2141  lists LL=(lists)L->m[1].data;
2142  if ((LL->nr >= 0) && LL->m[0].rtyp == BIGINT_CMD)
2143  {
2144  number tmp= (number) LL->m[0].data; // never use CopyD() on list elements
2145  // assume that tmp is integer, not rational
2146  n_MPZ (modBase, tmp, coeffs_BIGINT);
2147  }
2148  else if (LL->nr >= 0 && LL->m[0].rtyp == INT_CMD)
2149  {
2150  mpz_init_set_ui(modBase,(unsigned long) LL->m[0].data);
2151  }
2152  else
2153  {
2154  mpz_init_set_ui(modBase,0);
2155  }
2156  if (LL->nr >= 1)
2157  {
2158  modExponent = (unsigned long) LL->m[1].data;
2159  }
2160  else
2161  {
2162  modExponent = 1;
2163  }
2164  }
2165  // ----------------------------------------
2166  if ((mpz_cmp_ui(modBase, 1) == 0) && (mpz_cmp_ui(modBase, 0) < 0))
2167  {
2168  Werror("Wrong ground ring specification (module is 1)");
2169  return;
2170  }
2171  if (modExponent < 1)
2172  {
2173  Werror("Wrong ground ring specification (exponent smaller than 1");
2174  return;
2175  }
2176  // module is 0 ---> integers
2177  if (mpz_cmp_ui(modBase, 0) == 0)
2178  {
2179  R->cf=nInitChar(n_Z,NULL);
2180  }
2181  // we have an exponent
2182  else if (modExponent > 1)
2183  {
2184  //R->cf->ch = R->cf->modExponent;
2185  if ((mpz_cmp_ui(modBase, 2) == 0) && (modExponent <= 8*sizeof(unsigned long)))
2186  {
2187  /* this branch should be active for modExponent = 2..32 resp. 2..64,
2188  depending on the size of a long on the respective platform */
2189  R->cf=nInitChar(n_Z2m,(void*)(long)modExponent); // Use Z/2^ch
2190  omFreeSize (modBase, sizeof(mpz_t));
2191  }
2192  else
2193  {
2194  //ringtype 3
2195  ZnmInfo info;
2196  info.base= modBase;
2197  info.exp= modExponent;
2198  R->cf=nInitChar(n_Znm,(void*) &info);
2199  }
2200  }
2201  // just a module m > 1
2202  else
2203  {
2204  //ringtype = 2;
2205  //const int ch = mpz_get_ui(modBase);
2206  ZnmInfo info;
2207  info.base= modBase;
2208  info.exp= modExponent;
2209  R->cf=nInitChar(n_Zn,(void*) &info);
2210  }
2211 }
2212 #endif
2213 
2214 static void rRenameVars(ring R)
2215 {
2216  int i,j;
2217  BOOLEAN ch;
2218  do
2219  {
2220  ch=0;
2221  for(i=0;i<R->N-1;i++)
2222  {
2223  for(j=i+1;j<R->N;j++)
2224  {
2225  if (strcmp(R->names[i],R->names[j])==0)
2226  {
2227  ch=TRUE;
2228  Warn("name conflict var(%d) and var(%d): `%s`, rename to `@%s`",i+1,j+1,R->names[i],R->names[i]);
2229  omFree(R->names[j]);
2230  R->names[j]=(char *)omAlloc(2+strlen(R->names[i]));
2231  sprintf(R->names[j],"@%s",R->names[i]);
2232  }
2233  }
2234  }
2235  }
2236  while (ch);
2237  for(i=0;i<rPar(R); i++)
2238  {
2239  for(j=0;j<R->N;j++)
2240  {
2241  if (strcmp(rParameter(R)[i],R->names[j])==0)
2242  {
2243  Warn("name conflict par(%d) and var(%d): `%s`, renaming the VARIABLE to `@@(%d)`",i+1,j+1,R->names[j],i+1);
2244 // omFree(rParameter(R)[i]);
2245 // rParameter(R)[i]=(char *)omAlloc(10);
2246 // sprintf(rParameter(R)[i],"@@(%d)",i+1);
2247  omFree(R->names[j]);
2248  R->names[j]=(char *)omAlloc(10);
2249  sprintf(R->names[j],"@@(%d)",i+1);
2250  }
2251  }
2252  }
2253 }
2254 
2255 ring rCompose(const lists L, const BOOLEAN check_comp)
2256 {
2257  if ((L->nr!=3)
2258 #ifdef HAVE_PLURAL
2259  &&(L->nr!=5)
2260 #endif
2261  )
2262  return NULL;
2263  int is_gf_char=0;
2264  // 0: char/ cf - ring
2265  // 1: list (var)
2266  // 2: list (ord)
2267  // 3: qideal
2268  // possibly:
2269  // 4: C
2270  // 5: D
2271 
2272  ring R = (ring) omAlloc0Bin(sip_sring_bin);
2273 
2274 
2275  // ------------------------------------------------------------------
2276  // 0: char:
2277 #ifdef SINGULAR_4_1
2278  if (L->m[0].Typ()==CRING_CMD)
2279  {
2280  R->cf=(coeffs)L->m[0].Data();
2281  R->cf->ref++;
2282  }
2283  else
2284 #endif
2285  if (L->m[0].Typ()==INT_CMD)
2286  {
2287  int ch = (int)(long)L->m[0].Data();
2288  assume( ch >= 0 );
2289 
2290  if (ch == 0) // Q?
2291  R->cf = nInitChar(n_Q, NULL);
2292  else
2293  {
2294  int l = IsPrime(ch); // Zp?
2295  if( l != ch )
2296  {
2297  Warn("%d is invalid characteristic of ground field. %d is used.", ch, l);
2298  ch = l;
2299  }
2300  R->cf = nInitChar(n_Zp, (void*)(long)ch);
2301  }
2302  }
2303  else if (L->m[0].Typ()==LIST_CMD) // something complicated...
2304  {
2305  lists LL=(lists)L->m[0].Data();
2306 
2307 #ifdef HAVE_RINGS
2308  if (LL->m[0].Typ() == STRING_CMD) // 1st comes a string?
2309  {
2310  rComposeRing(LL, R); // Ring!?
2311  }
2312  else
2313 #endif
2314  if (LL->nr < 3)
2315  rComposeC(LL,R); // R, long_R, long_C
2316  else
2317  {
2318  if (LL->m[0].Typ()==INT_CMD)
2319  {
2320  int ch = (int)(long)LL->m[0].Data();
2321  while ((ch!=fftable[is_gf_char]) && (fftable[is_gf_char])) is_gf_char++;
2322  if (fftable[is_gf_char]==0) is_gf_char=-1;
2323 
2324  if(is_gf_char!= -1)
2325  {
2326  GFInfo param;
2327 
2328  param.GFChar = ch;
2329  param.GFDegree = 1;
2330  param.GFPar_name = (const char*)(((lists)(LL->m[1].Data()))->m[0].Data());
2331 
2332  // nfInitChar should be able to handle the case when ch is in fftables!
2333  R->cf = nInitChar(n_GF, (void*)&param);
2334  }
2335  }
2336 
2337  if( R->cf == NULL )
2338  {
2339  ring extRing = rCompose((lists)L->m[0].Data(),FALSE);
2340 
2341  if (extRing==NULL)
2342  {
2343  WerrorS("could not create the specified coefficient field");
2344  goto rCompose_err;
2345  }
2346 
2347  if( extRing->qideal != NULL ) // Algebraic extension
2348  {
2349  AlgExtInfo extParam;
2350 
2351  extParam.r = extRing;
2352 
2353  R->cf = nInitChar(n_algExt, (void*)&extParam);
2354  }
2355  else // Transcendental extension
2356  {
2357  TransExtInfo extParam;
2358  extParam.r = extRing;
2359  assume( extRing->qideal == NULL );
2360 
2361  R->cf = nInitChar(n_transExt, &extParam);
2362  }
2363  }
2364  }
2365  }
2366  else
2367  {
2368  WerrorS("coefficient field must be described by `int` or `list`");
2369  goto rCompose_err;
2370  }
2371 
2372  if( R->cf == NULL )
2373  {
2374  WerrorS("could not create coefficient field described by the input!");
2375  goto rCompose_err;
2376  }
2377 
2378  // ------------------------- VARS ---------------------------
2379  if (L->m[1].Typ()==LIST_CMD)
2380  {
2381  lists v=(lists)L->m[1].Data();
2382  R->N = v->nr+1;
2383  if (R->N<=0)
2384  {
2385  WerrorS("no ring variables");
2386  goto rCompose_err;
2387  }
2388  R->names = (char **)omAlloc0(R->N * sizeof(char_ptr));
2389  int i;
2390  for(i=0;i<R->N;i++)
2391  {
2392  if (v->m[i].Typ()==STRING_CMD)
2393  R->names[i]=omStrDup((char *)v->m[i].Data());
2394  else if (v->m[i].Typ()==POLY_CMD)
2395  {
2396  poly p=(poly)v->m[i].Data();
2397  int nr=pIsPurePower(p);
2398  if (nr>0)
2399  R->names[i]=omStrDup(currRing->names[nr-1]);
2400  else
2401  {
2402  Werror("var name %d must be a string or a ring variable",i+1);
2403  goto rCompose_err;
2404  }
2405  }
2406  else
2407  {
2408  Werror("var name %d must be `string`",i+1);
2409  goto rCompose_err;
2410  }
2411  }
2412  }
2413  else
2414  {
2415  WerrorS("variable must be given as `list`");
2416  goto rCompose_err;
2417  }
2418  // ------------------------ ORDER ------------------------------
2419  if (L->m[2].Typ()==LIST_CMD)
2420  {
2421  lists v=(lists)L->m[2].Data();
2422  int n= v->nr+2;
2423  int j;
2424  // initialize fields of R
2425  R->order=(int *)omAlloc0(n*sizeof(int));
2426  R->block0=(int *)omAlloc0(n*sizeof(int));
2427  R->block1=(int *)omAlloc0(n*sizeof(int));
2428  R->wvhdl=(int**)omAlloc0(n*sizeof(int_ptr));
2429  // init order, so that rBlocks works correctly
2430  for (j=0; j < n-1; j++)
2431  R->order[j] = (int) ringorder_unspec;
2432  // orderings
2433  for(j=0;j<n-1;j++)
2434  {
2435  // todo: a(..), M
2436  if (v->m[j].Typ()!=LIST_CMD)
2437  {
2438  WerrorS("ordering must be list of lists");
2439  goto rCompose_err;
2440  }
2441  lists vv=(lists)v->m[j].Data();
2442  if ((vv->nr!=1)
2443  || (vv->m[0].Typ()!=STRING_CMD)
2444  || ((vv->m[1].Typ()!=INTVEC_CMD) && (vv->m[1].Typ()!=INT_CMD)))
2445  {
2446  WerrorS("ordering name must be a (string,intvec)");
2447  goto rCompose_err;
2448  }
2449  R->order[j]=rOrderName(omStrDup((char*)vv->m[0].Data())); // assume STRING
2450 
2451  if (j==0) R->block0[0]=1;
2452  else
2453  {
2454  int jj=j-1;
2455  while((jj>=0)
2456  && ((R->order[jj]== ringorder_a)
2457  || (R->order[jj]== ringorder_aa)
2458  || (R->order[jj]== ringorder_am)
2459  || (R->order[jj]== ringorder_c)
2460  || (R->order[jj]== ringorder_C)
2461  || (R->order[jj]== ringorder_s)
2462  || (R->order[jj]== ringorder_S)
2463  ))
2464  {
2465  //Print("jj=%, skip %s\n",rSimpleOrdStr(R->order[jj]));
2466  jj--;
2467  }
2468  if (jj<0) R->block0[j]=1;
2469  else R->block0[j]=R->block1[jj]+1;
2470  }
2471  intvec *iv;
2472  if (vv->m[1].Typ()==INT_CMD)
2473  iv=new intvec((int)(long)vv->m[1].Data(),(int)(long)vv->m[1].Data());
2474  else
2475  iv=ivCopy((intvec*)vv->m[1].Data()); //assume INTVEC
2476  int iv_len=iv->length();
2477  R->block1[j]=si_max(R->block0[j],R->block0[j]+iv_len-1);
2478  if (R->block1[j]>R->N)
2479  {
2480  R->block1[j]=R->N;
2481  iv_len=R->block1[j]-R->block0[j]+1;
2482  }
2483  //Print("block %d from %d to %d\n",j,R->block0[j], R->block1[j]);
2484  int i;
2485  switch (R->order[j])
2486  {
2487  case ringorder_ws:
2488  case ringorder_Ws:
2489  R->OrdSgn=-1;
2490  case ringorder_aa:
2491  case ringorder_a:
2492  case ringorder_wp:
2493  case ringorder_Wp:
2494  R->wvhdl[j] =( int *)omAlloc(iv_len*sizeof(int));
2495  for (i=0; i<iv_len;i++)
2496  {
2497  R->wvhdl[j][i]=(*iv)[i];
2498  }
2499  break;
2500  case ringorder_am:
2501  R->wvhdl[j] =( int *)omAlloc((iv->length()+1)*sizeof(int));
2502  for (i=0; i<iv_len;i++)
2503  {
2504  R->wvhdl[j][i]=(*iv)[i];
2505  }
2506  R->wvhdl[j][i]=iv->length() - iv_len;
2507  //printf("ivlen:%d,iv->len:%d,mod:%d\n",iv_len,iv->length(),R->wvhdl[j][i]);
2508  for (; i<iv->length(); i++)
2509  {
2510  R->wvhdl[j][i+1]=(*iv)[i];
2511  }
2512  break;
2513  case ringorder_M:
2514  R->wvhdl[j] =( int *)omAlloc((iv->length())*sizeof(int));
2515  for (i=0; i<iv->length();i++) R->wvhdl[j][i]=(*iv)[i];
2516  R->block1[j]=si_max(R->block0[j],R->block0[j]+(int)sqrt((double)(iv->length()-1)));
2517  if (R->block1[j]>R->N)
2518  {
2519  WerrorS("ordering matrix too big");
2520  goto rCompose_err;
2521  }
2522  break;
2523  case ringorder_ls:
2524  case ringorder_ds:
2525  case ringorder_Ds:
2526  case ringorder_rs:
2527  R->OrdSgn=-1;
2528  case ringorder_lp:
2529  case ringorder_dp:
2530  case ringorder_Dp:
2531  case ringorder_rp:
2532  break;
2533  case ringorder_S:
2534  break;
2535  case ringorder_c:
2536  case ringorder_C:
2537  R->block1[j]=R->block0[j]=0;
2538  break;
2539 
2540  case ringorder_s:
2541  break;
2542 
2543  case ringorder_IS:
2544  {
2545  R->block1[j] = R->block0[j] = 0;
2546  if( iv->length() > 0 )
2547  {
2548  const int s = (*iv)[0];
2549  assume( -2 < s && s < 2 );
2550  R->block1[j] = R->block0[j] = s;
2551  }
2552  break;
2553  }
2554  case 0:
2555  case ringorder_unspec:
2556  break;
2557  }
2558  delete iv;
2559  }
2560  // sanity check
2561  j=n-2;
2562  if ((R->order[j]==ringorder_c)
2563  || (R->order[j]==ringorder_C)
2564  || (R->order[j]==ringorder_unspec)) j--;
2565  if (R->block1[j] != R->N)
2566  {
2567  if (((R->order[j]==ringorder_dp) ||
2568  (R->order[j]==ringorder_ds) ||
2569  (R->order[j]==ringorder_Dp) ||
2570  (R->order[j]==ringorder_Ds) ||
2571  (R->order[j]==ringorder_rp) ||
2572  (R->order[j]==ringorder_rs) ||
2573  (R->order[j]==ringorder_lp) ||
2574  (R->order[j]==ringorder_ls))
2575  &&
2576  R->block0[j] <= R->N)
2577  {
2578  R->block1[j] = R->N;
2579  }
2580  else
2581  {
2582  Werror("ordering incomplete: size (%d) should be %d",R->block1[j],R->N);
2583  goto rCompose_err;
2584  }
2585  }
2586  if (R->block0[j]>R->N)
2587  {
2588  Werror("not enough variables (%d) for ordering block %d, scanned so far:",R->N,j+1);
2589  for(int ii=0;ii<=j;ii++)
2590  Werror("ord[%d]: %s from v%d to v%d",ii+1,rSimpleOrdStr(R->order[ii]),R->block0[ii],R->block1[ii]);
2591  goto rCompose_err;
2592  }
2593  if (check_comp)
2594  {
2595  BOOLEAN comp_order=FALSE;
2596  int jj;
2597  for(jj=0;jj<n;jj++)
2598  {
2599  if ((R->order[jj]==ringorder_c) ||
2600  (R->order[jj]==ringorder_C)) { comp_order=TRUE; break; }
2601  }
2602  if (!comp_order)
2603  {
2604  R->order=(int*)omRealloc0Size(R->order,n*sizeof(int),(n+1)*sizeof(int));
2605  R->block0=(int*)omRealloc0Size(R->block0,n*sizeof(int),(n+1)*sizeof(int));
2606  R->block1=(int*)omRealloc0Size(R->block1,n*sizeof(int),(n+1)*sizeof(int));
2607  R->wvhdl=(int**)omRealloc0Size(R->wvhdl,n*sizeof(int_ptr),(n+1)*sizeof(int_ptr));
2608  R->order[n-1]=ringorder_C;
2609  R->block0[n-1]=0;
2610  R->block1[n-1]=0;
2611  R->wvhdl[n-1]=NULL;
2612  n++;
2613  }
2614  }
2615  }
2616  else
2617  {
2618  WerrorS("ordering must be given as `list`");
2619  goto rCompose_err;
2620  }
2621 
2622  // ------------------------ ??????? --------------------
2623 
2624  rRenameVars(R);
2625  rComplete(R);
2626 
2627 /*#ifdef HAVE_RINGS
2628 // currently, coefficients which are ring elements require a global ordering:
2629  if (rField_is_Ring(R) && (R->OrdSgn==-1))
2630  {
2631  WerrorS("global ordering required for these coefficients");
2632  goto rCompose_err;
2633  }
2634 #endif*/
2635 
2636 
2637  // ------------------------ Q-IDEAL ------------------------
2638 
2639  if (L->m[3].Typ()==IDEAL_CMD)
2640  {
2641  ideal q=(ideal)L->m[3].Data();
2642  if (q->m[0]!=NULL)
2643  {
2644  if (R->cf != currRing->cf) //->cf->ch!=currRing->cf->ch)
2645  {
2646  #if 0
2647  WerrorS("coefficient fields must be equal if q-ideal !=0");
2648  goto rCompose_err;
2649  #else
2650  ring orig_ring=currRing;
2651  rChangeCurrRing(R);
2652  int *perm=NULL;
2653  int *par_perm=NULL;
2654  int par_perm_size=0;
2655  nMapFunc nMap;
2656 
2657  if ((nMap=nSetMap(orig_ring->cf))==NULL)
2658  {
2659  if (rEqual(orig_ring,currRing))
2660  {
2661  nMap=n_SetMap(currRing->cf, currRing->cf);
2662  }
2663  else
2664  // Allow imap/fetch to be make an exception only for:
2665  if ( (rField_is_Q_a(orig_ring) && // Q(a..) -> Q(a..) || Q || Zp || Zp(a)
2668  ||
2669  (rField_is_Zp_a(orig_ring) && // Zp(a..) -> Zp(a..) || Zp
2670  (rField_is_Zp(currRing, rInternalChar(orig_ring)) ||
2671  rField_is_Zp_a(currRing, rInternalChar(orig_ring)))) )
2672  {
2673  par_perm_size=rPar(orig_ring);
2674 
2675 // if ((orig_ring->minpoly != NULL) || (orig_ring->qideal != NULL))
2676 // naSetChar(rInternalChar(orig_ring),orig_ring);
2677 // else ntSetChar(rInternalChar(orig_ring),orig_ring);
2678 
2679  nSetChar(currRing->cf);
2680  }
2681  else
2682  {
2683  WerrorS("coefficient fields must be equal if q-ideal !=0");
2684  goto rCompose_err;
2685  }
2686  }
2687  perm=(int *)omAlloc0((orig_ring->N+1)*sizeof(int));
2688  if (par_perm_size!=0)
2689  par_perm=(int *)omAlloc0(par_perm_size*sizeof(int));
2690  int i;
2691  #if 0
2692  // use imap:
2693  maFindPerm(orig_ring->names,orig_ring->N,orig_ring->parameter,orig_ring->P,
2694  currRing->names,currRing->N,currRing->parameter, currRing->P,
2695  perm,par_perm, currRing->ch);
2696  #else
2697  // use fetch
2698  if ((rPar(orig_ring)>0) && (rPar(currRing)==0))
2699  {
2700  for(i=si_min(rPar(orig_ring),rVar(currRing))-1;i>=0;i--) par_perm[i]=i+1;
2701  }
2702  else if (par_perm_size!=0)
2703  for(i=si_min(rPar(orig_ring),rPar(currRing))-1;i>=0;i--) par_perm[i]=-(i+1);
2704  for(i=si_min(orig_ring->N,rVar(currRing));i>0;i--) perm[i]=i;
2705  #endif
2706  ideal dest_id=idInit(IDELEMS(q),1);
2707  for(i=IDELEMS(q)-1; i>=0; i--)
2708  {
2709  dest_id->m[i]=p_PermPoly(q->m[i],perm,orig_ring, currRing,nMap,
2710  par_perm,par_perm_size);
2711  // PrintS("map:");pWrite(dest_id->m[i]);PrintLn();
2712  pTest(dest_id->m[i]);
2713  }
2714  R->qideal=dest_id;
2715  if (perm!=NULL)
2716  omFreeSize((ADDRESS)perm,(orig_ring->N+1)*sizeof(int));
2717  if (par_perm!=NULL)
2718  omFreeSize((ADDRESS)par_perm,par_perm_size*sizeof(int));
2719  rChangeCurrRing(orig_ring);
2720  #endif
2721  }
2722  else
2723  R->qideal=idrCopyR(q,currRing,R);
2724  }
2725  }
2726  else
2727  {
2728  WerrorS("q-ideal must be given as `ideal`");
2729  goto rCompose_err;
2730  }
2731 
2732 
2733  // ---------------------------------------------------------------
2734  #ifdef HAVE_PLURAL
2735  if (L->nr==5)
2736  {
2737  if (nc_CallPlural((matrix)L->m[4].Data(),
2738  (matrix)L->m[5].Data(),
2739  NULL,NULL,
2740  R,
2741  true, // !!!
2742  true, false,
2743  currRing, FALSE)) goto rCompose_err;
2744  // takes care about non-comm. quotient! i.e. calls "nc_SetupQuotient" due to last true
2745  }
2746  #endif
2747  return R;
2748 
2749 rCompose_err:
2750  if (R->N>0)
2751  {
2752  int i;
2753  if (R->names!=NULL)
2754  {
2755  i=R->N-1;
2756  while (i>=0) { if (R->names[i]!=NULL) omFree(R->names[i]); i--; }
2757  omFree(R->names);
2758  }
2759  }
2760  if (R->order!=NULL) omFree(R->order);
2761  if (R->block0!=NULL) omFree(R->block0);
2762  if (R->block1!=NULL) omFree(R->block1);
2763  if (R->wvhdl!=NULL) omFree(R->wvhdl);
2764  omFree(R);
2765  return NULL;
2766 }
2767 
2768 // from matpol.cc
2769 
2770 /*2
2771 * compute the jacobi matrix of an ideal
2772 */
2774 {
2775  int i,j;
2776  matrix result;
2777  ideal id=(ideal)a->Data();
2778 
2779  result =mpNew(IDELEMS(id),rVar(currRing));
2780  for (i=1; i<=IDELEMS(id); i++)
2781  {
2782  for (j=1; j<=rVar(currRing); j++)
2783  {
2784  MATELEM(result,i,j) = pDiff(id->m[i-1],j);
2785  }
2786  }
2787  res->data=(char *)result;
2788  return FALSE;
2789 }
2790 
2791 /*2
2792 * returns the Koszul-matrix of degree d of a vectorspace with dimension n
2793 * uses the first n entrees of id, if id <> NULL
2794 */
2796 {
2797  int n=(int)(long)b->Data();
2798  int d=(int)(long)c->Data();
2799  int k,l,sign,row,col;
2800  matrix result;
2801  ideal temp;
2802  BOOLEAN bo;
2803  poly p;
2804 
2805  if ((d>n) || (d<1) || (n<1))
2806  {
2807  res->data=(char *)mpNew(1,1);
2808  return FALSE;
2809  }
2810  int *choise = (int*)omAlloc(d*sizeof(int));
2811  if (id==NULL)
2812  temp=idMaxIdeal(1);
2813  else
2814  temp=(ideal)id->Data();
2815 
2816  k = binom(n,d);
2817  l = k*d;
2818  l /= n-d+1;
2819  result =mpNew(l,k);
2820  col = 1;
2821  idInitChoise(d,1,n,&bo,choise);
2822  while (!bo)
2823  {
2824  sign = 1;
2825  for (l=1;l<=d;l++)
2826  {
2827  if (choise[l-1]<=IDELEMS(temp))
2828  {
2829  p = pCopy(temp->m[choise[l-1]-1]);
2830  if (sign == -1) p = pNeg(p);
2831  sign *= -1;
2832  row = idGetNumberOfChoise(l-1,d,1,n,choise);
2833  MATELEM(result,row,col) = p;
2834  }
2835  }
2836  col++;
2837  idGetNextChoise(d,n,&bo,choise);
2838  }
2839  if (id==NULL) idDelete(&temp);
2840 
2841  res->data=(char *)result;
2842  return FALSE;
2843 }
2844 
2845 // from syz1.cc
2846 /*2
2847 * read out the Betti numbers from resolution
2848 * (interpreter interface)
2849 */
2851 {
2852  syStrategy syzstr=(syStrategy)u->Data();
2853 
2854  BOOLEAN minim=(int)(long)w->Data();
2855  int row_shift=0;
2856  int add_row_shift=0;
2857  intvec *weights=NULL;
2858  intvec *ww=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
2859  if (ww!=NULL)
2860  {
2861  weights=ivCopy(ww);
2862  add_row_shift = ww->min_in();
2863  (*weights) -= add_row_shift;
2864  }
2865 
2866  res->data=(void *)syBettiOfComputation(syzstr,minim,&row_shift,weights);
2867  //row_shift += add_row_shift;
2868  //Print("row_shift=%d, add_row_shift=%d\n",row_shift,add_row_shift);
2869  atSet(res,omStrDup("rowShift"),(void*)(long)add_row_shift,INT_CMD);
2870 
2871  return FALSE;
2872 }
2874 {
2875  sleftv tmp;
2876  memset(&tmp,0,sizeof(tmp));
2877  tmp.rtyp=INT_CMD;
2878  tmp.data=(void *)1;
2879  return syBetti2(res,u,&tmp);
2880 }
2881 
2882 /*3
2883 * converts a resolution into a list of modules
2884 */
2885 lists syConvRes(syStrategy syzstr,BOOLEAN toDel,int add_row_shift)
2886 {
2887  resolvente fullres = syzstr->fullres;
2888  resolvente minres = syzstr->minres;
2889 
2890  const int length = syzstr->length;
2891 
2892  if ((fullres==NULL) && (minres==NULL))
2893  {
2894  if (syzstr->hilb_coeffs==NULL)
2895  { // La Scala
2896  fullres = syReorder(syzstr->res, length, syzstr);
2897  }
2898  else
2899  { // HRES
2900  minres = syReorder(syzstr->orderedRes, length, syzstr);
2901  syKillEmptyEntres(minres, length);
2902  }
2903  }
2904 
2905  resolvente tr;
2906  int typ0=IDEAL_CMD;
2907 
2908  if (minres!=NULL)
2909  tr = minres;
2910  else
2911  tr = fullres;
2912 
2913  resolvente trueres=NULL; intvec ** w=NULL;
2914 
2915  if (length>0)
2916  {
2917  trueres = (resolvente)omAlloc0((length)*sizeof(ideal));
2918  for (int i=(length)-1;i>=0;i--)
2919  {
2920  if (tr[i]!=NULL)
2921  {
2922  trueres[i] = idCopy(tr[i]);
2923  }
2924  }
2925  if ( id_RankFreeModule(trueres[0], currRing) > 0)
2926  typ0 = MODUL_CMD;
2927  if (syzstr->weights!=NULL)
2928  {
2929  w = (intvec**)omAlloc0(length*sizeof(intvec*));
2930  for (int i=length-1;i>=0;i--)
2931  {
2932  if (syzstr->weights[i]!=NULL) w[i] = ivCopy(syzstr->weights[i]);
2933  }
2934  }
2935  }
2936 
2937  lists li = liMakeResolv(trueres, length, syzstr->list_length,typ0,
2938  w, add_row_shift);
2939 
2940  if (w != NULL) omFreeSize(w, length*sizeof(intvec*));
2941 
2942  if (toDel)
2943  syKillComputation(syzstr);
2944  else
2945  {
2946  if( fullres != NULL && syzstr->fullres == NULL )
2947  syzstr->fullres = fullres;
2948 
2949  if( minres != NULL && syzstr->minres == NULL )
2950  syzstr->minres = minres;
2951  }
2952 
2953  return li;
2954 
2955 
2956 }
2957 
2958 /*3
2959 * converts a list of modules into a resolution
2960 */
2962 {
2963  int typ0;
2965 
2966  resolvente fr = liFindRes(li,&(result->length),&typ0,&(result->weights));
2967  if (fr != NULL)
2968  {
2969 
2970  result->fullres = (resolvente)omAlloc0((result->length+1)*sizeof(ideal));
2971  for (int i=result->length-1;i>=0;i--)
2972  {
2973  if (fr[i]!=NULL)
2974  result->fullres[i] = idCopy(fr[i]);
2975  }
2976  result->list_length=result->length;
2977  omFreeSize((ADDRESS)fr,(result->length)*sizeof(ideal));
2978  }
2979  else
2980  {
2981  omFreeSize(result, sizeof(ssyStrategy));
2982  result = NULL;
2983  }
2984  if (toDel) li->Clean();
2985  return result;
2986 }
2987 
2988 /*3
2989 * converts a list of modules into a minimal resolution
2990 */
2992 {
2993  int typ0;
2995 
2996  resolvente fr = liFindRes(li,&(result->length),&typ0);
2997  result->minres = (resolvente)omAlloc0((result->length+1)*sizeof(ideal));
2998  for (int i=result->length-1;i>=0;i--)
2999  {
3000  if (fr[i]!=NULL)
3001  result->minres[i] = idCopy(fr[i]);
3002  }
3003  omFreeSize((ADDRESS)fr,(result->length)*sizeof(ideal));
3004  return result;
3005 }
3006 // from weight.cc
3008 {
3009  ideal F=(ideal)id->Data();
3010  intvec * iv = new intvec(rVar(currRing));
3011  polyset s;
3012  int sl, n, i;
3013  int *x;
3014 
3015  res->data=(char *)iv;
3016  s = F->m;
3017  sl = IDELEMS(F) - 1;
3018  n = rVar(currRing);
3019  double wNsqr = (double)2.0 / (double)n;
3021  x = (int * )omAlloc(2 * (n + 1) * sizeof(int));
3022  wCall(s, sl, x, wNsqr, currRing);
3023  for (i = n; i!=0; i--)
3024  (*iv)[i-1] = x[i + n + 1];
3025  omFreeSize((ADDRESS)x, 2 * (n + 1) * sizeof(int));
3026  return FALSE;
3027 }
3028 
3030 {
3031  res->data=(char *)id_QHomWeight((ideal)v->Data(), currRing);
3032  if (res->data==NULL)
3033  res->data=(char *)new intvec(rVar(currRing));
3034  return FALSE;
3035 }
3036 /*==============================================================*/
3037 // from clapsing.cc
3038 #if 0
3039 BOOLEAN jjIS_SQR_FREE(leftv res, leftv u)
3040 {
3041  BOOLEAN b=singclap_factorize((poly)(u->CopyD()), &v, 0);
3042  res->data=(void *)b;
3043 }
3044 #endif
3045 
3047 {
3048  res->data=singclap_resultant((poly)u->CopyD(),(poly)v->CopyD(),
3049  (poly)w->CopyD(), currRing);
3050  return errorreported;
3051 }
3052 
3054 {
3056  return (res->data==NULL);
3057 }
3058 
3059 // from semic.cc
3060 #ifdef HAVE_SPECTRUM
3061 
3062 // ----------------------------------------------------------------------------
3063 // Initialize a spectrum deep from a singular lists
3064 // ----------------------------------------------------------------------------
3065 
3066 void copy_deep( spectrum& spec, lists l )
3067 {
3068  spec.mu = (int)(long)(l->m[0].Data( ));
3069  spec.pg = (int)(long)(l->m[1].Data( ));
3070  spec.n = (int)(long)(l->m[2].Data( ));
3071 
3072  spec.copy_new( spec.n );
3073 
3074  intvec *num = (intvec*)l->m[3].Data( );
3075  intvec *den = (intvec*)l->m[4].Data( );
3076  intvec *mul = (intvec*)l->m[5].Data( );
3077 
3078  for( int i=0; i<spec.n; i++ )
3079  {
3080  spec.s[i] = (Rational)((*num)[i])/(Rational)((*den)[i]);
3081  spec.w[i] = (*mul)[i];
3082  }
3083 }
3084 
3085 // ----------------------------------------------------------------------------
3086 // singular lists constructor for spectrum
3087 // ----------------------------------------------------------------------------
3088 
3089 spectrum /*former spectrum::spectrum ( lists l )*/
3091 {
3092  spectrum result;
3093  copy_deep( result, l );
3094  return result;
3095 }
3096 
3097 // ----------------------------------------------------------------------------
3098 // generate a Singular lists from a spectrum
3099 // ----------------------------------------------------------------------------
3100 
3101 /* former spectrum::thelist ( void )*/
3103 {
3105 
3106  L->Init( 6 );
3107 
3108  intvec *num = new intvec( spec.n );
3109  intvec *den = new intvec( spec.n );
3110  intvec *mult = new intvec( spec.n );
3111 
3112  for( int i=0; i<spec.n; i++ )
3113  {
3114  (*num) [i] = spec.s[i].get_num_si( );
3115  (*den) [i] = spec.s[i].get_den_si( );
3116  (*mult)[i] = spec.w[i];
3117  }
3118 
3119  L->m[0].rtyp = INT_CMD; // milnor number
3120  L->m[1].rtyp = INT_CMD; // geometrical genus
3121  L->m[2].rtyp = INT_CMD; // # of spectrum numbers
3122  L->m[3].rtyp = INTVEC_CMD; // numerators
3123  L->m[4].rtyp = INTVEC_CMD; // denomiantors
3124  L->m[5].rtyp = INTVEC_CMD; // multiplicities
3125 
3126  L->m[0].data = (void*)(long)spec.mu;
3127  L->m[1].data = (void*)(long)spec.pg;
3128  L->m[2].data = (void*)(long)spec.n;
3129  L->m[3].data = (void*)num;
3130  L->m[4].data = (void*)den;
3131  L->m[5].data = (void*)mult;
3132 
3133  return L;
3134 }
3135 // from spectrum.cc
3136 // ----------------------------------------------------------------------------
3137 // print out an error message for a spectrum list
3138 // ----------------------------------------------------------------------------
3139 
3140 typedef enum
3141 {
3144 
3147 
3154 
3159 
3165 
3168 
3171 
3172 } semicState;
3173 
3174 void list_error( semicState state )
3175 {
3176  switch( state )
3177  {
3178  case semicListTooShort:
3179  WerrorS( "the list is too short" );
3180  break;
3181  case semicListTooLong:
3182  WerrorS( "the list is too long" );
3183  break;
3184 
3186  WerrorS( "first element of the list should be int" );
3187  break;
3189  WerrorS( "second element of the list should be int" );
3190  break;
3192  WerrorS( "third element of the list should be int" );
3193  break;
3195  WerrorS( "fourth element of the list should be intvec" );
3196  break;
3198  WerrorS( "fifth element of the list should be intvec" );
3199  break;
3201  WerrorS( "sixth element of the list should be intvec" );
3202  break;
3203 
3204  case semicListNNegative:
3205  WerrorS( "first element of the list should be positive" );
3206  break;
3208  WerrorS( "wrong number of numerators" );
3209  break;
3211  WerrorS( "wrong number of denominators" );
3212  break;
3214  WerrorS( "wrong number of multiplicities" );
3215  break;
3216 
3217  case semicListMuNegative:
3218  WerrorS( "the Milnor number should be positive" );
3219  break;
3220  case semicListPgNegative:
3221  WerrorS( "the geometrical genus should be nonnegative" );
3222  break;
3223  case semicListNumNegative:
3224  WerrorS( "all numerators should be positive" );
3225  break;
3226  case semicListDenNegative:
3227  WerrorS( "all denominators should be positive" );
3228  break;
3229  case semicListMulNegative:
3230  WerrorS( "all multiplicities should be positive" );
3231  break;
3232 
3233  case semicListNotSymmetric:
3234  WerrorS( "it is not symmetric" );
3235  break;
3237  WerrorS( "it is not monotonous" );
3238  break;
3239 
3240  case semicListMilnorWrong:
3241  WerrorS( "the Milnor number is wrong" );
3242  break;
3243  case semicListPGWrong:
3244  WerrorS( "the geometrical genus is wrong" );
3245  break;
3246 
3247  default:
3248  WerrorS( "unspecific error" );
3249  break;
3250  }
3251 }
3252 // ----------------------------------------------------------------------------
3253 // this is the main spectrum computation function
3254 // ----------------------------------------------------------------------------
3255 
3257 {
3267 };
3268 
3269 // from splist.cc
3270 // ----------------------------------------------------------------------------
3271 // Compute the spectrum of a spectrumPolyList
3272 // ----------------------------------------------------------------------------
3273 
3274 /* former spectrumPolyList::spectrum ( lists*, int) */
3276 {
3277  spectrumPolyNode **node = &speclist.root;
3279 
3280  poly f,tmp;
3281  int found,cmp;
3282 
3283  Rational smax( ( fast==0 ? 0 : rVar(currRing) ),
3284  ( fast==2 ? 2 : 1 ) );
3285 
3286  Rational weight_prev( 0,1 );
3287 
3288  int mu = 0; // the milnor number
3289  int pg = 0; // the geometrical genus
3290  int n = 0; // number of different spectral numbers
3291  int z = 0; // number of spectral number equal to smax
3292 
3293  while( (*node)!=(spectrumPolyNode*)NULL &&
3294  ( fast==0 || (*node)->weight<=smax ) )
3295  {
3296  // ---------------------------------------
3297  // determine the first normal form which
3298  // contains the monomial node->mon
3299  // ---------------------------------------
3300 
3301  found = FALSE;
3302  search = *node;
3303 
3304  while( search!=(spectrumPolyNode*)NULL && found==FALSE )
3305  {
3306  if( search->nf!=(poly)NULL )
3307  {
3308  f = search->nf;
3309 
3310  do
3311  {
3312  // --------------------------------
3313  // look for (*node)->mon in f
3314  // --------------------------------
3315 
3316  cmp = pCmp( (*node)->mon,f );
3317 
3318  if( cmp<0 )
3319  {
3320  f = pNext( f );
3321  }
3322  else if( cmp==0 )
3323  {
3324  // -----------------------------
3325  // we have found a normal form
3326  // -----------------------------
3327 
3328  found = TRUE;
3329 
3330  // normalize coefficient
3331 
3332  number inv = nInvers( pGetCoeff( f ) );
3333  pMult_nn( search->nf,inv );
3334  nDelete( &inv );
3335 
3336  // exchange normal forms
3337 
3338  tmp = (*node)->nf;
3339  (*node)->nf = search->nf;
3340  search->nf = tmp;
3341  }
3342  }
3343  while( cmp<0 && f!=(poly)NULL );
3344  }
3345  search = search->next;
3346  }
3347 
3348  if( found==FALSE )
3349  {
3350  // ------------------------------------------------
3351  // the weight of node->mon is a spectrum number
3352  // ------------------------------------------------
3353 
3354  mu++;
3355 
3356  if( (*node)->weight<=(Rational)1 ) pg++;
3357  if( (*node)->weight==smax ) z++;
3358  if( (*node)->weight>weight_prev ) n++;
3359 
3360  weight_prev = (*node)->weight;
3361  node = &((*node)->next);
3362  }
3363  else
3364  {
3365  // -----------------------------------------------
3366  // determine all other normal form which contain
3367  // the monomial node->mon
3368  // replace for node->mon its normal form
3369  // -----------------------------------------------
3370 
3371  while( search!=(spectrumPolyNode*)NULL )
3372  {
3373  if( search->nf!=(poly)NULL )
3374  {
3375  f = search->nf;
3376 
3377  do
3378  {
3379  // --------------------------------
3380  // look for (*node)->mon in f
3381  // --------------------------------
3382 
3383  cmp = pCmp( (*node)->mon,f );
3384 
3385  if( cmp<0 )
3386  {
3387  f = pNext( f );
3388  }
3389  else if( cmp==0 )
3390  {
3391  search->nf = pSub( search->nf,
3392  ppMult_nn( (*node)->nf,pGetCoeff( f ) ) );
3393  pNorm( search->nf );
3394  }
3395  }
3396  while( cmp<0 && f!=(poly)NULL );
3397  }
3398  search = search->next;
3399  }
3400  speclist.delete_node( node );
3401  }
3402 
3403  }
3404 
3405  // --------------------------------------------------------
3406  // fast computation exploits the symmetry of the spectrum
3407  // --------------------------------------------------------
3408 
3409  if( fast==2 )
3410  {
3411  mu = 2*mu - z;
3412  n = ( z > 0 ? 2*n - 1 : 2*n );
3413  }
3414 
3415  // --------------------------------------------------------
3416  // compute the spectrum numbers with their multiplicities
3417  // --------------------------------------------------------
3418 
3419  intvec *nom = new intvec( n );
3420  intvec *den = new intvec( n );
3421  intvec *mult = new intvec( n );
3422 
3423  int count = 0;
3424  int multiplicity = 1;
3425 
3426  for( search=speclist.root; search!=(spectrumPolyNode*)NULL &&
3427  ( fast==0 || search->weight<=smax );
3428  search=search->next )
3429  {
3430  if( search->next==(spectrumPolyNode*)NULL ||
3431  search->weight<search->next->weight )
3432  {
3433  (*nom) [count] = search->weight.get_num_si( );
3434  (*den) [count] = search->weight.get_den_si( );
3435  (*mult)[count] = multiplicity;
3436 
3437  multiplicity=1;
3438  count++;
3439  }
3440  else
3441  {
3442  multiplicity++;
3443  }
3444  }
3445 
3446  // --------------------------------------------------------
3447  // fast computation exploits the symmetry of the spectrum
3448  // --------------------------------------------------------
3449 
3450  if( fast==2 )
3451  {
3452  int n1,n2;
3453  for( n1=0, n2=n-1; n1<n2; n1++, n2-- )
3454  {
3455  (*nom) [n2] = rVar(currRing)*(*den)[n1]-(*nom)[n1];
3456  (*den) [n2] = (*den)[n1];
3457  (*mult)[n2] = (*mult)[n1];
3458  }
3459  }
3460 
3461  // -----------------------------------
3462  // test if the spectrum is symmetric
3463  // -----------------------------------
3464 
3465  if( fast==0 || fast==1 )
3466  {
3467  int symmetric=TRUE;
3468 
3469  for( int n1=0, n2=n-1 ; n1<n2 && symmetric==TRUE; n1++, n2-- )
3470  {
3471  if( (*mult)[n1]!=(*mult)[n2] ||
3472  (*den) [n1]!= (*den)[n2] ||
3473  (*nom)[n1]+(*nom)[n2]!=rVar(currRing)*(*den) [n1] )
3474  {
3475  symmetric = FALSE;
3476  }
3477  }
3478 
3479  if( symmetric==FALSE )
3480  {
3481  // ---------------------------------------------
3482  // the spectrum is not symmetric => degenerate
3483  // principal part
3484  // ---------------------------------------------
3485 
3486  *L = (lists)omAllocBin( slists_bin);
3487  (*L)->Init( 1 );
3488  (*L)->m[0].rtyp = INT_CMD; // milnor number
3489  (*L)->m[0].data = (void*)(long)mu;
3490 
3491  return spectrumDegenerate;
3492  }
3493  }
3494 
3495  *L = (lists)omAllocBin( slists_bin);
3496 
3497  (*L)->Init( 6 );
3498 
3499  (*L)->m[0].rtyp = INT_CMD; // milnor number
3500  (*L)->m[1].rtyp = INT_CMD; // geometrical genus
3501  (*L)->m[2].rtyp = INT_CMD; // number of spectrum values
3502  (*L)->m[3].rtyp = INTVEC_CMD; // nominators
3503  (*L)->m[4].rtyp = INTVEC_CMD; // denomiantors
3504  (*L)->m[5].rtyp = INTVEC_CMD; // multiplicities
3505 
3506  (*L)->m[0].data = (void*)(long)mu;
3507  (*L)->m[1].data = (void*)(long)pg;
3508  (*L)->m[2].data = (void*)(long)n;
3509  (*L)->m[3].data = (void*)nom;
3510  (*L)->m[4].data = (void*)den;
3511  (*L)->m[5].data = (void*)mult;
3512 
3513  return spectrumOK;
3514 }
3515 
3517 {
3518  int i;
3519 
3520  #ifdef SPECTRUM_DEBUG
3521  #ifdef SPECTRUM_PRINT
3522  #ifdef SPECTRUM_IOSTREAM
3523  cout << "spectrumCompute\n";
3524  if( fast==0 ) cout << " no optimization" << endl;
3525  if( fast==1 ) cout << " weight optimization" << endl;
3526  if( fast==2 ) cout << " symmetry optimization" << endl;
3527  #else
3528  fprintf( stdout,"spectrumCompute\n" );
3529  if( fast==0 ) fprintf( stdout," no optimization\n" );
3530  if( fast==1 ) fprintf( stdout," weight optimization\n" );
3531  if( fast==2 ) fprintf( stdout," symmetry optimization\n" );
3532  #endif
3533  #endif
3534  #endif
3535 
3536  // ----------------------
3537  // check if h is zero
3538  // ----------------------
3539 
3540  if( h==(poly)NULL )
3541  {
3542  return spectrumZero;
3543  }
3544 
3545  // ----------------------------------
3546  // check if h has a constant term
3547  // ----------------------------------
3548 
3549  if( hasConstTerm( h, currRing ) )
3550  {
3551  return spectrumBadPoly;
3552  }
3553 
3554  // --------------------------------
3555  // check if h has a linear term
3556  // --------------------------------
3557 
3558  if( hasLinearTerm( h, currRing ) )
3559  {
3560  *L = (lists)omAllocBin( slists_bin);
3561  (*L)->Init( 1 );
3562  (*L)->m[0].rtyp = INT_CMD; // milnor number
3563  /* (*L)->m[0].data = (void*)0;a -- done by Init */
3564 
3565  return spectrumNoSingularity;
3566  }
3567 
3568  // ----------------------------------
3569  // compute the jacobi ideal of (h)
3570  // ----------------------------------
3571 
3572  ideal J = NULL;
3573  J = idInit( rVar(currRing),1 );
3574 
3575  #ifdef SPECTRUM_DEBUG
3576  #ifdef SPECTRUM_PRINT
3577  #ifdef SPECTRUM_IOSTREAM
3578  cout << "\n computing the Jacobi ideal...\n";
3579  #else
3580  fprintf( stdout,"\n computing the Jacobi ideal...\n" );
3581  #endif
3582  #endif
3583  #endif
3584 
3585  for( i=0; i<rVar(currRing); i++ )
3586  {
3587  J->m[i] = pDiff( h,i+1); //j );
3588 
3589  #ifdef SPECTRUM_DEBUG
3590  #ifdef SPECTRUM_PRINT
3591  #ifdef SPECTRUM_IOSTREAM
3592  cout << " ";
3593  #else
3594  fprintf( stdout," " );
3595  #endif
3596  pWrite( J->m[i] );
3597  #endif
3598  #endif
3599  }
3600 
3601  // --------------------------------------------
3602  // compute a standard basis stdJ of jac(h)
3603  // --------------------------------------------
3604 
3605  #ifdef SPECTRUM_DEBUG
3606  #ifdef SPECTRUM_PRINT
3607  #ifdef SPECTRUM_IOSTREAM
3608  cout << endl;
3609  cout << " computing a standard basis..." << endl;
3610  #else
3611  fprintf( stdout,"\n" );
3612  fprintf( stdout," computing a standard basis...\n" );
3613  #endif
3614  #endif
3615  #endif
3616 
3617  ideal stdJ = kStd(J,currRing->qideal,isNotHomog,NULL);
3618  idSkipZeroes( stdJ );
3619 
3620  #ifdef SPECTRUM_DEBUG
3621  #ifdef SPECTRUM_PRINT
3622  for( i=0; i<IDELEMS(stdJ); i++ )
3623  {
3624  #ifdef SPECTRUM_IOSTREAM
3625  cout << " ";
3626  #else
3627  fprintf( stdout," " );
3628  #endif
3629 
3630  pWrite( stdJ->m[i] );
3631  }
3632  #endif
3633  #endif
3634 
3635  idDelete( &J );
3636 
3637  // ------------------------------------------
3638  // check if the h has a singularity
3639  // ------------------------------------------
3640 
3641  if( hasOne( stdJ, currRing ) )
3642  {
3643  // -------------------------------
3644  // h is smooth in the origin
3645  // return only the Milnor number
3646  // -------------------------------
3647 
3648  *L = (lists)omAllocBin( slists_bin);
3649  (*L)->Init( 1 );
3650  (*L)->m[0].rtyp = INT_CMD; // milnor number
3651  /* (*L)->m[0].data = (void*)0;a -- done by Init */
3652 
3653  return spectrumNoSingularity;
3654  }
3655 
3656  // ------------------------------------------
3657  // check if the singularity h is isolated
3658  // ------------------------------------------
3659 
3660  for( i=rVar(currRing); i>0; i-- )
3661  {
3662  if( hasAxis( stdJ,i, currRing )==FALSE )
3663  {
3664  return spectrumNotIsolated;
3665  }
3666  }
3667 
3668  // ------------------------------------------
3669  // compute the highest corner hc of stdJ
3670  // ------------------------------------------
3671 
3672  #ifdef SPECTRUM_DEBUG
3673  #ifdef SPECTRUM_PRINT
3674  #ifdef SPECTRUM_IOSTREAM
3675  cout << "\n computing the highest corner...\n";
3676  #else
3677  fprintf( stdout,"\n computing the highest corner...\n" );
3678  #endif
3679  #endif
3680  #endif
3681 
3682  poly hc = (poly)NULL;
3683 
3684  scComputeHC( stdJ,currRing->qideal, 0,hc );
3685 
3686  if( hc!=(poly)NULL )
3687  {
3688  pGetCoeff(hc) = nInit(1);
3689 
3690  for( i=rVar(currRing); i>0; i-- )
3691  {
3692  if( pGetExp( hc,i )>0 ) pDecrExp( hc,i );
3693  }
3694  pSetm( hc );
3695  }
3696  else
3697  {
3698  return spectrumNoHC;
3699  }
3700 
3701  #ifdef SPECTRUM_DEBUG
3702  #ifdef SPECTRUM_PRINT
3703  #ifdef SPECTRUM_IOSTREAM
3704  cout << " ";
3705  #else
3706  fprintf( stdout," " );
3707  #endif
3708  pWrite( hc );
3709  #endif
3710  #endif
3711 
3712  // ----------------------------------------
3713  // compute the Newton polygon nph of h
3714  // ----------------------------------------
3715 
3716  #ifdef SPECTRUM_DEBUG
3717  #ifdef SPECTRUM_PRINT
3718  #ifdef SPECTRUM_IOSTREAM
3719  cout << "\n computing the newton polygon...\n";
3720  #else
3721  fprintf( stdout,"\n computing the newton polygon...\n" );
3722  #endif
3723  #endif
3724  #endif
3725 
3726  newtonPolygon nph( h, currRing );
3727 
3728  #ifdef SPECTRUM_DEBUG
3729  #ifdef SPECTRUM_PRINT
3730  cout << nph;
3731  #endif
3732  #endif
3733 
3734  // -----------------------------------------------
3735  // compute the weight corner wc of (stdj,nph)
3736  // -----------------------------------------------
3737 
3738  #ifdef SPECTRUM_DEBUG
3739  #ifdef SPECTRUM_PRINT
3740  #ifdef SPECTRUM_IOSTREAM
3741  cout << "\n computing the weight corner...\n";
3742  #else
3743  fprintf( stdout,"\n computing the weight corner...\n" );
3744  #endif
3745  #endif
3746  #endif
3747 
3748  poly wc = ( fast==0 ? pCopy( hc ) :
3749  ( fast==1 ? computeWC( nph,(Rational)rVar(currRing), currRing ) :
3750  /* fast==2 */computeWC( nph,
3751  ((Rational)rVar(currRing))/(Rational)2, currRing ) ) );
3752 
3753  #ifdef SPECTRUM_DEBUG
3754  #ifdef SPECTRUM_PRINT
3755  #ifdef SPECTRUM_IOSTREAM
3756  cout << " ";
3757  #else
3758  fprintf( stdout," " );
3759  #endif
3760  pWrite( wc );
3761  #endif
3762  #endif
3763 
3764  // -------------
3765  // compute NF
3766  // -------------
3767 
3768  #ifdef SPECTRUM_DEBUG
3769  #ifdef SPECTRUM_PRINT
3770  #ifdef SPECTRUM_IOSTREAM
3771  cout << "\n computing NF...\n" << endl;
3772  #else
3773  fprintf( stdout,"\n computing NF...\n" );
3774  #endif
3775  #endif
3776  #endif
3777 
3778  spectrumPolyList NF( &nph );
3779 
3780  computeNF( stdJ,hc,wc,&NF, currRing );
3781 
3782  #ifdef SPECTRUM_DEBUG
3783  #ifdef SPECTRUM_PRINT
3784  cout << NF;
3785  #ifdef SPECTRUM_IOSTREAM
3786  cout << endl;
3787  #else
3788  fprintf( stdout,"\n" );
3789  #endif
3790  #endif
3791  #endif
3792 
3793  // ----------------------------
3794  // compute the spectrum of h
3795  // ----------------------------
3796 // spectrumState spectrumStateFromList( spectrumPolyList& speclist, lists *L, int fast );
3797 
3798  return spectrumStateFromList(NF, L, fast );
3799 }
3800 
3801 // ----------------------------------------------------------------------------
3802 // this procedure is called from the interpreter
3803 // ----------------------------------------------------------------------------
3804 // first = polynomial
3805 // result = list of spectrum numbers
3806 // ----------------------------------------------------------------------------
3807 
3809 {
3810  switch( state )
3811  {
3812  case spectrumZero:
3813  WerrorS( "polynomial is zero" );
3814  break;
3815  case spectrumBadPoly:
3816  WerrorS( "polynomial has constant term" );
3817  break;
3818  case spectrumNoSingularity:
3819  WerrorS( "not a singularity" );
3820  break;
3821  case spectrumNotIsolated:
3822  WerrorS( "the singularity is not isolated" );
3823  break;
3824  case spectrumNoHC:
3825  WerrorS( "highest corner cannot be computed" );
3826  break;
3827  case spectrumDegenerate:
3828  WerrorS( "principal part is degenerate" );
3829  break;
3830  case spectrumOK:
3831  break;
3832 
3833  default:
3834  WerrorS( "unknown error occurred" );
3835  break;
3836  }
3837 }
3838 
3840 {
3841  spectrumState state = spectrumOK;
3842 
3843  // -------------------
3844  // check consistency
3845  // -------------------
3846 
3847  // check for a local ring
3848 
3849  if( !ringIsLocal(currRing ) )
3850  {
3851  WerrorS( "only works for local orderings" );
3852  state = spectrumWrongRing;
3853  }
3854 
3855  // no quotient rings are allowed
3856 
3857  else if( currRing->qideal != NULL )
3858  {
3859  WerrorS( "does not work in quotient rings" );
3860  state = spectrumWrongRing;
3861  }
3862  else
3863  {
3864  lists L = (lists)NULL;
3865  int flag = 1; // weight corner optimization is safe
3866 
3867  state = spectrumCompute( (poly)first->Data( ),&L,flag );
3868 
3869  if( state==spectrumOK )
3870  {
3871  result->rtyp = LIST_CMD;
3872  result->data = (char*)L;
3873  }
3874  else
3875  {
3876  spectrumPrintError(state);
3877  }
3878  }
3879 
3880  return (state!=spectrumOK);
3881 }
3882 
3883 // ----------------------------------------------------------------------------
3884 // this procedure is called from the interpreter
3885 // ----------------------------------------------------------------------------
3886 // first = polynomial
3887 // result = list of spectrum numbers
3888 // ----------------------------------------------------------------------------
3889 
3891 {
3892  spectrumState state = spectrumOK;
3893 
3894  // -------------------
3895  // check consistency
3896  // -------------------
3897 
3898  // check for a local polynomial ring
3899 
3900  if( currRing->OrdSgn != -1 )
3901  // ?? HS: the test above is also true for k[x][[y]], k[[x]][y]
3902  // or should we use:
3903  //if( !ringIsLocal( ) )
3904  {
3905  WerrorS( "only works for local orderings" );
3906  state = spectrumWrongRing;
3907  }
3908  else if( currRing->qideal != NULL )
3909  {
3910  WerrorS( "does not work in quotient rings" );
3911  state = spectrumWrongRing;
3912  }
3913  else
3914  {
3915  lists L = (lists)NULL;
3916  int flag = 2; // symmetric optimization
3917 
3918  state = spectrumCompute( (poly)first->Data( ),&L,flag );
3919 
3920  if( state==spectrumOK )
3921  {
3922  result->rtyp = LIST_CMD;
3923  result->data = (char*)L;
3924  }
3925  else
3926  {
3927  spectrumPrintError(state);
3928  }
3929  }
3930 
3931  return (state!=spectrumOK);
3932 }
3933 
3934 // ----------------------------------------------------------------------------
3935 // check if a list is a spectrum
3936 // check for:
3937 // list has 6 elements
3938 // 1st element is int (mu=Milnor number)
3939 // 2nd element is int (pg=geometrical genus)
3940 // 3rd element is int (n =number of different spectrum numbers)
3941 // 4th element is intvec (num=numerators)
3942 // 5th element is intvec (den=denomiantors)
3943 // 6th element is intvec (mul=multiplicities)
3944 // exactly n numerators
3945 // exactly n denominators
3946 // exactly n multiplicities
3947 // mu>0
3948 // pg>=0
3949 // n>0
3950 // num>0
3951 // den>0
3952 // mul>0
3953 // symmetriy with respect to numberofvariables/2
3954 // monotony
3955 // mu = sum of all multiplicities
3956 // pg = sum of all multiplicities where num/den<=1
3957 // ----------------------------------------------------------------------------
3958 
3960 {
3961  // -------------------
3962  // check list length
3963  // -------------------
3964 
3965  if( l->nr < 5 )
3966  {
3967  return semicListTooShort;
3968  }
3969  else if( l->nr > 5 )
3970  {
3971  return semicListTooLong;
3972  }
3973 
3974  // -------------
3975  // check types
3976  // -------------
3977 
3978  if( l->m[0].rtyp != INT_CMD )
3979  {
3981  }
3982  else if( l->m[1].rtyp != INT_CMD )
3983  {
3985  }
3986  else if( l->m[2].rtyp != INT_CMD )
3987  {
3989  }
3990  else if( l->m[3].rtyp != INTVEC_CMD )
3991  {
3993  }
3994  else if( l->m[4].rtyp != INTVEC_CMD )
3995  {
3997  }
3998  else if( l->m[5].rtyp != INTVEC_CMD )
3999  {
4001  }
4002 
4003  // -------------------------
4004  // check number of entries
4005  // -------------------------
4006 
4007  int mu = (int)(long)(l->m[0].Data( ));
4008  int pg = (int)(long)(l->m[1].Data( ));
4009  int n = (int)(long)(l->m[2].Data( ));
4010 
4011  if( n <= 0 )
4012  {
4013  return semicListNNegative;
4014  }
4015 
4016  intvec *num = (intvec*)l->m[3].Data( );
4017  intvec *den = (intvec*)l->m[4].Data( );
4018  intvec *mul = (intvec*)l->m[5].Data( );
4019 
4020  if( n != num->length( ) )
4021  {
4023  }
4024  else if( n != den->length( ) )
4025  {
4027  }
4028  else if( n != mul->length( ) )
4029  {
4031  }
4032 
4033  // --------
4034  // values
4035  // --------
4036 
4037  if( mu <= 0 )
4038  {
4039  return semicListMuNegative;
4040  }
4041  if( pg < 0 )
4042  {
4043  return semicListPgNegative;
4044  }
4045 
4046  int i;
4047 
4048  for( i=0; i<n; i++ )
4049  {
4050  if( (*num)[i] <= 0 )
4051  {
4052  return semicListNumNegative;
4053  }
4054  if( (*den)[i] <= 0 )
4055  {
4056  return semicListDenNegative;
4057  }
4058  if( (*mul)[i] <= 0 )
4059  {
4060  return semicListMulNegative;
4061  }
4062  }
4063 
4064  // ----------------
4065  // check symmetry
4066  // ----------------
4067 
4068  int j;
4069 
4070  for( i=0, j=n-1; i<=j; i++,j-- )
4071  {
4072  if( (*num)[i] != rVar(currRing)*((*den)[i]) - (*num)[j] ||
4073  (*den)[i] != (*den)[j] ||
4074  (*mul)[i] != (*mul)[j] )
4075  {
4076  return semicListNotSymmetric;
4077  }
4078  }
4079 
4080  // ----------------
4081  // check monotony
4082  // ----------------
4083 
4084  for( i=0, j=1; i<n/2; i++,j++ )
4085  {
4086  if( (*num)[i]*(*den)[j] >= (*num)[j]*(*den)[i] )
4087  {
4088  return semicListNotMonotonous;
4089  }
4090  }
4091 
4092  // ---------------------
4093  // check Milnor number
4094  // ---------------------
4095 
4096  for( mu=0, i=0; i<n; i++ )
4097  {
4098  mu += (*mul)[i];
4099  }
4100 
4101  if( mu != (int)(long)(l->m[0].Data( )) )
4102  {
4103  return semicListMilnorWrong;
4104  }
4105 
4106  // -------------------------
4107  // check geometrical genus
4108  // -------------------------
4109 
4110  for( pg=0, i=0; i<n; i++ )
4111  {
4112  if( (*num)[i]<=(*den)[i] )
4113  {
4114  pg += (*mul)[i];
4115  }
4116  }
4117 
4118  if( pg != (int)(long)(l->m[1].Data( )) )
4119  {
4120  return semicListPGWrong;
4121  }
4122 
4123  return semicOK;
4124 }
4125 
4126 // ----------------------------------------------------------------------------
4127 // this procedure is called from the interpreter
4128 // ----------------------------------------------------------------------------
4129 // first = list of spectrum numbers
4130 // second = list of spectrum numbers
4131 // result = sum of the two lists
4132 // ----------------------------------------------------------------------------
4133 
4135 {
4136  semicState state;
4137 
4138  // -----------------
4139  // check arguments
4140  // -----------------
4141 
4142  lists l1 = (lists)first->Data( );
4143  lists l2 = (lists)second->Data( );
4144 
4145  if( (state=list_is_spectrum( l1 )) != semicOK )
4146  {
4147  WerrorS( "first argument is not a spectrum:" );
4148  list_error( state );
4149  }
4150  else if( (state=list_is_spectrum( l2 )) != semicOK )
4151  {
4152  WerrorS( "second argument is not a spectrum:" );
4153  list_error( state );
4154  }
4155  else
4156  {
4157  spectrum s1= spectrumFromList ( l1 );
4158  spectrum s2= spectrumFromList ( l2 );
4159  spectrum sum( s1+s2 );
4160 
4161  result->rtyp = LIST_CMD;
4162  result->data = (char*)(getList(sum));
4163  }
4164 
4165  return (state!=semicOK);
4166 }
4167 
4168 // ----------------------------------------------------------------------------
4169 // this procedure is called from the interpreter
4170 // ----------------------------------------------------------------------------
4171 // first = list of spectrum numbers
4172 // second = integer
4173 // result = the multiple of the first list by the second factor
4174 // ----------------------------------------------------------------------------
4175 
4177 {
4178  semicState state;
4179 
4180  // -----------------
4181  // check arguments
4182  // -----------------
4183 
4184  lists l = (lists)first->Data( );
4185  int k = (int)(long)second->Data( );
4186 
4187  if( (state=list_is_spectrum( l ))!=semicOK )
4188  {
4189  WerrorS( "first argument is not a spectrum" );
4190  list_error( state );
4191  }
4192  else if( k < 0 )
4193  {
4194  WerrorS( "second argument should be positive" );
4195  state = semicMulNegative;
4196  }
4197  else
4198  {
4199  spectrum s= spectrumFromList( l );
4200  spectrum product( k*s );
4201 
4202  result->rtyp = LIST_CMD;
4203  result->data = (char*)getList(product);
4204  }
4205 
4206  return (state!=semicOK);
4207 }
4208 
4209 // ----------------------------------------------------------------------------
4210 // this procedure is called from the interpreter
4211 // ----------------------------------------------------------------------------
4212 // first = list of spectrum numbers
4213 // second = list of spectrum numbers
4214 // result = semicontinuity index
4215 // ----------------------------------------------------------------------------
4216 
4218 {
4219  semicState state;
4220  BOOLEAN qh=(((int)(long)w->Data())==1);
4221 
4222  // -----------------
4223  // check arguments
4224  // -----------------
4225 
4226  lists l1 = (lists)u->Data( );
4227  lists l2 = (lists)v->Data( );
4228 
4229  if( (state=list_is_spectrum( l1 ))!=semicOK )
4230  {
4231  WerrorS( "first argument is not a spectrum" );
4232  list_error( state );
4233  }
4234  else if( (state=list_is_spectrum( l2 ))!=semicOK )
4235  {
4236  WerrorS( "second argument is not a spectrum" );
4237  list_error( state );
4238  }
4239  else
4240  {
4241  spectrum s1= spectrumFromList( l1 );
4242  spectrum s2= spectrumFromList( l2 );
4243 
4244  res->rtyp = INT_CMD;
4245  if (qh)
4246  res->data = (void*)(long)(s1.mult_spectrumh( s2 ));
4247  else
4248  res->data = (void*)(long)(s1.mult_spectrum( s2 ));
4249  }
4250 
4251  // -----------------
4252  // check status
4253  // -----------------
4254 
4255  return (state!=semicOK);
4256 }
4258 {
4259  sleftv tmp;
4260  memset(&tmp,0,sizeof(tmp));
4261  tmp.rtyp=INT_CMD;
4262  /* tmp.data = (void *)0; -- done by memset */
4263 
4264  return semicProc3(res,u,v,&tmp);
4265 }
4266 
4267 #endif
4268 
4270 {
4271  res->data= (void*)loNewtonPolytope( (ideal)arg1->Data() );
4272  return FALSE;
4273 }
4274 
4276 {
4277  if ( !(rField_is_long_R(currRing)) )
4278  {
4279  WerrorS("Ground field not implemented!");
4280  return TRUE;
4281  }
4282 
4283  simplex * LP;
4284  matrix m;
4285 
4286  leftv v= args;
4287  if ( v->Typ() != MATRIX_CMD ) // 1: matrix
4288  return TRUE;
4289  else
4290  m= (matrix)(v->CopyD());
4291 
4292  LP = new simplex(MATROWS(m),MATCOLS(m));
4293  LP->mapFromMatrix(m);
4294 
4295  v= v->next;
4296  if ( v->Typ() != INT_CMD ) // 2: m = number of constraints
4297  return TRUE;
4298  else
4299  LP->m= (int)(long)(v->Data());
4300 
4301  v= v->next;
4302  if ( v->Typ() != INT_CMD ) // 3: n = number of variables
4303  return TRUE;
4304  else
4305  LP->n= (int)(long)(v->Data());
4306 
4307  v= v->next;
4308  if ( v->Typ() != INT_CMD ) // 4: m1 = number of <= constraints
4309  return TRUE;
4310  else
4311  LP->m1= (int)(long)(v->Data());
4312 
4313  v= v->next;
4314  if ( v->Typ() != INT_CMD ) // 5: m2 = number of >= constraints
4315  return TRUE;
4316  else
4317  LP->m2= (int)(long)(v->Data());
4318 
4319  v= v->next;
4320  if ( v->Typ() != INT_CMD ) // 6: m3 = number of == constraints
4321  return TRUE;
4322  else
4323  LP->m3= (int)(long)(v->Data());
4324 
4325 #ifdef mprDEBUG_PROT
4326  Print("m (constraints) %d\n",LP->m);
4327  Print("n (columns) %d\n",LP->n);
4328  Print("m1 (<=) %d\n",LP->m1);
4329  Print("m2 (>=) %d\n",LP->m2);
4330  Print("m3 (==) %d\n",LP->m3);
4331 #endif
4332 
4333  LP->compute();
4334 
4335  lists lres= (lists)omAlloc( sizeof(slists) );
4336  lres->Init( 6 );
4337 
4338  lres->m[0].rtyp= MATRIX_CMD; // output matrix
4339  lres->m[0].data=(void*)LP->mapToMatrix(m);
4340 
4341  lres->m[1].rtyp= INT_CMD; // found a solution?
4342  lres->m[1].data=(void*)(long)LP->icase;
4343 
4344  lres->m[2].rtyp= INTVEC_CMD;
4345  lres->m[2].data=(void*)LP->posvToIV();
4346 
4347  lres->m[3].rtyp= INTVEC_CMD;
4348  lres->m[3].data=(void*)LP->zrovToIV();
4349 
4350  lres->m[4].rtyp= INT_CMD;
4351  lres->m[4].data=(void*)(long)LP->m;
4352 
4353  lres->m[5].rtyp= INT_CMD;
4354  lres->m[5].data=(void*)(long)LP->n;
4355 
4356  res->data= (void*)lres;
4357 
4358  return FALSE;
4359 }
4360 
4361 BOOLEAN nuMPResMat( leftv res, leftv arg1, leftv arg2 )
4362 {
4363  ideal gls = (ideal)(arg1->Data());
4364  int imtype= (int)(long)arg2->Data();
4365 
4366  uResultant::resMatType mtype= determineMType( imtype );
4367 
4368  // check input ideal ( = polynomial system )
4369  if ( mprIdealCheck( gls, arg1->Name(), mtype, true ) != mprOk )
4370  {
4371  return TRUE;
4372  }
4373 
4374  uResultant *resMat= new uResultant( gls, mtype, false );
4375  if (resMat!=NULL)
4376  {
4377  res->rtyp = MODUL_CMD;
4378  res->data= (void*)resMat->accessResMat()->getMatrix();
4379  if (!errorreported) delete resMat;
4380  }
4381  return errorreported;
4382 }
4383 
4384 BOOLEAN nuLagSolve( leftv res, leftv arg1, leftv arg2, leftv arg3 )
4385 {
4386 
4387  poly gls;
4388  gls= (poly)(arg1->Data());
4389  int howclean= (int)(long)arg3->Data();
4390 
4391  if ( !(rField_is_R(currRing) ||
4392  rField_is_Q(currRing) ||
4395  {
4396  WerrorS("Ground field not implemented!");
4397  return TRUE;
4398  }
4399 
4402  {
4403  unsigned long int ii = (unsigned long int)arg2->Data();
4404  setGMPFloatDigits( ii, ii );
4405  }
4406 
4407  if ( gls == NULL || pIsConstant( gls ) )
4408  {
4409  WerrorS("Input polynomial is constant!");
4410  return TRUE;
4411  }
4412 
4413  int ldummy;
4414  int deg= currRing->pLDeg( gls, &ldummy, currRing );
4415  // int deg= pDeg( gls );
4416  // int len= pLength( gls );
4417  int i,vpos=0;
4418  poly piter;
4419  lists elist;
4420  lists rlist;
4421 
4422  elist= (lists)omAlloc( sizeof(slists) );
4423  elist->Init( 0 );
4424 
4425  if ( rVar(currRing) > 1 )
4426  {
4427  piter= gls;
4428  for ( i= 1; i <= rVar(currRing); i++ )
4429  if ( pGetExp( piter, i ) )
4430  {
4431  vpos= i;
4432  break;
4433  }
4434  while ( piter )
4435  {
4436  for ( i= 1; i <= rVar(currRing); i++ )
4437  if ( (vpos != i) && (pGetExp( piter, i ) != 0) )
4438  {
4439  WerrorS("The input polynomial must be univariate!");
4440  return TRUE;
4441  }
4442  pIter( piter );
4443  }
4444  }
4445 
4446  rootContainer * roots= new rootContainer();
4447  number * pcoeffs= (number *)omAlloc( (deg+1) * sizeof( number ) );
4448  piter= gls;
4449  for ( i= deg; i >= 0; i-- )
4450  {
4451  //if ( piter ) Print("deg %d, pDeg(piter) %d\n",i,pTotaldegree(piter));
4452  if ( piter && pTotaldegree(piter) == i )
4453  {
4454  pcoeffs[i]= nCopy( pGetCoeff( piter ) );
4455  //nPrint( pcoeffs[i] );PrintS(" ");
4456  pIter( piter );
4457  }
4458  else
4459  {
4460  pcoeffs[i]= nInit(0);
4461  }
4462  }
4463 
4464 #ifdef mprDEBUG_PROT
4465  for (i=deg; i >= 0; i--)
4466  {
4467  nPrint( pcoeffs[i] );PrintS(" ");
4468  }
4469  PrintLn();
4470 #endif
4471 
4472  roots->fillContainer( pcoeffs, NULL, 1, deg, rootContainer::onepoly, 1 );
4473  roots->solver( howclean );
4474 
4475  int elem= roots->getAnzRoots();
4476  char *dummy;
4477  int j;
4478 
4479  rlist= (lists)omAlloc( sizeof(slists) );
4480  rlist->Init( elem );
4481 
4483  {
4484  for ( j= 0; j < elem; j++ )
4485  {
4486  rlist->m[j].rtyp=NUMBER_CMD;
4487  rlist->m[j].data=(void *)nCopy((number)(roots->getRoot(j)));
4488  //rlist->m[j].data=(void *)(number)(roots->getRoot(j));
4489  }
4490  }
4491  else
4492  {
4493  for ( j= 0; j < elem; j++ )
4494  {
4495  dummy = complexToStr( (*roots)[j], gmp_output_digits, currRing->cf );
4496  rlist->m[j].rtyp=STRING_CMD;
4497  rlist->m[j].data=(void *)dummy;
4498  }
4499  }
4500 
4501  elist->Clean();
4502  //omFreeSize( (ADDRESS) elist, sizeof(slists) );
4503 
4504  // this is (via fillContainer) the same data as in root
4505  //for ( i= deg; i >= 0; i-- ) nDelete( &pcoeffs[i] );
4506  //omFreeSize( (ADDRESS) pcoeffs, (deg+1) * sizeof( number ) );
4507 
4508  delete roots;
4509 
4510  res->rtyp= LIST_CMD;
4511  res->data= (void*)rlist;
4512 
4513  return FALSE;
4514 }
4515 
4516 BOOLEAN nuVanderSys( leftv res, leftv arg1, leftv arg2, leftv arg3)
4517 {
4518  int i;
4519  ideal p,w;
4520  p= (ideal)arg1->Data();
4521  w= (ideal)arg2->Data();
4522 
4523  // w[0] = f(p^0)
4524  // w[1] = f(p^1)
4525  // ...
4526  // p can be a vector of numbers (multivariate polynom)
4527  // or one number (univariate polynom)
4528  // tdg = deg(f)
4529 
4530  int n= IDELEMS( p );
4531  int m= IDELEMS( w );
4532  int tdg= (int)(long)arg3->Data();
4533 
4534  res->data= (void*)NULL;
4535 
4536  // check the input
4537  if ( tdg < 1 )
4538  {
4539  WerrorS("Last input parameter must be > 0!");
4540  return TRUE;
4541  }
4542  if ( n != rVar(currRing) )
4543  {
4544  Werror("Size of first input ideal must be equal to %d!",rVar(currRing));
4545  return TRUE;
4546  }
4547  if ( m != (int)pow((double)tdg+1,(double)n) )
4548  {
4549  Werror("Size of second input ideal must be equal to %d!",
4550  (int)pow((double)tdg+1,(double)n));
4551  return TRUE;
4552  }
4553  if ( !(rField_is_Q(currRing) /* ||
4554  rField_is_R() || rField_is_long_R() ||
4555  rField_is_long_C()*/ ) )
4556  {
4557  WerrorS("Ground field not implemented!");
4558  return TRUE;
4559  }
4560 
4561  number tmp;
4562  number *pevpoint= (number *)omAlloc( n * sizeof( number ) );
4563  for ( i= 0; i < n; i++ )
4564  {
4565  pevpoint[i]=nInit(0);
4566  if ( (p->m)[i] )
4567  {
4568  tmp = pGetCoeff( (p->m)[i] );
4569  if ( nIsZero(tmp) || nIsOne(tmp) || nIsMOne(tmp) )
4570  {
4571  omFreeSize( (ADDRESS)pevpoint, n * sizeof( number ) );
4572  WerrorS("Elements of first input ideal must not be equal to -1, 0, 1!");
4573  return TRUE;
4574  }
4575  } else tmp= NULL;
4576  if ( !nIsZero(tmp) )
4577  {
4578  if ( !pIsConstant((p->m)[i]))
4579  {
4580  omFreeSize( (ADDRESS)pevpoint, n * sizeof( number ) );
4581  WerrorS("Elements of first input ideal must be numbers!");
4582  return TRUE;
4583  }
4584  pevpoint[i]= nCopy( tmp );
4585  }
4586  }
4587 
4588  number *wresults= (number *)omAlloc( m * sizeof( number ) );
4589  for ( i= 0; i < m; i++ )
4590  {
4591  wresults[i]= nInit(0);
4592  if ( (w->m)[i] && !nIsZero(pGetCoeff((w->m)[i])) )
4593  {
4594  if ( !pIsConstant((w->m)[i]))
4595  {
4596  omFreeSize( (ADDRESS)pevpoint, n * sizeof( number ) );
4597  omFreeSize( (ADDRESS)wresults, m * sizeof( number ) );
4598  WerrorS("Elements of second input ideal must be numbers!");
4599  return TRUE;
4600  }
4601  wresults[i]= nCopy(pGetCoeff((w->m)[i]));
4602  }
4603  }
4604 
4605  vandermonde vm( m, n, tdg, pevpoint, FALSE );
4606  number *ncpoly= vm.interpolateDense( wresults );
4607  // do not free ncpoly[]!!
4608  poly rpoly= vm.numvec2poly( ncpoly );
4609 
4610  omFreeSize( (ADDRESS)pevpoint, n * sizeof( number ) );
4611  omFreeSize( (ADDRESS)wresults, m * sizeof( number ) );
4612 
4613  res->data= (void*)rpoly;
4614  return FALSE;
4615 }
4616 
4618 {
4619  leftv v= args;
4620 
4621  ideal gls;
4622  int imtype;
4623  int howclean;
4624 
4625  // get ideal
4626  if ( v->Typ() != IDEAL_CMD )
4627  return TRUE;
4628  else gls= (ideal)(v->Data());
4629  v= v->next;
4630 
4631  // get resultant matrix type to use (0,1)
4632  if ( v->Typ() != INT_CMD )
4633  return TRUE;
4634  else imtype= (int)(long)v->Data();
4635  v= v->next;
4636 
4637  if (imtype==0)
4638  {
4639  ideal test_id=idInit(1,1);
4640  int j;
4641  for(j=IDELEMS(gls)-1;j>=0;j--)
4642  {
4643  if (gls->m[j]!=NULL)
4644  {
4645  test_id->m[0]=gls->m[j];
4646  intvec *dummy_w=id_QHomWeight(test_id, currRing);
4647  if (dummy_w!=NULL)
4648  {
4649  WerrorS("Newton polytope not of expected dimension");
4650  delete dummy_w;
4651  return TRUE;
4652  }
4653  }
4654  }
4655  }
4656 
4657  // get and set precision in digits ( > 0 )
4658  if ( v->Typ() != INT_CMD )
4659  return TRUE;
4660  else if ( !(rField_is_R(currRing) || rField_is_long_R(currRing) || \
4662  {
4663  unsigned long int ii=(unsigned long int)v->Data();
4664  setGMPFloatDigits( ii, ii );
4665  }
4666  v= v->next;
4667 
4668  // get interpolation steps (0,1,2)
4669  if ( v->Typ() != INT_CMD )
4670  return TRUE;
4671  else howclean= (int)(long)v->Data();
4672 
4673  uResultant::resMatType mtype= determineMType( imtype );
4674  int i,count;
4675  lists listofroots= NULL;
4676  number smv= NULL;
4677  BOOLEAN interpolate_det= (mtype==uResultant::denseResMat)?TRUE:FALSE;
4678 
4679  //emptylist= (lists)omAlloc( sizeof(slists) );
4680  //emptylist->Init( 0 );
4681 
4682  //res->rtyp = LIST_CMD;
4683  //res->data= (void *)emptylist;
4684 
4685  // check input ideal ( = polynomial system )
4686  if ( mprIdealCheck( gls, args->Name(), mtype ) != mprOk )
4687  {
4688  return TRUE;
4689  }
4690 
4691  uResultant * ures;
4692  rootContainer ** iproots;
4693  rootContainer ** muiproots;
4694  rootArranger * arranger;
4695 
4696  // main task 1: setup of resultant matrix
4697  ures= new uResultant( gls, mtype );
4698  if ( ures->accessResMat()->initState() != resMatrixBase::ready )
4699  {
4700  WerrorS("Error occurred during matrix setup!");
4701  return TRUE;
4702  }
4703 
4704  // if dense resultant, check if minor nonsingular
4705  if ( mtype == uResultant::denseResMat )
4706  {
4707  smv= ures->accessResMat()->getSubDet();
4708 #ifdef mprDEBUG_PROT
4709  PrintS("// Determinant of submatrix: ");nPrint(smv);PrintLn();
4710 #endif
4711  if ( nIsZero(smv) )
4712  {
4713  WerrorS("Unsuitable input ideal: Minor of resultant matrix is singular!");
4714  return TRUE;
4715  }
4716  }
4717 
4718  // main task 2: Interpolate specialized resultant polynomials
4719  if ( interpolate_det )
4720  iproots= ures->interpolateDenseSP( false, smv );
4721  else
4722  iproots= ures->specializeInU( false, smv );
4723 
4724  // main task 3: Interpolate specialized resultant polynomials
4725  if ( interpolate_det )
4726  muiproots= ures->interpolateDenseSP( true, smv );
4727  else
4728  muiproots= ures->specializeInU( true, smv );
4729 
4730 #ifdef mprDEBUG_PROT
4731  int c= iproots[0]->getAnzElems();
4732  for (i=0; i < c; i++) pWrite(iproots[i]->getPoly());
4733  c= muiproots[0]->getAnzElems();
4734  for (i=0; i < c; i++) pWrite(muiproots[i]->getPoly());
4735 #endif
4736 
4737  // main task 4: Compute roots of specialized polys and match them up
4738  arranger= new rootArranger( iproots, muiproots, howclean );
4739  arranger->solve_all();
4740 
4741  // get list of roots
4742  if ( arranger->success() )
4743  {
4744  arranger->arrange();
4745  listofroots= listOfRoots(arranger, gmp_output_digits );
4746  }
4747  else
4748  {
4749  WerrorS("Solver was unable to find any roots!");
4750  return TRUE;
4751  }
4752 
4753  // free everything
4754  count= iproots[0]->getAnzElems();
4755  for (i=0; i < count; i++) delete iproots[i];
4756  omFreeSize( (ADDRESS) iproots, count * sizeof(rootContainer*) );
4757  count= muiproots[0]->getAnzElems();
4758  for (i=0; i < count; i++) delete muiproots[i];
4759  omFreeSize( (ADDRESS) muiproots, count * sizeof(rootContainer*) );
4760 
4761  delete ures;
4762  delete arranger;
4763  nDelete( &smv );
4764 
4765  res->data= (void *)listofroots;
4766 
4767  //emptylist->Clean();
4768  // omFreeSize( (ADDRESS) emptylist, sizeof(slists) );
4769 
4770  return FALSE;
4771 }
4772 
4773 // from mpr_numeric.cc
4774 lists listOfRoots( rootArranger* self, const unsigned int oprec )
4775 {
4776  int i,j;
4777  int count= self->roots[0]->getAnzRoots(); // number of roots
4778  int elem= self->roots[0]->getAnzElems(); // number of koordinates per root
4779 
4780  lists listofroots= (lists)omAlloc( sizeof(slists) ); // must be done this way!
4781 
4782  if ( self->found_roots )
4783  {
4784  listofroots->Init( count );
4785 
4786  for (i=0; i < count; i++)
4787  {
4788  lists onepoint= (lists)omAlloc(sizeof(slists)); // must be done this way!
4789  onepoint->Init(elem);
4790  for ( j= 0; j < elem; j++ )
4791  {
4792  if ( !rField_is_long_C(currRing) )
4793  {
4794  onepoint->m[j].rtyp=STRING_CMD;
4795  onepoint->m[j].data=(void *)complexToStr((*self->roots[j])[i],oprec, currRing->cf);
4796  }
4797  else
4798  {
4799  onepoint->m[j].rtyp=NUMBER_CMD;
4800  onepoint->m[j].data=(void *)n_Copy((number)(self->roots[j]->getRoot(i)), currRing->cf);
4801  }
4802  onepoint->m[j].next= NULL;
4803  onepoint->m[j].name= NULL;
4804  }
4805  listofroots->m[i].rtyp=LIST_CMD;
4806  listofroots->m[i].data=(void *)onepoint;
4807  listofroots->m[j].next= NULL;
4808  listofroots->m[j].name= NULL;
4809  }
4810 
4811  }
4812  else
4813  {
4814  listofroots->Init( 0 );
4815  }
4816 
4817  return listofroots;
4818 }
4819 
4820 // from ring.cc
4822 {
4823  ring rg = NULL;
4824  if (h!=NULL)
4825  {
4826 // Print(" new ring:%s (l:%d)\n",IDID(h),IDLEV(h));
4827  rg = IDRING(h);
4828  if (rg==NULL) return; //id <>NULL, ring==NULL
4829  omCheckAddrSize((ADDRESS)h,sizeof(idrec));
4830  if (IDID(h)) // OB: ????
4831  omCheckAddr((ADDRESS)IDID(h));
4832  rTest(rg);
4833  }
4834 
4835  // clean up history
4837  {
4839  memset(&sLastPrinted,0,sizeof(sleftv));
4840  }
4841 
4842  if ((rg!=currRing)&&(currRing!=NULL))
4843  {
4845  if (DENOMINATOR_LIST!=NULL)
4846  {
4847  if (TEST_V_ALLWARN)
4848  Warn("deleting denom_list for ring change to %s",IDID(h));
4849  do
4850  {
4851  n_Delete(&(dd->n),currRing->cf);
4852  dd=dd->next;
4854  DENOMINATOR_LIST=dd;
4855  } while(DENOMINATOR_LIST!=NULL);
4856  }
4857  }
4858 
4859  // test for valid "currRing":
4860  if ((rg!=NULL) && (rg->idroot==NULL))
4861  {
4862  ring old=rg;
4863  rg=rAssure_HasComp(rg);
4864  if (old!=rg)
4865  {
4866  rKill(old);
4867  IDRING(h)=rg;
4868  }
4869  }
4870  /*------------ change the global ring -----------------------*/
4871  rChangeCurrRing(rg);
4872  currRingHdl = h;
4873 }
4874 
4876 {
4877  // change some bad orderings/combination into better ones
4878  leftv h=ord;
4879  while(h!=NULL)
4880  {
4881  BOOLEAN change=FALSE;
4882  intvec *iv = (intvec *)(h->data);
4883  // ws(-i) -> wp(i)
4884  if ((*iv)[1]==ringorder_ws)
4885  {
4886  BOOLEAN neg=TRUE;
4887  for(int i=2;i<iv->length();i++)
4888  if((*iv)[i]>=0) { neg=FALSE; break; }
4889  if (neg)
4890  {
4891  (*iv)[1]=ringorder_wp;
4892  for(int i=2;i<iv->length();i++)
4893  (*iv)[i]= - (*iv)[i];
4894  change=TRUE;
4895  }
4896  }
4897  // Ws(-i) -> Wp(i)
4898  if ((*iv)[1]==ringorder_Ws)
4899  {
4900  BOOLEAN neg=TRUE;
4901  for(int i=2;i<iv->length();i++)
4902  if((*iv)[i]>=0) { neg=FALSE; break; }
4903  if (neg)
4904  {
4905  (*iv)[1]=ringorder_Wp;
4906  for(int i=2;i<iv->length();i++)
4907  (*iv)[i]= -(*iv)[i];
4908  change=TRUE;
4909  }
4910  }
4911  // wp(1) -> dp
4912  if ((*iv)[1]==ringorder_wp)
4913  {
4914  BOOLEAN all_one=TRUE;
4915  for(int i=2;i<iv->length();i++)
4916  if((*iv)[i]!=1) { all_one=FALSE; break; }
4917  if (all_one)
4918  {
4919  intvec *iv2=new intvec(3);
4920  (*iv2)[0]=1;
4921  (*iv2)[1]=ringorder_dp;
4922  (*iv2)[2]=iv->length()-2;
4923  delete iv;
4924  iv=iv2;
4925  h->data=iv2;
4926  change=TRUE;
4927  }
4928  }
4929  // Wp(1) -> Dp
4930  if ((*iv)[1]==ringorder_Wp)
4931  {
4932  BOOLEAN all_one=TRUE;
4933  for(int i=2;i<iv->length();i++)
4934  if((*iv)[i]!=1) { all_one=FALSE; break; }
4935  if (all_one)
4936  {
4937  intvec *iv2=new intvec(3);
4938  (*iv2)[0]=1;
4939  (*iv2)[1]=ringorder_Dp;
4940  (*iv2)[2]=iv->length()-2;
4941  delete iv;
4942  iv=iv2;
4943  h->data=iv2;
4944  change=TRUE;
4945  }
4946  }
4947  // dp(1)/Dp(1)/rp(1) -> lp(1)
4948  if (((*iv)[1]==ringorder_dp)
4949  || ((*iv)[1]==ringorder_Dp)
4950  || ((*iv)[1]==ringorder_rp))
4951  {
4952  if (iv->length()==3)
4953  {
4954  if ((*iv)[2]==1)
4955  {
4956  (*iv)[1]=ringorder_lp;
4957  change=TRUE;
4958  }
4959  }
4960  }
4961  // lp(i),lp(j) -> lp(i+j)
4962  if(((*iv)[1]==ringorder_lp)
4963  && (h->next!=NULL))
4964  {
4965  intvec *iv2 = (intvec *)(h->next->data);
4966  if ((*iv2)[1]==ringorder_lp)
4967  {
4968  leftv hh=h->next;
4969  h->next=hh->next;
4970  hh->next=NULL;
4971  if ((*iv2)[0]==1)
4972  (*iv)[2] += 1; // last block unspecified, at least 1
4973  else
4974  (*iv)[2] += (*iv2)[2];
4975  hh->CleanUp();
4976  omFree(hh);
4977  change=TRUE;
4978  }
4979  }
4980  // -------------------
4981  if (!change) h=h->next;
4982  }
4983  return ord;
4984 }
4985 
4986 
4988 {
4989  int last = 0, o=0, n = 1, i=0, typ = 1, j;
4990  ord=rOptimizeOrdAsSleftv(ord);
4991  sleftv *sl = ord;
4992 
4993  // determine nBlocks
4994  while (sl!=NULL)
4995  {
4996  intvec *iv = (intvec *)(sl->data);
4997  if (((*iv)[1]==ringorder_c)||((*iv)[1]==ringorder_C))
4998  i++;
4999  else if ((*iv)[1]==ringorder_L)
5000  {
5001  R->bitmask=(*iv)[2];
5002  n--;
5003  }
5004  else if (((*iv)[1]!=ringorder_a)
5005  && ((*iv)[1]!=ringorder_a64)
5006  && ((*iv)[1]!=ringorder_am))
5007  o++;
5008  n++;
5009  sl=sl->next;
5010  }
5011  // check whether at least one real ordering
5012  if (o==0)
5013  {
5014  WerrorS("invalid combination of orderings");
5015  return TRUE;
5016  }
5017  // if no c/C ordering is given, increment n
5018  if (i==0) n++;
5019  else if (i != 1)
5020  {
5021  // throw error if more than one is given
5022  WerrorS("more than one ordering c/C specified");
5023  return TRUE;
5024  }
5025 
5026  // initialize fields of R
5027  R->order=(int *)omAlloc0(n*sizeof(int));
5028  R->block0=(int *)omAlloc0(n*sizeof(int));
5029  R->block1=(int *)omAlloc0(n*sizeof(int));
5030  R->wvhdl=(int**)omAlloc0(n*sizeof(int_ptr));
5031 
5032  int *weights=(int*)omAlloc0((R->N+1)*sizeof(int));
5033 
5034  // init order, so that rBlocks works correctly
5035  for (j=0; j < n-1; j++)
5036  R->order[j] = (int) ringorder_unspec;
5037  // set last _C order, if no c/C order was given
5038  if (i == 0) R->order[n-2] = ringorder_C;
5039 
5040  /* init orders */
5041  sl=ord;
5042  n=-1;
5043  while (sl!=NULL)
5044  {
5045  intvec *iv;
5046  iv = (intvec *)(sl->data);
5047  if ((*iv)[1]!=ringorder_L)
5048  {
5049  n++;
5050 
5051  /* the format of an ordering:
5052  * iv[0]: factor
5053  * iv[1]: ordering
5054  * iv[2..end]: weights
5055  */
5056  R->order[n] = (*iv)[1];
5057  typ=1;
5058  switch ((*iv)[1])
5059  {
5060  case ringorder_ws:
5061  case ringorder_Ws:
5062  typ=-1;
5063  case ringorder_wp:
5064  case ringorder_Wp:
5065  R->wvhdl[n]=(int*)omAlloc((iv->length()-1)*sizeof(int));
5066  R->block0[n] = last+1;
5067  for (i=2; i<iv->length(); i++)
5068  {
5069  R->wvhdl[n][i-2] = (*iv)[i];
5070  last++;
5071  if (weights[last]==0) weights[last]=(*iv)[i]*typ;
5072  }
5073  R->block1[n] = last;
5074  break;
5075  case ringorder_ls:
5076  case ringorder_ds:
5077  case ringorder_Ds:
5078  case ringorder_rs:
5079  typ=-1;
5080  case ringorder_lp:
5081  case ringorder_dp:
5082  case ringorder_Dp:
5083  case ringorder_rp:
5084  R->block0[n] = last+1;
5085  if (iv->length() == 3) last+=(*iv)[2];
5086  else last += (*iv)[0];
5087  R->block1[n] = last;
5088  //if ((R->block0[n]>R->block1[n])
5089  //|| (R->block1[n]>rVar(R)))
5090  //{
5091  // R->block1[n]=rVar(R);
5092  // //WerrorS("ordering larger than number of variables");
5093  // break;
5094  //}
5095  if (rCheckIV(iv)) return TRUE;
5096  for(i=si_min(rVar(R),R->block1[n]);i>=R->block0[n];i--)
5097  {
5098  if (weights[i]==0) weights[i]=typ;
5099  }
5100  break;
5101 
5102  case ringorder_s: // no 'rank' params!
5103  {
5104 
5105  if(iv->length() > 3)
5106  return TRUE;
5107 
5108  if(iv->length() == 3)
5109  {
5110  const int s = (*iv)[2];
5111  R->block0[n] = s;
5112  R->block1[n] = s;
5113  }
5114  break;
5115  }
5116  case ringorder_IS:
5117  {
5118  if(iv->length() != 3) return TRUE;
5119 
5120  const int s = (*iv)[2];
5121 
5122  if( 1 < s || s < -1 ) return TRUE;
5123 
5124  R->block0[n] = s;
5125  R->block1[n] = s;
5126  break;
5127  }
5128  case ringorder_S:
5129  case ringorder_c:
5130  case ringorder_C:
5131  {
5132  if (rCheckIV(iv)) return TRUE;
5133  break;
5134  }
5135  case ringorder_aa:
5136  case ringorder_a:
5137  {
5138  R->block0[n] = last+1;
5139  R->block1[n] = si_min(last+iv->length()-2 , rVar(R));
5140  R->wvhdl[n] = (int*)omAlloc((iv->length()-1)*sizeof(int));
5141  for (i=2; i<iv->length(); i++)
5142  {
5143  R->wvhdl[n][i-2]=(*iv)[i];
5144  last++;
5145  if (weights[last]==0) weights[last]=(*iv)[i]*typ;
5146  }
5147  last=R->block0[n]-1;
5148  break;
5149  }
5150  case ringorder_am:
5151  {
5152  R->block0[n] = last+1;
5153  R->block1[n] = si_min(last+iv->length()-2 , rVar(R));
5154  R->wvhdl[n] = (int*)omAlloc(iv->length()*sizeof(int));
5155  if (R->block1[n]- R->block0[n]+2>=iv->length())
5156  WarnS("missing module weights");
5157  for (i=2; i<=(R->block1[n]-R->block0[n]+2); i++)
5158  {
5159  R->wvhdl[n][i-2]=(*iv)[i];
5160  last++;
5161  if (weights[last]==0) weights[last]=(*iv)[i]*typ;
5162  }
5163  R->wvhdl[n][i-2]=iv->length() -3 -(R->block1[n]- R->block0[n]);
5164  for (; i<iv->length(); i++)
5165  {
5166  R->wvhdl[n][i-1]=(*iv)[i];
5167  }
5168  last=R->block0[n]-1;
5169  break;
5170  }
5171  case ringorder_a64:
5172  {
5173  R->block0[n] = last+1;
5174  R->block1[n] = si_min(last+iv->length()-2 , rVar(R));
5175  R->wvhdl[n] = (int*)omAlloc((iv->length()-1)*sizeof(int64));
5176  int64 *w=(int64 *)R->wvhdl[n];
5177  for (i=2; i<iv->length(); i++)
5178  {
5179  w[i-2]=(*iv)[i];
5180  last++;
5181  if (weights[last]==0) weights[last]=(*iv)[i]*typ;
5182  }
5183  last=R->block0[n]-1;
5184  break;
5185  }
5186  case ringorder_M:
5187  {
5188  int Mtyp=rTypeOfMatrixOrder(iv);
5189  if (Mtyp==0) return TRUE;
5190  if (Mtyp==-1) typ = -1;
5191 
5192  R->wvhdl[n] =( int *)omAlloc((iv->length()-1)*sizeof(int));
5193  for (i=2; i<iv->length();i++)
5194  R->wvhdl[n][i-2]=(*iv)[i];
5195 
5196  R->block0[n] = last+1;
5197  last += (int)sqrt((double)(iv->length()-2));
5198  R->block1[n] = last;
5199  for(i=si_min(rVar(R),R->block1[n]);i>=R->block0[n];i--)
5200  {
5201  if (weights[i]==0) weights[i]=typ;
5202  }
5203  break;
5204  }
5205 
5206  case ringorder_no:
5207  R->order[n] = ringorder_unspec;
5208  return TRUE;
5209 
5210  default:
5211  Werror("Internal Error: Unknown ordering %d", (*iv)[1]);
5212  R->order[n] = ringorder_unspec;
5213  return TRUE;
5214  }
5215  }
5216  sl=sl->next;
5217  }
5218 
5219  // check for complete coverage
5220  while ( n >= 0 && (
5221  (R->order[n]==ringorder_c)
5222  || (R->order[n]==ringorder_C)
5223  || (R->order[n]==ringorder_s)
5224  || (R->order[n]==ringorder_S)
5225  || (R->order[n]==ringorder_IS)
5226  )) n--;
5227 
5228  assume( n >= 0 );
5229 
5230  if (R->block1[n] != R->N)
5231  {
5232  if (((R->order[n]==ringorder_dp) ||
5233  (R->order[n]==ringorder_ds) ||
5234  (R->order[n]==ringorder_Dp) ||
5235  (R->order[n]==ringorder_Ds) ||
5236  (R->order[n]==ringorder_rp) ||
5237  (R->order[n]==ringorder_rs) ||
5238  (R->order[n]==ringorder_lp) ||
5239  (R->order[n]==ringorder_ls))
5240  &&
5241  R->block0[n] <= R->N)
5242  {
5243  R->block1[n] = R->N;
5244  }
5245  else
5246  {
5247  Werror("mismatch of number of vars (%d) and ordering (%d vars)",
5248  R->N,R->block1[n]);
5249  return TRUE;
5250  }
5251  }
5252  // find OrdSgn:
5253  R->OrdSgn = 1;
5254  for(i=1;i<=R->N;i++)
5255  { if (weights[i]<0) { R->OrdSgn=-1;break; }}
5256  omFree(weights);
5257  return FALSE;
5258 }
5259 
5261 {
5262 
5263  while(sl!=NULL)
5264  {
5265  if (sl->Name() == sNoName)
5266  {
5267  if (sl->Typ()==POLY_CMD)
5268  {
5269  sleftv s_sl;
5270  iiConvert(POLY_CMD,ANY_TYPE,-1,sl,&s_sl);
5271  if (s_sl.Name() != sNoName)
5272  *p = omStrDup(s_sl.Name());
5273  else
5274  *p = NULL;
5275  sl->next = s_sl.next;
5276  s_sl.next = NULL;
5277  s_sl.CleanUp();
5278  if (*p == NULL) return TRUE;
5279  }
5280  else
5281  return TRUE;
5282  }
5283  else
5284  *p = omStrDup(sl->Name());
5285  p++;
5286  sl=sl->next;
5287  }
5288  return FALSE;
5289 }
5290 
5291 const short MAX_SHORT = 32767; // (1 << (sizeof(short)*8)) - 1;
5292 
5293 ////////////////////
5294 //
5295 // rInit itself:
5296 //
5297 // INPUT: s: name, pn: ch & parameter (names), rv: variable (names)
5298 // ord: ordering
5299 // RETURN: currRingHdl on success
5300 // NULL on error
5301 // NOTE: * makes new ring to current ring, on success
5302 // * considers input sleftv's as read-only
5303 //idhdl rInit(char *s, sleftv* pn, sleftv* rv, sleftv* ord)
5304 ring rInit(sleftv* pn, sleftv* rv, sleftv* ord)
5305 {
5306 #ifdef HAVE_RINGS
5307  //unsigned int ringtype = 0;
5308  mpz_ptr modBase = NULL;
5309  unsigned int modExponent = 1;
5310 #endif
5311  int float_len=0;
5312  int float_len2=0;
5313  ring R = NULL;
5314  //BOOLEAN ffChar=FALSE;
5315 
5316  /* ch -------------------------------------------------------*/
5317  // get ch of ground field
5318 
5319  // allocated ring
5320  R = (ring) omAlloc0Bin(sip_sring_bin);
5321 
5322  coeffs cf = NULL;
5323 
5324  assume( pn != NULL );
5325  const int P = pn->listLength();
5326 
5327  if ((pn->Typ()==CRING_CMD)&&(P==1))
5328  {
5329  cf=(coeffs)pn->CopyD();
5330  assume( cf != NULL );
5331  }
5332  else if (pn->Typ()==INT_CMD)
5333  {
5334  int ch = (int)(long)pn->Data();
5335 
5336  /* parameter? -------------------------------------------------------*/
5337  pn = pn->next;
5338 
5339  if (pn == NULL) // no params!?
5340  {
5341  if (ch!=0)
5342  {
5343  int ch2=IsPrime(ch);
5344  if ((ch<2)||(ch!=ch2))
5345  {
5346  Warn("%d is invalid as characteristic of the ground field. 32003 is used.", ch);
5347  ch=32003;
5348  }
5349  cf = nInitChar(n_Zp, (void*)(long)ch);
5350  }
5351  else
5352  cf = nInitChar(n_Q, (void*)(long)ch);
5353  }
5354  else
5355  {
5356  const int pars = pn->listLength();
5357 
5358  assume( pars > 0 );
5359 
5360  // predefined finite field: (p^k, a)
5361  if ((ch!=0) && (ch!=IsPrime(ch)) && (pars == 1))
5362  {
5363  GFInfo param;
5364 
5365  param.GFChar = ch;
5366  param.GFDegree = 1;
5367  param.GFPar_name = pn->name;
5368 
5369  cf = nInitChar(n_GF, &param);
5370  }
5371  else // (0/p, a, b, ..., z)
5372  {
5373  if ((ch!=0) && (ch!=IsPrime(ch)))
5374  {
5375  WerrorS("too many parameters");
5376  goto rInitError;
5377  }
5378 
5379  char ** names = (char**)omAlloc0(pars * sizeof(char_ptr));
5380 
5381  if (rSleftvList2StringArray(pn, names))
5382  {
5383  WerrorS("parameter expected");
5384  goto rInitError;
5385  }
5386 
5387  TransExtInfo extParam;
5388 
5389  extParam.r = rDefault( ch, pars, names); // Q/Zp [ p_1, ... p_pars ]
5390  for(int i=pars-1; i>=0;i--)
5391  {
5392  omFree(names[i]);
5393  }
5394  omFree(names);
5395 
5396  cf = nInitChar(n_transExt, &extParam);
5397  }
5398  }
5399 
5400 // if (cf==NULL) goto rInitError;
5401  assume( cf != NULL );
5402  }
5403  else if ((pn->name != NULL)
5404  && ((strcmp(pn->name,"real")==0) || (strcmp(pn->name,"complex")==0)))
5405  {
5406  BOOLEAN complex_flag=(strcmp(pn->name,"complex")==0);
5407  if ((pn->next!=NULL) && (pn->next->Typ()==INT_CMD))
5408  {
5409  float_len=(int)(long)pn->next->Data();
5410  float_len2=float_len;
5411  pn=pn->next;
5412  if ((pn->next!=NULL) && (pn->next->Typ()==INT_CMD))
5413  {
5414  float_len2=(int)(long)pn->next->Data();
5415  pn=pn->next;
5416  }
5417  }
5418 
5419  if (!complex_flag)
5420  complex_flag= pn->next != NULL;
5421  if( !complex_flag && (float_len2 <= (short)SHORT_REAL_LENGTH))
5422  cf=nInitChar(n_R, NULL);
5423  else // longR or longC?
5424  {
5425  LongComplexInfo param;
5426 
5427  param.float_len = si_min (float_len, 32767);
5428  param.float_len2 = si_min (float_len2, 32767);
5429 
5430  // set the parameter name
5431  if (complex_flag)
5432  {
5433  if (param.float_len < SHORT_REAL_LENGTH)
5434  {
5437  }
5438  if (pn->next == NULL)
5439  param.par_name=(const char*)"i"; //default to i
5440  else
5441  param.par_name = (const char*)pn->next->name;
5442  }
5443 
5444  cf = nInitChar(complex_flag ? n_long_C: n_long_R, (void*)&param);
5445  }
5446  assume( cf != NULL );
5447  }
5448 #ifdef HAVE_RINGS
5449  else if ((pn->name != NULL) && (strcmp(pn->name, "integer") == 0))
5450  {
5451  // TODO: change to use coeffs_BIGINT!?
5452  modBase = (mpz_ptr) omAlloc(sizeof(mpz_t));
5453  mpz_init_set_si(modBase, 0);
5454  if (pn->next!=NULL)
5455  {
5456  if (pn->next->Typ()==INT_CMD)
5457  {
5458  mpz_set_ui(modBase, (int)(long) pn->next->Data());
5459  pn=pn->next;
5460  if ((pn->next!=NULL) && (pn->next->Typ()==INT_CMD))
5461  {
5462  modExponent = (long) pn->next->Data();
5463  pn=pn->next;
5464  }
5465  while ((pn->next!=NULL) && (pn->next->Typ()==INT_CMD))
5466  {
5467  mpz_mul_ui(modBase, modBase, (int)(long) pn->next->Data());
5468  pn=pn->next;
5469  }
5470  }
5471  else if (pn->next->Typ()==BIGINT_CMD)
5472  {
5473  number p=(number)pn->next->CopyD(); // FIXME: why CopyD() here if nlGMP should not overtake p!?
5474  nlGMP(p,(number)modBase,coeffs_BIGINT); // TODO? // extern void nlGMP(number &i, number n, const coeffs r); // FIXME: n_MPZ( modBase, p, coeffs_BIGINT); ?
5475  n_Delete(&p,coeffs_BIGINT);
5476  }
5477  }
5478  else
5479  cf=nInitChar(n_Z,NULL);
5480 
5481  if ((mpz_cmp_ui(modBase, 1) == 0) && (mpz_cmp_ui(modBase, 0) < 0))
5482  {
5483  Werror("Wrong ground ring specification (module is 1)");
5484  goto rInitError;
5485  }
5486  if (modExponent < 1)
5487  {
5488  Werror("Wrong ground ring specification (exponent smaller than 1");
5489  goto rInitError;
5490  }
5491  // module is 0 ---> integers ringtype = 4;
5492  // we have an exponent
5493  if (modExponent > 1 && cf == NULL)
5494  {
5495  if ((mpz_cmp_ui(modBase, 2) == 0) && (modExponent <= 8*sizeof(unsigned long)))
5496  {
5497  /* this branch should be active for modExponent = 2..32 resp. 2..64,
5498  depending on the size of a long on the respective platform */
5499  //ringtype = 1; // Use Z/2^ch
5500  cf=nInitChar(n_Z2m,(void*)(long)modExponent);
5501  mpz_clear(modBase);
5502  omFreeSize (modBase, sizeof (mpz_t));
5503  }
5504  else
5505  {
5506  if (mpz_cmp_ui(modBase,0)==0)
5507  {
5508  WerrorS("modulus must not be 0 or parameter not allowed");
5509  goto rInitError;
5510  }
5511  //ringtype = 3;
5512  ZnmInfo info;
5513  info.base= modBase;
5514  info.exp= modExponent;
5515  cf=nInitChar(n_Znm,(void*) &info); //exponent is missing
5516  }
5517  }
5518  // just a module m > 1
5519  else if (cf == NULL)
5520  {
5521  if (mpz_cmp_ui(modBase,0)==0)
5522  {
5523  WerrorS("modulus must not be 0 or parameter not allowed");
5524  goto rInitError;
5525  }
5526  //ringtype = 2;
5527  ZnmInfo info;
5528  info.base= modBase;
5529  info.exp= modExponent;
5530  cf=nInitChar(n_Zn,(void*) &info);
5531  }
5532  assume( cf != NULL );
5533  }
5534 #endif
5535  // ring NEW = OLD, (), (); where OLD is a polynomial ring...
5536  else if ((pn->Typ()==RING_CMD) && (P == 1))
5537  {
5538  TransExtInfo extParam;
5539  extParam.r = (ring)pn->Data();
5540  cf = nInitChar(n_transExt, &extParam);
5541  }
5542  else if ((pn->Typ()==QRING_CMD) && (P == 1)) // same for qrings - which should be fields!?
5543  {
5544  AlgExtInfo extParam;
5545  extParam.r = (ring)pn->Data();
5546 
5547  cf = nInitChar(n_algExt, &extParam); // Q[a]/<minideal>
5548  }
5549  else
5550  {
5551  Werror("Wrong or unknown ground field specification");
5552 #ifndef SING_NDEBUG
5553  sleftv* p = pn;
5554  while (p != NULL)
5555  {
5556  Print( "pn[%p]: type: %d [%s]: %p, name: %s", (void*)p, p->Typ(), Tok2Cmdname(p->Typ()), p->Data(), (p->name == NULL? "NULL" : p->name) );
5557  PrintLn();
5558  p = p->next;
5559  }
5560 #endif
5561  goto rInitError;
5562  }
5563 // pn=pn->next;
5564 
5565  /*every entry in the new ring is initialized to 0*/
5566 
5567  /* characteristic -----------------------------------------------*/
5568  /* input: 0 ch=0 : Q parameter=NULL ffChar=FALSE float_len
5569  * 0 1 : Q(a,...) *names FALSE
5570  * 0 -1 : R NULL FALSE 0
5571  * 0 -1 : R NULL FALSE prec. >6
5572  * 0 -1 : C *names FALSE prec. 0..?
5573  * p p : Fp NULL FALSE
5574  * p -p : Fp(a) *names FALSE
5575  * q q : GF(q=p^n) *names TRUE
5576  */
5577  if (cf==NULL)
5578  {
5579  Werror("Invalid ground field specification");
5580  goto rInitError;
5581 // const int ch=32003;
5582 // cf=nInitChar(n_Zp, (void*)(long)ch);
5583  }
5584 
5585  assume( R != NULL );
5586 
5587  R->cf = cf;
5588 
5589  /* names and number of variables-------------------------------------*/
5590  {
5591  int l=rv->listLength();
5592 
5593  if (l>MAX_SHORT)
5594  {
5595  Werror("too many ring variables(%d), max is %d",l,MAX_SHORT);
5596  goto rInitError;
5597  }
5598  R->N = l; /*rv->listLength();*/
5599  }
5600  R->names = (char **)omAlloc0(R->N * sizeof(char_ptr));
5601  if (rSleftvList2StringArray(rv, R->names))
5602  {
5603  WerrorS("name of ring variable expected");
5604  goto rInitError;
5605  }
5606 
5607  /* check names and parameters for conflicts ------------------------- */
5608  rRenameVars(R); // conflicting variables will be renamed
5609  /* ordering -------------------------------------------------------------*/
5610  if (rSleftvOrdering2Ordering(ord, R))
5611  goto rInitError;
5612 
5613  // Complete the initialization
5614  if (rComplete(R,1))
5615  goto rInitError;
5616 
5617 /*#ifdef HAVE_RINGS
5618 // currently, coefficients which are ring elements require a global ordering:
5619  if (rField_is_Ring(R) && (R->OrdSgn==-1))
5620  {
5621  WerrorS("global ordering required for these coefficients");
5622  goto rInitError;
5623  }
5624 #endif*/
5625 
5626  rTest(R);
5627 
5628  // try to enter the ring into the name list
5629  // need to clean up sleftv here, before this ring can be set to
5630  // new currRing or currRing can be killed beacuse new ring has
5631  // same name
5632  if (pn != NULL) pn->CleanUp();
5633  if (rv != NULL) rv->CleanUp();
5634  if (ord != NULL) ord->CleanUp();
5635  //if ((tmp = enterid(s, myynest, RING_CMD, &IDROOT))==NULL)
5636  // goto rInitError;
5637 
5638  //memcpy(IDRING(tmp),R,sizeof(*R));
5639  // set current ring
5640  //omFreeBin(R, ip_sring_bin);
5641  //return tmp;
5642  return R;
5643 
5644  // error case:
5645  rInitError:
5646  if ((R != NULL)&&(R->cf!=NULL)) rDelete(R);
5647  if (pn != NULL) pn->CleanUp();
5648  if (rv != NULL) rv->CleanUp();
5649  if (ord != NULL) ord->CleanUp();
5650  return NULL;
5651 }
5652 
5653 ring rSubring(ring org_ring, sleftv* rv)
5654 {
5655  ring R = rCopy0(org_ring);
5656  int *perm=(int *)omAlloc0((org_ring->N+1)*sizeof(int));
5657  int n = rBlocks(org_ring), i=0, j;
5658 
5659  /* names and number of variables-------------------------------------*/
5660  {
5661  int l=rv->listLength();
5662  if (l>MAX_SHORT)
5663  {
5664  Werror("too many ring variables(%d), max is %d",l,MAX_SHORT);
5665  goto rInitError;
5666  }
5667  R->N = l; /*rv->listLength();*/
5668  }
5669  omFree(R->names);
5670  R->names = (char **)omAlloc0(R->N * sizeof(char_ptr));
5671  if (rSleftvList2StringArray(rv, R->names))
5672  {
5673  WerrorS("name of ring variable expected");
5674  goto rInitError;
5675  }
5676 
5677  /* check names for subring in org_ring ------------------------- */
5678  {
5679  i=0;
5680 
5681  for(j=0;j<R->N;j++)
5682  {
5683  for(;i<org_ring->N;i++)
5684  {
5685  if (strcmp(org_ring->names[i],R->names[j])==0)
5686  {
5687  perm[i+1]=j+1;
5688  break;
5689  }
5690  }
5691  if (i>org_ring->N)
5692  {
5693  Werror("variable %d (%s) not in basering",j+1,R->names[j]);
5694  break;
5695  }
5696  }
5697  }
5698  //Print("perm=");
5699  //for(i=1;i<org_ring->N;i++) Print("v%d -> v%d\n",i,perm[i]);
5700  /* ordering -------------------------------------------------------------*/
5701 
5702  for(i=0;i<n;i++)
5703  {
5704  int min_var=-1;
5705  int max_var=-1;
5706  for(j=R->block0[i];j<=R->block1[i];j++)
5707  {
5708  if (perm[j]>0)
5709  {
5710  if (min_var==-1) min_var=perm[j];
5711  max_var=perm[j];
5712  }
5713  }
5714  if (min_var!=-1)
5715  {
5716  //Print("block %d: old %d..%d, now:%d..%d\n",
5717  // i,R->block0[i],R->block1[i],min_var,max_var);
5718  R->block0[i]=min_var;
5719  R->block1[i]=max_var;
5720  if (R->wvhdl[i]!=NULL)
5721  {
5722  omFree(R->wvhdl[i]);
5723  R->wvhdl[i]=(int*)omAlloc0((max_var-min_var+1)*sizeof(int));
5724  for(j=org_ring->block0[i];j<=org_ring->block1[i];j++)
5725  {
5726  if (perm[j]>0)
5727  {
5728  R->wvhdl[i][perm[j]-R->block0[i]]=
5729  org_ring->wvhdl[i][j-org_ring->block0[i]];
5730  //Print("w%d=%d (orig_w%d)\n",perm[j],R->wvhdl[i][perm[j]-R->block0[i]],j);
5731  }
5732  }
5733  }
5734  }
5735  else
5736  {
5737  if(R->block0[i]>0)
5738  {
5739  //Print("skip block %d\n",i);
5740  R->order[i]=ringorder_unspec;
5741  if (R->wvhdl[i] !=NULL) omFree(R->wvhdl[i]);
5742  R->wvhdl[i]=NULL;
5743  }
5744  //else Print("keep block %d\n",i);
5745  }
5746  }
5747  i=n-1;
5748  while(i>0)
5749  {
5750  // removed unneded blocks
5751  if(R->order[i-1]==ringorder_unspec)
5752  {
5753  for(j=i;j<=n;j++)
5754  {
5755  R->order[j-1]=R->order[j];
5756  R->block0[j-1]=R->block0[j];
5757  R->block1[j-1]=R->block1[j];
5758  if (R->wvhdl[j-1] !=NULL) omFree(R->wvhdl[j-1]);
5759  R->wvhdl[j-1]=R->wvhdl[j];
5760  }
5761  R->order[n]=ringorder_unspec;
5762  n--;
5763  }
5764  i--;
5765  }
5766  n=rBlocks(org_ring)-1;
5767  while (R->order[n]==0) n--;
5768  while (R->order[n]==ringorder_unspec) n--;
5769  if ((R->order[n]==ringorder_c) || (R->order[n]==ringorder_C)) n--;
5770  if (R->block1[n] != R->N)
5771  {
5772  if (((R->order[n]==ringorder_dp) ||
5773  (R->order[n]==ringorder_ds) ||
5774  (R->order[n]==ringorder_Dp) ||
5775  (R->order[n]==ringorder_Ds) ||
5776  (R->order[n]==ringorder_rp) ||
5777  (R->order[n]==ringorder_rs) ||
5778  (R->order[n]==ringorder_lp) ||
5779  (R->order[n]==ringorder_ls))
5780  &&
5781  R->block0[n] <= R->N)
5782  {
5783  R->block1[n] = R->N;
5784  }
5785  else
5786  {
5787  Werror("mismatch of number of vars (%d) and ordering (%d vars) in block %d",
5788  R->N,R->block1[n],n);
5789  return NULL;
5790  }
5791  }
5792  omFree(perm);
5793  // find OrdSgn:
5794  R->OrdSgn = org_ring->OrdSgn; // IMPROVE!
5795  //for(i=1;i<=R->N;i++)
5796  //{ if (weights[i]<0) { R->OrdSgn=-1;break; }}
5797  //omFree(weights);
5798  // Complete the initialization
5799  if (rComplete(R,1))
5800  goto rInitError;
5801 
5802  rTest(R);
5803 
5804  if (rv != NULL) rv->CleanUp();
5805 
5806  return R;
5807 
5808  // error case:
5809  rInitError:
5810  if (R != NULL) rDelete(R);
5811  if (rv != NULL) rv->CleanUp();
5812  return NULL;
5813 }
5814 
5815 void rKill(ring r)
5816 {
5817  if ((r->ref<=0)&&(r->order!=NULL))
5818  {
5819 #ifdef RDEBUG
5820  if (traceit &TRACE_SHOW_RINGS) Print("kill ring %lx\n",(long)r);
5821 #endif
5822  if (r->qideal!=NULL)
5823  {
5824  id_Delete(&r->qideal, r);
5825  r->qideal = NULL;
5826  }
5827  int j;
5828 #ifdef USE_IILOCALRING
5829  for (j=0;j<myynest;j++)
5830  {
5831  if (iiLocalRing[j]==r)
5832  {
5833  if (j+1==myynest) Warn("killing the basering for level %d",j);
5834  iiLocalRing[j]=NULL;
5835  }
5836  }
5837 #else /* USE_IILOCALRING */
5838 //#endif /* USE_IILOCALRING */
5839  {
5840  proclevel * nshdl = procstack;
5841  int lev=myynest-1;
5842 
5843  for(; nshdl != NULL; nshdl = nshdl->next)
5844  {
5845  if (nshdl->cRing==r)
5846  {
5847  Warn("killing the basering for level %d",lev);
5848  nshdl->cRing=NULL;
5849  nshdl->cRingHdl=NULL;
5850  }
5851  }
5852  }
5853 #endif /* USE_IILOCALRING */
5854 // any variables depending on r ?
5855  while (r->idroot!=NULL)
5856  {
5857  r->idroot->lev=myynest; // avoid warning about kill global objects
5858  killhdl2(r->idroot,&(r->idroot),r);
5859  }
5860  if (r==currRing)
5861  {
5862  // all dependend stuff is done, clean global vars:
5863  if ((currRing->ppNoether)!=NULL) pDelete(&(currRing->ppNoether));
5865  {
5867  }
5868  //if ((myynest>0) && (iiRETURNEXPR.RingDependend()))
5869  //{
5870  // WerrorS("return value depends on local ring variable (export missing ?)");
5871  // iiRETURNEXPR.CleanUp();
5872  //}
5873  currRing=NULL;
5874  currRingHdl=NULL;
5875  }
5876 
5877  /* nKillChar(r); will be called from inside of rDelete */
5878  rDelete(r);
5879  return;
5880  }
5881  r->ref--;
5882 }
5883 
5884 void rKill(idhdl h)
5885 {
5886  ring r = IDRING(h);
5887  int ref=0;
5888  if (r!=NULL)
5889  {
5890  ref=r->ref;
5891  rKill(r);
5892  }
5893  if (h==currRingHdl)
5894  {
5895  if (ref<=0) { currRing=NULL; currRingHdl=NULL;}
5896  else
5897  {
5899  }
5900  }
5901 }
5902 
5904 {
5905  //idhdl next_best=NULL;
5906  idhdl h=root;
5907  while (h!=NULL)
5908  {
5909  if (((IDTYP(h)==RING_CMD)||(IDTYP(h)==QRING_CMD))
5910  && (h!=n)
5911  && (IDRING(h)==r)
5912  )
5913  {
5914  // if (IDLEV(h)==myynest)
5915  // return h;
5916  // if ((IDLEV(h)==0) || (next_best==NULL))
5917  // next_best=h;
5918  // else if (IDLEV(next_best)<IDLEV(h))
5919  // next_best=h;
5920  return h;
5921  }
5922  h=IDNEXT(h);
5923  }
5924  //return next_best;
5925  return NULL;
5926 }
5927 
5928 extern BOOLEAN jjPROC(leftv res, leftv u, leftv v);
5930 {
5931  //test|=Sy_bit(OPT_PROT);
5932  idhdl save_ringhdl=currRingHdl;
5933  ideal resid;
5934  idhdl new_ring=NULL;
5935  if ((currRingHdl==NULL) || (IDRING(currRingHdl)!=currRing))
5936  {
5937  currRingHdl=enterid(omStrDup(" GROEBNERring"),0,RING_CMD,&IDROOT,FALSE);
5938  new_ring=currRingHdl;
5940  }
5941  sleftv v; memset(&v,0,sizeof(v)); v.rtyp=IDEAL_CMD; v.data=(char *) F;
5942  idhdl h=ggetid("groebner");
5943  sleftv u; memset(&u,0,sizeof(u)); u.rtyp=IDHDL; u.data=(char *) h;
5944  u.name=IDID(h);
5945 
5946  sleftv res; memset(&res,0,sizeof(res));
5947  if(jjPROC(&res,&u,&v))
5948  {
5949  resid=kStd(F,Q,testHomog,NULL);
5950  }
5951  else
5952  {
5953  //printf("typ:%d\n",res.rtyp);
5954  resid=(ideal)(res.data);
5955  }
5956  // cleanup GROEBNERring, save_ringhdl, u,v,(res )
5957  if (new_ring!=NULL)
5958  {
5959  idhdl h=IDROOT;
5960  if (h==new_ring) IDROOT=h->next;
5961  else
5962  {
5963  while ((h!=NULL) &&(h->next!=new_ring)) h=h->next;
5964  if (h!=NULL) h->next=h->next->next;
5965  }
5966  if (h!=NULL) omFreeSize(h,sizeof(*h));
5967  }
5968  currRingHdl=save_ringhdl;
5969  u.CleanUp();
5970  v.CleanUp();
5971  return resid;
5972 }
5973 
5974 static void jjINT_S_TO_ID(int n,int *e, leftv res)
5975 {
5976  if (n==0) n=1;
5977  ideal l=idInit(n,1);
5978  int i;
5979  poly p;
5980  for(i=rVar(currRing);i>0;i--)
5981  {
5982  if (e[i]>0)
5983  {
5984  n--;
5985  p=pOne();
5986  pSetExp(p,i,1);
5987  pSetm(p);
5988  l->m[n]=p;
5989  if (n==0) break;
5990  }
5991  }
5992  res->data=(char*)l;
5993  setFlag(res,FLAG_STD);
5994  omFreeSize((ADDRESS)e,(rVar(currRing)+1)*sizeof(int));
5995 }
5997 {
5998  int *e=(int *)omAlloc0((rVar(currRing)+1)*sizeof(int));
5999  int n=pGetVariables((poly)u->Data(),e);
6000  jjINT_S_TO_ID(n,e,res);
6001  return FALSE;
6002 }
6003 
6005 {
6006  int *e=(int *)omAlloc0((rVar(currRing)+1)*sizeof(int));
6007  ideal I=(ideal)u->Data();
6008  int i;
6009  int n=0;
6010  for(i=I->nrows*I->ncols-1;i>=0;i--)
6011  {
6012  int n0=pGetVariables(I->m[i],e);
6013  if (n0>n) n=n0;
6014  }
6015  jjINT_S_TO_ID(n,e,res);
6016  return FALSE;
6017 }
6018 
6019 void paPrint(const char *n,package p)
6020 {
6021  Print(" %s (",n);
6022  switch (p->language)
6023  {
6024  case LANG_SINGULAR: PrintS("S"); break;
6025  case LANG_C: PrintS("C"); break;
6026  case LANG_TOP: PrintS("T"); break;
6027  case LANG_NONE: PrintS("N"); break;
6028  default: PrintS("U");
6029  }
6030  if(p->libname!=NULL)
6031  Print(",%s", p->libname);
6032  PrintS(")");
6033 }
6034 
6036 {
6037  intvec *aa=(intvec*)a->Data();
6038  sleftv tmp_out;
6039  sleftv tmp_in;
6040  leftv curr=res;
6041  BOOLEAN bo=FALSE;
6042  for(int i=0;i<aa->length(); i++)
6043  {
6044  memset(&tmp_in,0,sizeof(tmp_in));
6045  tmp_in.rtyp=INT_CMD;
6046  tmp_in.data=(void*)(long)(*aa)[i];
6047  if (proc==NULL)
6048  bo=iiExprArith1(&tmp_out,&tmp_in,op);
6049  else
6050  bo=jjPROC(&tmp_out,proc,&tmp_in);
6051  if (bo)
6052  {
6053  res->CleanUp(currRing);
6054  Werror("apply fails at index %d",i+1);
6055  return TRUE;
6056  }
6057  if (i==0) { memcpy(res,&tmp_out,sizeof(tmp_out)); }
6058  else
6059  {
6060  curr->next=(leftv)omAllocBin(sleftv_bin);
6061  curr=curr->next;
6062  memcpy(curr,&tmp_out,sizeof(tmp_out));
6063  }
6064  }
6065  return FALSE;
6066 }
6068 {
6069  WerrorS("not implemented");
6070  return TRUE;
6071 }
6072 BOOLEAN iiApplyIDEAL(leftv res, leftv a, int op, leftv proc)
6073 {
6074  WerrorS("not implemented");
6075  return TRUE;
6076 }
6077 BOOLEAN iiApplyLIST(leftv res, leftv a, int op, leftv proc)
6078 {
6079  lists aa=(lists)a->Data();
6080  sleftv tmp_out;
6081  sleftv tmp_in;
6082  leftv curr=res;
6083  BOOLEAN bo=FALSE;
6084  for(int i=0;i<=aa->nr; i++)
6085  {
6086  memset(&tmp_in,0,sizeof(tmp_in));
6087  tmp_in.Copy(&(aa->m[i]));
6088  if (proc==NULL)
6089  bo=iiExprArith1(&tmp_out,&tmp_in,op);
6090  else
6091  bo=jjPROC(&tmp_out,proc,&tmp_in);
6092  tmp_in.CleanUp();
6093  if (bo)
6094  {
6095  res->CleanUp(currRing);
6096  Werror("apply fails at index %d",i+1);
6097  return TRUE;
6098  }
6099  if (i==0) { memcpy(res,&tmp_out,sizeof(tmp_out)); }
6100  else
6101  {
6102  curr->next=(leftv)omAllocBin(sleftv_bin);
6103  curr=curr->next;
6104  memcpy(curr,&tmp_out,sizeof(tmp_out));
6105  }
6106  }
6107  return FALSE;
6108 }
6109 BOOLEAN iiApply(leftv res, leftv a, int op, leftv proc)
6110 {
6111  memset(res,0,sizeof(sleftv));
6112  res->rtyp=a->Typ();
6113  switch (res->rtyp /*a->Typ()*/)
6114  {
6115  case INTVEC_CMD:
6116  case INTMAT_CMD:
6117  return iiApplyINTVEC(res,a,op,proc);
6118  case BIGINTMAT_CMD:
6119  return iiApplyBIGINTMAT(res,a,op,proc);
6120  case IDEAL_CMD:
6121  case MODUL_CMD:
6122  case MATRIX_CMD:
6123  return iiApplyIDEAL(res,a,op,proc);
6124  case LIST_CMD:
6125  return iiApplyLIST(res,a,op,proc);
6126  }
6127  WerrorS("first argument to `apply` must allow an index");
6128  return TRUE;
6129 }
6130 
6132 {
6133  // assume a: level
6134  if ((a->Typ()==INT_CMD)&&((long)a->Data()>=0))
6135  {
6136  if ((TEST_V_ALLWARN) && (myynest==0)) WarnS("ASSUME at top level is of no use: see documentation");
6137  char assume_yylinebuf[80];
6138  strncpy(assume_yylinebuf,my_yylinebuf,79);
6139  int lev=(long)a->Data();
6140  int startlev=0;
6141  idhdl h=ggetid("assumeLevel");
6142  if ((h!=NULL)&&(IDTYP(h)==INT_CMD)) startlev=(long)IDINT(h);
6143  if(lev <=startlev)
6144  {
6145  BOOLEAN bo=b->Eval();
6146  if (bo) { WerrorS("syntax error in ASSUME");return TRUE;}
6147  if (b->Typ()!=INT_CMD) { WerrorS("ASUMME(<level>,<int expr>)");return TRUE; }
6148  if (b->Data()==NULL) { Werror("ASSUME failed:%s",assume_yylinebuf);return TRUE;}
6149  }
6150  }
6151  b->CleanUp();
6152  a->CleanUp();
6153  return FALSE;
6154 }
6155 
6156 #include "libparse.h"
6157 
6158 BOOLEAN iiARROW(leftv r, char* a, char *s)
6159 {
6160  char *ss=(char*)omAlloc(strlen(a)+strlen(s)+30); /* max. 27 currently */
6161  // find end of s:
6162  int end_s=strlen(s);
6163  while ((end_s>0) && ((s[end_s]<=' ')||(s[end_s]==';'))) end_s--;
6164  s[end_s+1]='\0';
6165  char *name=(char *)omAlloc(strlen(a)+strlen(s)+30);
6166  sprintf(name,"%s->%s",a,s);
6167  // find start of last expression
6168  int start_s=end_s-1;
6169  while ((start_s>=0) && (s[start_s]!=';')) start_s--;
6170  if (start_s<0) // ';' not found
6171  {
6172  sprintf(ss,"parameter def %s;return(%s);\n",a,s);
6173  }
6174  else // s[start_s] is ';'
6175  {
6176  s[start_s]='\0';
6177  sprintf(ss,"parameter def %s;%s;return(%s);\n",a,s,s+start_s+1);
6178  }
6179  memset(r,0,sizeof(*r));
6180  // now produce procinfo for PROC_CMD:
6181  r->data = (void *)omAlloc0Bin(procinfo_bin);
6182  ((procinfo *)(r->data))->language=LANG_NONE;
6183  iiInitSingularProcinfo((procinfo *)r->data,"",name,0,0);
6184  ((procinfo *)r->data)->data.s.body=ss;
6185  omFree(name);
6186  r->rtyp=PROC_CMD;
6187  //r->rtyp=STRING_CMD;
6188  //r->data=ss;
6189  return FALSE;
6190 }
6191 
6193 {
6194  int t=arg->Typ();
6195  char* ring_name=(char*)r->Name();
6196  ring_name=omStrDup(ring_name);
6197  if ((t==RING_CMD) ||(t==QRING_CMD))
6198  {
6199  sleftv tmp;
6200  memset(&tmp,0,sizeof(tmp));
6201  tmp.rtyp=IDHDL;
6202  tmp.data=(char*)rDefault(ring_name);
6203  if (tmp.data!=NULL)
6204  {
6205  BOOLEAN b=iiAssign(&tmp,arg);
6206  if (b) return TRUE;
6207  rSetHdl(ggetid(ring_name));
6208  omFree(ring_name);
6209  return FALSE;
6210  }
6211  else
6212  return TRUE;
6213  }
6214  else if (t==CRING_CMD)
6215  {
6216  sleftv tmp;
6217  sleftv n;
6218  memset(&n,0,sizeof(n));
6219  n.name=ring_name;
6220  if (iiDeclCommand(&tmp,&n,myynest,CRING_CMD,&IDROOT)) return TRUE;
6221  if (iiAssign(&tmp,arg)) return TRUE;
6222  //Print("create %s\n",r->Name());
6223  //Print("from %s(%d)\n",Tok2Cmdname(arg->Typ()),arg->Typ());
6224  return FALSE;
6225  }
6226  return TRUE;// not handled -> error for now
6227 }
6228 
6229 static void iiReportTypes(int nr,int t,const short *T)
6230 {
6231  char *buf=(char*)omAlloc(250);
6232  buf[0]='\0';
6233  if (nr==0)
6234  sprintf(buf,"wrong length of parameters(%d), expected ",t);
6235  else
6236  sprintf(buf,"par. %d is of type `%s`, expected ",nr,Tok2Cmdname(t));
6237  for(int i=1;i<=T[0];i++)
6238  {
6239  strcat(buf,"`");
6240  strcat(buf,Tok2Cmdname(T[i]));
6241  strcat(buf,"`");
6242  if (i<T[0]) strcat(buf,",");
6243  }
6244  WerrorS(buf);
6245 }
6246 
6247 BOOLEAN iiCheckTypes(leftv args, const short *type_list, int report)
6248 {
6249  if (args==NULL)
6250  {
6251  if (type_list[0]==0) return TRUE;
6252  else
6253  {
6254  if (report) WerrorS("no arguments expected");
6255  return FALSE;
6256  }
6257  }
6258  int l=args->listLength();
6259  if (l!=(int)type_list[0])
6260  {
6261  if (report) iiReportTypes(0,l,type_list);
6262  return FALSE;
6263  }
6264  for(int i=1;i<=l;i++,args=args->next)
6265  {
6266  short t=type_list[i];
6267  if (t!=ANY_TYPE)
6268  {
6269  if (((t==IDHDL)&&(args->rtyp!=IDHDL))
6270  || (t!=args->Typ()))
6271  {
6272  if (report) iiReportTypes(i,args->Typ(),type_list);
6273  return FALSE;
6274  }
6275  }
6276  }
6277  return TRUE;
6278 }
mpz_ptr base
Definition: rmodulon.h:18
int status int void size_t count
Definition: si_signals.h:58
int & rows()
Definition: matpol.h:24
int length
Definition: syz.h:60
BOOLEAN jjCHARSERIES(leftv res, leftv u)
Definition: ipshell.cc:3053
intvec ** weights
Definition: syz.h:45
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
for idElimination, like a, except pFDeg, pWeigths ignore it
Definition: ring.h:684
const const intvec const intvec const ring _currRing const const intvec const intvec const ring _currRing int
Definition: gb_hack.h:53
CanonicalForm map(const CanonicalForm &primElem, const Variable &alpha, const CanonicalForm &F, const Variable &beta)
map from to such that is mapped onto
Definition: cf_map_ext.cc:400
int iiRETURNEXPR_len
Definition: iplib.cc:518
int hMu2
Definition: hdegree.cc:22
complex root finder for univariate polynomials based on laguers algorithm
Definition: mpr_numeric.h:65
#define IDLIST(a)
Definition: ipid.h:136
void VoiceBackTrack()
Definition: fevoices.cc:75
ip_package * package
Definition: structs.h:46
#define omRealloc0Size(addr, o_size, size)
Definition: omAllocDecl.h:221
int cf_getSmallPrime(int i)
Definition: cf_primes.cc:28
#define pIsPurePower(p)
Definition: polys.h:219
#define idMaxIdeal(D)
initialise the maximal ideal (at 0)
Definition: ideals.h:38
const CanonicalForm int s
Definition: facAbsFact.cc:55
unsigned si_opt_1
Definition: options.c:5
void rDecomposeC(leftv h, const ring R)
Definition: ipshell.cc:1804
int iiTestConvert(int inputType, int outputType)
Definition: gentable.cc:290
sleftv * m
Definition: lists.h:45
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition: feread.cc:33
#define omCheckAddrSize(addr, size)
Definition: omAllocDecl.h:327
for int64 weights
Definition: ring.h:664
void atSet(idhdl root, const char *name, void *data, int typ)
Definition: attrib.cc:156
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
#define TRACE_SHOW_RINGS
Definition: reporter.h:28
void hDimSolve(scmon pure, int Npure, scfmon rad, int Nrad, varset var, int Nvar)
Definition: hdegree.cc:29
int Eval()
Definition: subexpr.cc:1715
spectrumPolyNode * next
Definition: splist.h:39
#define pSetm(p)
Definition: polys.h:241
resolvente syReorder(resolvente res, int length, syStrategy syzstr, BOOLEAN toCopy=TRUE, resolvente totake=NULL)
Definition: syz1.cc:1653
number * interpolateDense(const number *q)
Solves the Vandermode linear system {i=1}^{n} x_i^k-1 w_i = q_k, k=1,..,n.
Definition: mpr_numeric.cc:160
matrix mapToMatrix(matrix m)
ring rSubring(ring org_ring, sleftv *rv)
Definition: ipshell.cc:5653
spectrumState
Definition: ipshell.cc:3256
int yylineno
Definition: febase.cc:45
const poly a
Definition: syzextra.cc:212
void PrintLn()
Definition: reporter.cc:322
void compute()
#define ANY_TYPE
Definition: tok.h:34
#define Print
Definition: emacs.cc:83
Base class for solving 0-dim poly systems using u-resultant.
Definition: mpr_base.h:62
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:42
scfmon hwork
Definition: hutil.cc:19
void mu(int **points, int sizePoints)
Definition: tok.h:85
ring r
Definition: algext.h:40
void hIndAllMult(scmon pure, int Npure, scfmon rad, int Nrad, varset var, int Nvar)
Definition: hdegree.cc:494
#define IDLINK(a)
Definition: ipid.h:137
#define SHORT_REAL_LENGTH
Definition: numbers.h:54
int hNexist
Definition: hutil.cc:22
int * varset
Definition: hutil.h:23
idhdl currPackHdl
Definition: ipid.cc:60
vandermonde system solver for interpolating polynomials from their values
Definition: mpr_numeric.h:28
const short MAX_SHORT
Definition: ipshell.cc:5291
int hCo
Definition: hdegree.cc:22
Definition: attrib.h:14
resolvente liFindRes(lists L, int *len, int *typ0, intvec ***weights)
Definition: lists.cc:313
Subexpr e
Definition: subexpr.h:106
Rational weight
Definition: splist.h:41
static BOOLEAN rField_is_Zp_a(const ring r)
Definition: ring.h:469
Definition: lists.h:22
CanonicalForm num(const CanonicalForm &f)
virtual IStateType initState() const
Definition: mpr_base.h:41
procinfo * iiInitSingularProcinfo(procinfov pi, const char *libname, const char *procname, int line, long pos, BOOLEAN pstatic)
Definition: iplib.cc:966
ideal kStd(ideal F, ideal Q, tHomog h, intvec **w, intvec *hilb, int syzComp, int newIdeal, intvec *vw)
Definition: kstd1.cc:2067
#define IDINTVEC(a)
Definition: ipid.h:127
ring rCompose(const lists L, const BOOLEAN check_comp)
Definition: ipshell.cc:2255
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:44
BOOLEAN mpKoszul(leftv res, leftv c, leftv b, leftv id)
Definition: ipshell.cc:2795
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition: coeffs.h:37
loop
Definition: myNF.cc:98
BOOLEAN iiExprArith1(leftv res, leftv a, int op)
Definition: iparith.cc:8289
#define IDID(a)
Definition: ipid.h:121
BOOLEAN idIsZeroDim(ideal i, const ring R=currRing)
Definition: ideals.h:179
#define pSetExp(p, i, v)
Definition: polys.h:42
static int si_min(const int a, const int b)
Definition: auxiliary.h:167
BOOLEAN jjVARIABLES_P(leftv res, leftv u)
Definition: ipshell.cc:5996
idhdl rSimpleFindHdl(ring r, idhdl root, idhdl n)
Definition: ipshell.cc:5903
#define FALSE
Definition: auxiliary.h:140
Linear Programming / Linear Optimization using Simplex - Algorithm.
Definition: mpr_numeric.h:194
Compatiblity layer for legacy polynomial operations (over currRing)
BOOLEAN rSleftvOrdering2Ordering(sleftv *ord, ring R)
Definition: ipshell.cc:4987
BOOLEAN iiApplyBIGINTMAT(leftv res, leftv a, int op, leftv proc)
Definition: ipshell.cc:6067
attr * Attribute()
Definition: subexpr.cc:1346
Definition: tok.h:42
return P p
Definition: myNF.cc:203
opposite of ls
Definition: ring.h:685
int exprlist_length(leftv v)
Definition: ipshell.cc:549
BOOLEAN semicProc3(leftv res, leftv u, leftv v, leftv w)
Definition: ipshell.cc:4217
void syMinimizeResolvente(resolvente res, int length, int first)
Definition: syz.cc:360
Matrices of numbers.
Definition: bigintmat.h:32
BOOLEAN iiApplyIDEAL(leftv res, leftv a, int op, leftv proc)
Definition: ipshell.cc:6072
f
Definition: cfModGcd.cc:4022
static int rPar(const ring r)
(r->cf->P)
Definition: ring.h:538
Rational * s
Definition: semic.h:70
unsigned short fftable[]
Definition: ffields.cc:61
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:228
spectrum spectrumFromList(lists l)
Definition: ipshell.cc:3090
BOOLEAN jjPROC(leftv res, leftv u, leftv v)
Definition: iparith.cc:1605
lists syConvRes(syStrategy syzstr, BOOLEAN toDel, int add_row_shift)
Definition: ipshell.cc:2885
BOOLEAN jjRESULTANT(leftv res, leftv u, leftv v, leftv w)
Definition: ipshell.cc:3046
static BOOLEAN rField_is_R(const ring r)
Definition: ring.h:458
scmon * scfmon
Definition: hutil.h:22
#define pTest(p)
Definition: polys.h:387
char * filename
Definition: fevoices.h:62
void list_error(semicState state)
Definition: ipshell.cc:3174
static FORCE_INLINE void nSetChar(const coeffs r)
initialisations after each ring change
Definition: coeffs.h:436
static poly last
Definition: hdegree.cc:1056
#define pDecrExp(p, i)
Definition: polys.h:44
sleftv iiRETURNEXPR
Definition: iplib.cc:517
rational (GMP) numbers
Definition: coeffs.h:30
#define V_DEF_RES
Definition: options.h:48
resMatrixBase * accessResMat()
Definition: mpr_base.h:78
const char * GFPar_name
Definition: coeffs.h:94
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define IDNEXT(a)
Definition: ipid.h:117
int pg
Definition: semic.h:68
scfmon hexist
Definition: hutil.cc:19
Definition: grammar.cc:271
{p < 2^31}
Definition: coeffs.h:29
proclevel * procstack
Definition: ipid.cc:57
const ideal
Definition: gb_hack.h:42
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
BOOLEAN jjBETTI2(leftv res, leftv u, leftv v)
Definition: ipshell.cc:970
#define IDROOT
Definition: ipid.h:20
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:531
void id_Delete(ideal *h, ring r)
#define pNeg(p)
Definition: polys.h:169
intvec * ivCopy(const intvec *o)
Definition: intvec.h:132
BOOLEAN siq
Definition: subexpr.cc:58
static int * multiplicity
poly singclap_resultant(poly f, poly g, poly x, const ring r)
Definition: clapsing.cc:317
const char sNoName[]
Definition: subexpr.cc:56
int listLength()
Definition: subexpr.cc:61
monf hCreate(int Nvar)
Definition: hutil.cc:1002
long int64
Definition: auxiliary.h:112
void scComputeHC(ideal S, ideal Q, int ak, poly &hEdge, ring tailRing)
Definition: hdegree.cc:999
int hNvar
Definition: hutil.cc:22
intvec * id_QHomWeight(ideal id, const ring r)
int get_den_si()
Definition: GMPrat.cc:159
BOOLEAN nuVanderSys(leftv res, leftv arg1, leftv arg2, leftv arg3)
COMPUTE: polynomial p with values given by v at points p1,..,pN derived from p; more precisely: consi...
Definition: ipshell.cc:4516
resolvente res
Definition: syz.h:47
#define pCmp(p1, p2)
pCmp: args may be NULL returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2))) ...
Definition: polys.h:115
BOOLEAN spectrumProc(leftv result, leftv first)
Definition: ipshell.cc:3839
static BOOLEAN rField_is_Q_a(const ring r)
Definition: ring.h:479
BOOLEAN jjVARIABLES_ID(leftv res, leftv u)
Definition: ipshell.cc:6004
#define TRUE
Definition: auxiliary.h:144
#define nIsOne(n)
Definition: numbers.h:25
denominator_list DENOMINATOR_LIST
Definition: kutil.cc:81
uResultant::resMatType determineMType(int imtype)
Definition: mpr_inout.cc:135
int length() const
Definition: intvec.h:85
BOOLEAN maApplyFetch(int what, map theMap, leftv res, leftv w, ring preimage_r, int *perm, int *par_perm, int P, nMapFunc nMap)
Definition: maps_ip.cc:55
void type_cmd(leftv v)
Definition: ipshell.cc:248
BOOLEAN iiAssignCR(leftv r, leftv arg)
Definition: ipshell.cc:6192
#define IDIDEAL(a)
Definition: ipid.h:132
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1435
poly iiHighCorner(ideal I, int ak)
Definition: ipshell.cc:1605
void * ADDRESS
Definition: auxiliary.h:161
int hNrad
Definition: hutil.cc:22
intvec * zrovToIV()
int hNpure
Definition: hutil.cc:22
sleftv * leftv
Definition: structs.h:60
bool solver(const int polishmode=PM_NONE)
Definition: mpr_numeric.cc:450
void pWrite(poly p)
Definition: polys.h:279
BOOLEAN spmulProc(leftv result, leftv first, leftv second)
Definition: ipshell.cc:4176
BOOLEAN hasConstTerm(poly h, const ring r)
Definition: spectrum.h:28
scmon hpure
Definition: hutil.cc:20
void WerrorS(const char *s)
Definition: feFopen.cc:23
int k
Definition: cfEzgcd.cc:93
#define nIsMOne(n)
Definition: numbers.h:26
int min_in()
Definition: intvec.h:109
static BOOLEAN rField_is_GF(const ring r)
Definition: ring.h:461
static char const ** rParameter(const ring r)
(r->cf->parameter)
Definition: ring.h:564
void nlGMP(number &i, number n, const coeffs r)
Definition: longrat.cc:1397
#define Q
Definition: sirandom.c:25
int getAnzElems()
Definition: mpr_numeric.h:95
ring rAssure_HasComp(const ring r)
Definition: ring.cc:4532
ideal loNewtonPolytope(const ideal id)
Definition: mpr_base.cc:3192
void killlocals_rec(idhdl *root, int v, ring r)
Definition: ipshell.cc:325
int get_num_si()
Definition: GMPrat.cc:145
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
Definition: monomials.h:51
void hRadical(scfmon rad, int *Nrad, int Nvar)
Definition: hutil.cc:417
int traceit
Definition: febase.cc:47
#define WarnS
Definition: emacs.cc:81
rootContainer ** specializeInU(BOOLEAN matchUp=false, const number subDetVal=NULL)
Definition: mpr_base.cc:3060
CanonicalForm Lc(const CanonicalForm &f)
coeffs coeffs_BIGINT
Definition: ipid.cc:53
int hasOne(ideal J, const ring r)
Definition: spectrum.cc:96
int Typ()
Definition: subexpr.cc:949
#define omAlloc(size)
Definition: omAllocDecl.h:210
idhdl cRingHdl
Definition: ipid.h:60
BOOLEAN exitBuffer(feBufferTypes typ)
Definition: fevoices.cc:231
static void list1(const char *s, idhdl h, BOOLEAN c, BOOLEAN fullname)
Definition: ipshell.cc:151
static bool rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:355
poly numvec2poly(const number *q)
Definition: mpr_numeric.cc:107
void rComposeC(lists L, ring R)
Definition: ipshell.cc:2062
#define Sy_bit(x)
Definition: options.h:30
static void jjINT_S_TO_ID(int n, int *e, leftv res)
Definition: ipshell.cc:5974
const char * Name()
Definition: subexpr.h:121
scfmon hrad
Definition: hutil.cc:19
void Print(leftv store=NULL, int spaces=0)
Called by type_cmd (e.g. "r;") or as default in jPRINT.
Definition: subexpr.cc:73
int iiIsPrime0(unsigned p)
Definition: ipshell.cc:585
static int pLength(poly a)
Definition: p_polys.h:189
int int kStrategy strat if(h==NULL) return NULL
Creation data needed for finite fields.
Definition: coeffs.h:90
BOOLEAN iiExport(leftv v, int toLev)
Definition: ipshell.cc:1505
Definition: idrec.h:34
Definition: semic.h:63
#define IDHDL
Definition: tok.h:35
Definition: mpr_base.h:98
poly pp
Definition: myNF.cc:296
idhdl iiCurrProc
Definition: ipshell.cc:83
idhdl rDefault(const char *s)
Definition: ipshell.cc:1645
idhdl get(const char *s, int lev)
Definition: ipid.cc:90
real floating point (GMP) numbers
Definition: coeffs.h:33
BITSET validOpts
Definition: kstd1.cc:70
BOOLEAN iiParameter(leftv p)
Definition: ipshell.cc:1285
short float_len2
additional char-flags, rInit
Definition: coeffs.h:100
BOOLEAN iiAlias(leftv p)
Definition: ipshell.cc:1320
#define pGetVariables(p, e)
Definition: polys.h:222
bool found
Definition: facFactorize.cc:56
const char * currid
Definition: grammar.cc:172
intvec ** hilb_coeffs
Definition: syz.h:46
omBin procinfo_bin
Definition: subexpr.cc:51
#define nPrint(a)
only for debug, over any initalized currRing
Definition: numbers.h:46
lists getList(spectrum &spec)
Definition: ipshell.cc:3102
void ipListFlag(idhdl h)
Definition: ipid.cc:516
int iiRegularity(lists L)
Definition: ipshell.cc:997
void * data
Definition: subexpr.h:89
void rDecomposeCF(leftv h, const ring r, const ring R)
Definition: ipshell.cc:1716
void hDelete(scfmon ev, int ev_length)
Definition: hutil.cc:146
#define pIter(p)
Definition: monomials.h:44
poly res
Definition: myNF.cc:322
BOOLEAN iiTestAssume(leftv a, leftv b)
Definition: ipshell.cc:6131
semicState list_is_spectrum(lists l)
Definition: ipshell.cc:3959
Definition: subexpr.h:20
BOOLEAN kWeight(leftv res, leftv id)
Definition: ipshell.cc:3007
int rTypeOfMatrixOrder(intvec *order)
Definition: ring.cc:195
#define IDPACKAGE(a)
Definition: ipid.h:138
int myynest
Definition: febase.cc:46
#define omReallocSize(addr, o_size, size)
Definition: omAllocDecl.h:220
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:12
char * char_ptr
Definition: structs.h:56
#define pGetExp(p, i)
Exponent.
Definition: polys.h:41
#define IDTYP(a)
Definition: ipid.h:118
indset ISet
Definition: hdegree.cc:277
single prescision (6,6) real numbers
Definition: coeffs.h:31
void * CopyA()
Definition: subexpr.cc:1912
void killhdl2(idhdl h, idhdl *ih, ring r)
Definition: ipid.cc:400
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:256
spectrumPolyNode * root
Definition: splist.h:60
BOOLEAN hasLinearTerm(poly h, const ring r)
Definition: spectrum.h:30
static int rBlocks(ring r)
Definition: ring.h:507
BOOLEAN syBetti1(leftv res, leftv u)
Definition: ipshell.cc:2873
Definition: tok.h:56
int RingDependend(int t)
Definition: gentable.cc:23
spectrumState spectrumStateFromList(spectrumPolyList &speclist, lists *L, int fast)
Definition: ipshell.cc:3275
char my_yylinebuf[80]
Definition: febase.cc:48
BOOLEAN nuLagSolve(leftv res, leftv arg1, leftv arg2, leftv arg3)
find the (complex) roots an univariate polynomial Determines the roots of an univariate polynomial us...
Definition: ipshell.cc:4384
short float_len
additional char-flags, rInit
Definition: coeffs.h:99
const ring r
Definition: syzextra.cc:208
Coefficient rings, fields and other domains suitable for Singular polynomials.
resolvente orderedRes
Definition: syz.h:48
BOOLEAN killlocals_list(int v, lists L)
Definition: ipshell.cc:362
BOOLEAN RingDependend()
Definition: subexpr.cc:369
static FORCE_INLINE BOOLEAN nCoeff_is_algExt(const coeffs r)
TRUE iff r represents an algebraic extension field.
Definition: coeffs.h:906
intvec * posvToIV()
Definition: intvec.h:16
#define pSub(a, b)
Definition: polys.h:258
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
void hKill(monf xmem, int Nvar)
Definition: hutil.cc:1016
void rKill(ring r)
Definition: ipshell.cc:5815
BOOLEAN rComplete(ring r, int force)
this needs to be called whenever a new ring is created: new fields in ring are created (like VarOffse...
Definition: ring.cc:3371
for(int i=0;i< R->ExpL_Size;i++) Print("%09lx "
Definition: cfEzgcd.cc:66
varset hvar
Definition: hutil.cc:21
BOOLEAN mapFromMatrix(matrix m)
void list_cmd(int typ, const char *what, const char *prefix, BOOLEAN iterate, BOOLEAN fullname)
Definition: ipshell.cc:422
void computeNF(ideal stdJ, poly hc, poly wc, spectrumPolyList *NF, const ring r)
Definition: spectrum.cc:309
int j
Definition: myNF.cc:70
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:43
Definition: tok.h:58
Definition: ipid.h:56
const char * name
Definition: subexpr.h:88
#define omFree(addr)
Definition: omAllocDecl.h:261
static long pTotaldegree(poly p)
Definition: polys.h:253
static leftv rOptimizeOrdAsSleftv(leftv ord)
Definition: ipshell.cc:4875
polyrec * poly
Definition: hilb.h:10
BOOLEAN rCheckIV(intvec *iv)
Definition: ring.cc:185
#define assume(x)
Definition: mod2.h:405
int search(const CFArray &A, const CanonicalForm &F, int i, int j)
search for F in A between index i and j
The main handler for Singular numbers which are suitable for Singular polynomials.
static BOOLEAN iiNoKeepRing
Definition: ipshell.cc:86
void hIndMult(scmon pure, int Npure, scfmon rad, int Nrad, varset var, int Nvar)
Definition: hdegree.cc:311
double(* wFunctional)(int *degw, int *lpol, int npol, double *rel, double wx, double wNsqr)
Definition: weight.cc:28
int status int void * buf
Definition: si_signals.h:58
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition: ring.cc:1281
indlist * indset
Definition: hutil.h:35
int GFDegree
Definition: coeffs.h:93
void hPure(scfmon stc, int a, int *Nstc, varset var, int Nvar, scmon pure, int *Npure)
Definition: hutil.cc:627
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:71
BOOLEAN hasAxis(ideal J, int k, const ring r)
Definition: spectrum.cc:81
void killlocals(int v)
Definition: ipshell.cc:382
complex floating point (GMP) numbers
Definition: coeffs.h:40
static FORCE_INLINE char * nCoeffName(const coeffs cf)
Definition: coeffs.h:962
Definition: grammar.cc:270
const char * rSimpleOrdStr(int ord)
Definition: ring.cc:88
ip_smatrix * matrix
int mult_spectrumh(spectrum &)
Definition: semic.cc:425
gmp_float sqrt(const gmp_float &a)
Definition: mpr_complex.cc:329
bool success()
Definition: mpr_numeric.h:162
#define IDSTRING(a)
Definition: ipid.h:135
#define rTest(r)
Definition: ring.h:769
idhdl currRingHdl
Definition: ipid.cc:64
static resolvente iiCopyRes(resolvente r, int l)
Definition: ipshell.cc:905
BOOLEAN nuUResSolve(leftv res, leftv args)
solve a multipolynomial system using the u-resultant Input ideal must be 0-dimensional and (currRing-...
Definition: ipshell.cc:4617
omBin indlist_bin
Definition: hdegree.cc:23
void Copy(leftv e)
Definition: subexpr.cc:637
static void iiReportTypes(int nr, int t, const short *T)
Definition: ipshell.cc:6229
#define setFlag(A, F)
Definition: ipid.h:112
indset JSet
Definition: hdegree.cc:277
All the auxiliary stuff.
#define pSetComp(p, v)
Definition: polys.h:38
void arrange()
Definition: mpr_numeric.cc:896
int rOrderName(char *ordername)
Definition: ring.cc:508
omBin sip_sring_bin
Definition: ring.cc:54
int m
Definition: cfEzgcd.cc:119
void idDelete(ideal *h, ring r=currRing)
delete an ideal
Definition: ideals.h:31
void idGetNextChoise(int r, int end, BOOLEAN *endch, int *choise)
#define pIsConstant(p)
like above, except that Comp might be != 0
Definition: polys.h:209
proclevel * next
Definition: ipid.h:59
#define pMult_nn(p, n)
Definition: polys.h:171
int * scmon
Definition: hutil.h:21
struct for passing initialization parameters to naInitChar
Definition: transext.h:92
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:41
BOOLEAN iiApplyLIST(leftv res, leftv a, int op, leftv proc)
Definition: ipshell.cc:6077
void spectrumPrintError(spectrumState state)
Definition: ipshell.cc:3808
void fillContainer(number *_coeffs, number *_ievpoint, const int _var, const int _tdg, const rootType _rt, const int _anz)
Definition: mpr_numeric.cc:313
const char * iiTwoOps(int t)
Definition: ipshell.cc:90
static int si_max(const int a, const int b)
Definition: auxiliary.h:166
unsigned long exp
Definition: rmodulon.h:18
#define info
Definition: libparse.cc:1254
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
Definition: coeffs.h:914
idrec * idhdl
Definition: ring.h:18
virtual ideal getMatrix()
Definition: mpr_base.h:31
int cf_getNumSmallPrimes()
Definition: cf_primes.cc:34
int IsPrime(int p)
Definition: ipshell.cc:633
omBin sleftv_bin
Definition: subexpr.cc:50
int i
Definition: cfEzgcd.cc:123
Induced (Schreyer) ordering.
Definition: ring.h:686
void PrintS(const char *s)
Definition: reporter.cc:294
BOOLEAN iiDebugMarker
Definition: ipshell.cc:1023
matrix singclap_irrCharSeries(ideal I, const ring r)
Definition: clapsing.cc:1398
static BOOLEAN rField_is_Q(const ring r)
Definition: ring.h:452
lists rDecompose(const ring r)
Definition: ipshell.cc:1869
idhdl next
Definition: idrec.h:38
BOOLEAN spectrumfProc(leftv result, leftv first)
Definition: ipshell.cc:3890
S?
Definition: ring.h:668
#define pOne()
Definition: polys.h:286
gmp_complex * getRoot(const int i)
Definition: mpr_numeric.h:88
idhdl rFindHdl(ring r, idhdl n)
Definition: ipshell.cc:1690
void iiDebug()
Definition: ipshell.cc:1025
Definition: tok.h:88
void solve_all()
Definition: mpr_numeric.cc:871
#define IDELEMS(i)
Definition: simpleideals.h:19
BOOLEAN loSimplex(leftv res, leftv args)
Implementation of the Simplex Algorithm.
Definition: ipshell.cc:4275
BOOLEAN rEqual(ring r1, ring r2, BOOLEAN qr)
returns TRUE, if r1 equals r2 FALSE, otherwise Equality is determined componentwise, if qr == 1, then qrideal equality is tested, as well
Definition: ring.cc:1594
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition: coeffs.h:718
lists scIndIndset(ideal S, BOOLEAN all, ideal Q)
Definition: ipshell.cc:1060
spectrumState spectrumCompute(poly h, lists *L, int fast)
Definition: ipshell.cc:3516
CFList tmp2
Definition: facFqBivar.cc:70
mprState mprIdealCheck(const ideal theIdeal, const char *name, uResultant::resMatType mtype, BOOLEAN rmatrix=false)
Definition: mpr_inout.cc:94
void idSkipZeroes(ideal ide)
void iiMakeResolv(resolvente r, int length, int rlen, char *name, int typ0, intvec **weights)
Definition: ipshell.cc:816
rootContainer ** interpolateDenseSP(BOOLEAN matchUp=false, const number subDetVal=NULL)
Definition: mpr_base.cc:2922
#define IDLEV(a)
Definition: ipid.h:120
resolvente fullres
Definition: syz.h:57
static void rRenameVars(ring R)
Definition: ipshell.cc:2214
const char * VoiceName()
Definition: fevoices.cc:64
#define nDelete(n)
Definition: numbers.h:16
semicState
Definition: ipshell.cc:3140
#define IDMAP(a)
Definition: ipid.h:134
int cols() const
Definition: bigintmat.h:128
#define FLAG_STD
Definition: ipid.h:108
short errorreported
Definition: feFopen.cc:22
int n
Definition: semic.h:69
leftv next
Definition: subexpr.h:87
static BOOLEAN rField_is_long_C(const ring r)
Definition: ring.h:485
#define rHasLocalOrMixedOrdering_currRing()
Definition: ring.h:748
void test_cmd(int i)
Definition: ipshell.cc:511
void rChangeCurrRing(ring r)
Definition: polys.cc:14
#define IDNUMBER(a)
Definition: ipid.h:131
resolvente minres
Definition: syz.h:58
static BOOLEAN rField_is_Zp(const ring r)
Definition: ring.h:446
void hLexR(scfmon rad, int Nrad, varset var, int Nvar)
Definition: hutil.cc:571
#define BVERBOSE(a)
Definition: options.h:33
INLINE_THIS void Init(int l=0)
Definition: lists.h:66
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition: matpol.cc:48
CanonicalForm buf2
Definition: facFqBivar.cc:71
#define nInvers(a)
Definition: numbers.h:33
BOOLEAN syBetti2(leftv res, leftv u, leftv w)
Definition: ipshell.cc:2850
Definition: tok.h:38
int iiDeclCommand(leftv sy, leftv name, int lev, int t, idhdl *root, BOOLEAN isring, BOOLEAN init_b)
Definition: ipshell.cc:1160
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
BOOLEAN iiAllStart(procinfov pi, char *p, feBufferTypes t, int l)
Definition: iplib.cc:312
int GFChar
Definition: coeffs.h:92
#define IDPROC(a)
Definition: ipid.h:139
void paPrint(const char *n, package p)
Definition: ipshell.cc:6019
BOOLEAN iiCheckRing(int i)
Definition: ipshell.cc:1585
#define pi
Definition: libparse.cc:1143
ideal idInit(int idsize, int rank)
Definition: simpleideals.cc:40
poly p_PermPoly(poly p, const int *perm, const ring oldRing, const ring dst, nMapFunc nMap, const int *par_perm, int OldPar)
Definition: p_polys.cc:3892
BOOLEAN nc_CallPlural(matrix cc, matrix dd, poly cn, poly dn, ring r, bool bSetupQuotient, bool bCopyInput, bool bBeQuiet, ring curr, bool dummy_ring=false)
returns TRUE if there were errors analyze inputs, check them for consistency detects nc_type...
Definition: old.gring.cc:2734
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
BOOLEAN kQHWeight(leftv res, leftv v)
Definition: ipshell.cc:3029
static BOOLEAN iiInternalExport(leftv v, int toLev)
Definition: ipshell.cc:1397
ring * iiLocalRing
Definition: iplib.cc:515
void * atGet(idhdl root, const char *name, int t, void *defaultReturnValue)
Definition: attrib.cc:135
int nr
Definition: lists.h:43
int rows() const
Definition: bigintmat.h:129
int & cols()
Definition: matpol.h:25
char name(const Variable &v)
Definition: variable.h:95
void maFindPerm(char const *const *const preim_names, int preim_n, char const *const *const preim_par, int preim_p, char const *const *const names, int n, char const *const *const par, int nop, int *perm, int *par_perm, n_coeffType ch)
Definition: maps.cc:169
#define ppMult_nn(p, n)
Definition: polys.h:170
void rComposeRing(lists L, ring R)
Definition: ipshell.cc:2121
int mu
Definition: semic.h:67
CanonicalForm cf
Definition: cfModGcd.cc:4024
#define MATCOLS(i)
Definition: matpol.h:28
Definition: tok.h:95
void mult(unsigned long *result, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition: minpoly.cc:649
#define BREAK_LINE_LENGTH
Definition: ipshell.cc:1024
#define nIsZero(n)
Definition: numbers.h:19
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:428
void rDecomposeRing(leftv h, const ring R)
Definition: ipshell.cc:1840
#define NULL
Definition: omList.c:10
attr attribute
Definition: idrec.h:41
poly * polyset
Definition: hutil.h:17
slists * lists
Definition: mpr_numeric.h:146
intvec * syBettiOfComputation(syStrategy syzstr, BOOLEAN minim=TRUE, int *row_shift=NULL, intvec *weights=NULL)
Definition: syz1.cc:1767
int getAnzRoots()
Definition: mpr_numeric.h:97
package req_packhdl
Definition: subexpr.h:107
BOOLEAN iiDefaultParameter(leftv p)
Definition: ipshell.cc:1202
{p^n < 2^16}
Definition: coeffs.h:32
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition: coeffs.h:451
CanonicalForm den(const CanonicalForm &f)
struct for passing initialization parameters to naInitChar
Definition: algext.h:40
void wCall(poly *s, int sl, int *x, double wNsqr, const ring R)
Definition: weight.cc:116
BOOLEAN semicProc(leftv res, leftv u, leftv v)
Definition: ipshell.cc:4257
void rDelete(ring r)
unconditionally deletes fields in r
Definition: ring.cc:448
BOOLEAN nuMPResMat(leftv res, leftv arg1, leftv arg2)
returns module representing the multipolynomial resultant matrix Arguments 2: ideal i...
Definition: ipshell.cc:4361
#define IDINT(a)
Definition: ipid.h:124
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:128
#define IDPOLY(a)
Definition: ipid.h:129
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic ...
Definition: coeffs.h:34
Voice * currentVoice
Definition: fevoices.cc:55
BOOLEAN iiWRITE(leftv, leftv v)
Definition: ipshell.cc:643
BOOLEAN iiCheckTypes(leftv args, const short *type_list, int report)
check a list of arguemys against a given field of types return TRUE if the types match return FALSE (...
Definition: ipshell.cc:6247
BOOLEAN jjBETTI(leftv res, leftv u)
Definition: ipshell.cc:936
package basePack
Definition: ipid.cc:63
coeffs basecoeffs() const
Definition: bigintmat.h:130
#define R
Definition: sirandom.c:26
void copy_new(int)
Definition: semic.cc:54
static BOOLEAN rField_is_Ring_Z(const ring r)
Definition: ring.h:425
void pNorm(poly p, const ring R=currRing)
Definition: polys.h:334
BOOLEAN iiConvert(int inputType, int outputType, int index, leftv input, leftv output, struct sConvertTypes *dConvertTypes)
Definition: ipconv.cc:295
static BOOLEAN rField_is_long_R(const ring r)
Definition: ring.h:482
lists liMakeResolv(resolvente r, int length, int reallen, int typ0, intvec **weights, int add_row_shift)
Definition: lists.cc:216
denominator_list next
Definition: kutil.h:65
void idInitChoise(int r, int beg, int end, BOOLEAN *endch, int *choise)
monf radmem
Definition: hutil.cc:24
#define IDRING(a)
Definition: ipid.h:126
const CanonicalForm & w
Definition: facAbsFact.cc:55
strat ak
Definition: myNF.cc:321
#define pDelete(p_ptr)
Definition: polys.h:157
package currPack
Definition: ipid.cc:62
ring cRing
Definition: ipid.h:61
int iiOpsTwoChar(const char *s)
Definition: ipshell.cc:123
leftv iiCurrArgs
Definition: ipshell.cc:82
Variable x
Definition: cfModGcd.cc:4023
int rtyp
Definition: subexpr.h:92
ideal fast_map(ideal map_id, ring map_r, ideal image_id, ring image_r)
Definition: fast_maps.cc:354
BOOLEAN jjMINRES(leftv res, leftv v)
Definition: ipshell.cc:915
#define nCopy(n)
Definition: numbers.h:15
sleftv sLastPrinted
Definition: subexpr.cc:55
void CleanUp(ring r=currRing)
Definition: subexpr.cc:301
void Clean(ring r=currRing)
Definition: lists.h:25
#define pNext(p)
Definition: monomials.h:43
void * Data()
Definition: subexpr.cc:1091
int * w
Definition: semic.h:71
#define nSetMap(R)
Definition: numbers.h:43
const char * par_name
parameter name
Definition: coeffs.h:101
ideal idrCopyR(ideal id, ring src_r, ring dest_r)
Definition: prCopy.cc:192
int typ
Definition: idrec.h:43
short list_length
Definition: syz.h:62
#define pSetCoeff0(p, n)
Definition: monomials.h:67
static int rInternalChar(const ring r)
Definition: ring.h:628
Definition: tok.h:96
matrix mp_Copy(matrix a, const ring r)
copies matrix a (from ring r to r)
Definition: matpol.cc:74
ideal * resolvente
Definition: ideals.h:20
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition: fevoices.cc:169
syStrategy syConvList(lists li, BOOLEAN toDel)
Definition: ipshell.cc:2961
BOOLEAN iiApplyINTVEC(leftv res, leftv a, int op, leftv proc)
Definition: ipshell.cc:6035
number nlMapGMP(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:208
ideal idCopy(ideal A, const ring R=currRing)
Definition: ideals.h:76
attr attribute
Definition: subexpr.h:90
omBin slists_bin
Definition: lists.cc:23
BOOLEAN iiARROW(leftv r, char *a, char *s)
Definition: ipshell.cc:6158
BOOLEAN ringIsLocal(const ring r)
Definition: spectrum.cc:461
BOOLEAN spaddProc(leftv result, leftv first, leftv second)
Definition: ipshell.cc:4134
int idGetNumberOfChoise(int t, int d, int begin, int end, int *choise)
attr get(const char *s)
Definition: attrib.cc:96
char * complexToStr(gmp_complex &c, const unsigned int oprec, const coeffs src)
Definition: mpr_complex.cc:717
Definition: tok.h:126
intvec * syBetti(resolvente res, int length, int *regularity, intvec *weights, BOOLEAN tomin, int *row_shift)
Definition: syz.cc:793
int hisModule
Definition: hutil.cc:23
leftv iiMap(map theMap, const char *what)
Definition: ipshell.cc:670
size_t gmp_output_digits
Definition: mpr_complex.cc:44
ring rInit(sleftv *pn, sleftv *rv, sleftv *ord)
Definition: ipshell.cc:5304
#define pDiff(a, b)
Definition: polys.h:267
idhdl packFindHdl(package r)
Definition: ipid.cc:729
#define omCheckAddr(addr)
Definition: omAllocDecl.h:328
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
void iiCheckPack(package &p)
Definition: ipshell.cc:1629
ideal singclap_factorize(poly f, intvec **v, int with_exps, const ring r)
Definition: clapsing.cc:784
#define MATROWS(i)
Definition: matpol.h:27
void wrp(poly p)
Definition: polys.h:281
void setGMPFloatDigits(size_t digits, size_t rest)
Set size of mantissa digits - the number of output digits (basis 10) the size of mantissa consists of...
Definition: mpr_complex.cc:62
int icase
Definition: mpr_numeric.h:201
kBucketDestroy & P
Definition: myNF.cc:191
static jList * T
Definition: janet.cc:37
#define IDDATA(a)
Definition: ipid.h:125
void rSetHdl(idhdl h)
Definition: ipshell.cc:4821
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
BITSET kOptions
Definition: kstd1.cc:55
BOOLEAN iiBranchTo(leftv r, leftv args)
Definition: ipshell.cc:1215
#define nInit(i)
Definition: numbers.h:24
Rational pow(const Rational &a, int e)
Definition: GMPrat.cc:418
unsigned si_opt_2
Definition: options.c:6
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition: iplib.cc:200
BOOLEAN rSleftvList2StringArray(sleftv *sl, char **p)
Definition: ipshell.cc:5260
int * int_ptr
Definition: structs.h:57
static Poly * h
Definition: janet.cc:978
s?
Definition: ring.h:669
int BOOLEAN
Definition: auxiliary.h:131
static poly p_Init(const ring r, omBin bin)
Definition: p_polys.h:1248
BOOLEAN idIs0(ideal h)
const poly b
Definition: syzextra.cc:213
BOOLEAN jjBETTI2_ID(leftv res, leftv u, leftv v)
Definition: ipshell.cc:949
void syKillEmptyEntres(resolvente res, int length)
Definition: syz1.cc:2209
BOOLEAN iiApply(leftv res, leftv a, int op, leftv proc)
Definition: ipshell.cc:6109
int mult_spectrum(spectrum &)
Definition: semic.cc:396
package cPack
Definition: ipid.h:63
lists listOfRoots(rootArranger *self, const unsigned int oprec)
Definition: ipshell.cc:4774
static BOOLEAN rField_is_numeric(const ring r)
Definition: ring.h:455
BOOLEAN lRingDependend(lists L)
Definition: lists.cc:199
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:477
scfmon hInit(ideal S, ideal Q, int *Nexist, ring tailRing)
Definition: hutil.cc:34
#define V_REDEFINE
Definition: options.h:43
void copy_deep(spectrum &spec, lists l)
Definition: ipshell.cc:3066
void delete_node(spectrumPolyNode **)
Definition: splist.cc:256
int binom(int n, int r)
void Werror(const char *fmt,...)
Definition: reporter.cc:199
virtual number getSubDet()
Definition: mpr_base.h:37
ideal kGroebner(ideal F, ideal Q)
Definition: ipshell.cc:5929
#define TEST_V_ALLWARN
Definition: options.h:135
void syKillComputation(syStrategy syzstr, ring r=currRing)
Definition: syz1.cc:1497
void * CopyD(int t)
Definition: subexpr.cc:656
const char * lastreserved
Definition: ipshell.cc:84
int hMu
Definition: hdegree.cc:22
idhdl ggetid(const char *n, BOOLEAN, idhdl *packhdl)
Definition: ipid.cc:487
int atyp
Definition: attrib.h:21
static FORCE_INLINE void n_MPZ(mpz_t result, number &n, const coeffs r)
conversion of n to a GMP integer; 0 if not possible
Definition: coeffs.h:550
#define omAlloc0(size)
Definition: omAllocDecl.h:211
static void killlocals0(int v, idhdl *localhdl, const ring r)
Definition: ipshell.cc:290
return result
Definition: facAbsBiFact.cc:76
int l
Definition: cfEzgcd.cc:94
double wFunctionalBuch(int *degw, int *lpol, int npol, double *rel, double wx, double wNsqr)
Definition: weight0.c:82
int sign(const CanonicalForm &a)
#define IDMATRIX(a)
Definition: ipid.h:133
BOOLEAN loNewtonP(leftv res, leftv arg1)
compute Newton Polytopes of input polynomials
Definition: ipshell.cc:4269
#define pCopy(p)
return a copy of the poly
Definition: polys.h:156
#define MATELEM(mat, i, j)
Definition: matpol.h:29
poly computeWC(const newtonPolygon &np, Rational max_weight, const ring r)
Definition: spectrum.cc:142
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:316
syStrategy syForceMin(lists li)
Definition: ipshell.cc:2991
ssyStrategy * syStrategy
Definition: syz.h:35
utypes data
Definition: idrec.h:40
int IsCmd(const char *n, int &tok)
Definition: iparith.cc:8688
void hSupp(scfmon stc, int Nstc, varset var, int *Nvar)
Definition: hutil.cc:180
BOOLEAN iiAssign(leftv l, leftv r, BOOLEAN toplevel)
Definition: ipassign.cc:1659
BOOLEAN mpJacobi(leftv res, leftv a)
Definition: ipshell.cc:2773
#define Warn
Definition: emacs.cc:80
#define omStrDup(s)
Definition: omAllocDecl.h:263