iparith.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 
5 /*
6 * ABSTRACT: table driven kernel interface, used by interpreter
7 */
8 
9 
10 #include <kernel/mod2.h>
11 
12 #include <omalloc/omalloc.h>
13 
14 #include <factory/factory.h>
15 
16 #include <coeffs/bigintmat.h>
17 #include <coeffs/coeffs.h>
18 #include <coeffs/numbers.h>
19 
20 
21 #include <misc/options.h>
22 #include <misc/intvec.h>
23 #include <misc/sirandom.h>
24 #include <misc/prime.h>
25 
26 #include <polys/prCopy.h>
27 #include <polys/matpol.h>
28 #include <polys/monomials/maps.h>
29 #include <polys/coeffrings.h>
30 #include <polys/sparsmat.h>
31 #include <polys/weight.h>
33 #include <polys/clapsing.h>
34 
37 
41 
42 #include <kernel/spectrum/GMPrat.h>
44 #include <kernel/oswrapper/timer.h>
45 #include <kernel/fglm/fglm.h>
46 
48 #include <kernel/GBEngine/syz.h>
49 #include <kernel/GBEngine/kstd1.h>
50 #include <kernel/GBEngine/units.h>
51 #include <kernel/GBEngine/tgb.h>
52 
53 #include <kernel/preimage.h>
54 #include <kernel/polys.h>
55 #include <kernel/ideals.h>
56 
57 #include <Singular/mod_lib.h>
58 #include <Singular/fevoices.h>
59 #include <Singular/tok.h>
60 #include <Singular/ipid.h>
61 #include <Singular/sdb.h>
62 #include <Singular/subexpr.h>
63 #include <Singular/lists.h>
64 #include <Singular/maps_ip.h>
65 
66 #include <Singular/ipconv.h>
67 #include <Singular/ipprint.h>
68 #include <Singular/attrib.h>
69 #include <Singular/links/silink.h>
70 #include <Singular/misc_ip.h>
72 
73 #ifdef SINGULAR_4_1
74 #include <Singular/number2.h>
75 #endif
76 
77 # include <Singular/fglm.h>
78 
79 #include <Singular/blackbox.h>
80 #include <Singular/newstruct.h>
81 #include <Singular/ipshell.h>
82 //#include <kernel/mpr_inout.h>
83 
84 #include <reporter/si_signals.h>
85 
86 
87 #include <stdlib.h>
88 #include <string.h>
89 #include <ctype.h>
90 #include <stdio.h>
91 #include <time.h>
92 #include <unistd.h>
93 #include <vector>
94 
95 lists rDecompose(const ring r);
96 ring rCompose(const lists L, const BOOLEAN check_comp=TRUE);
97 
98 
99 // defaults for all commands: NO_PLURAL | NO_RING | ALLOW_ZERODIVISOR
100 
101 #ifdef HAVE_PLURAL
102  #include <kernel/GBEngine/ratgring.h>
103  #include <kernel/GBEngine/nc.h>
104  #include <polys/nc/nc.h>
105  #include <polys/nc/sca.h>
106  #define PLURAL_MASK 3
107 #else /* HAVE_PLURAL */
108  #define PLURAL_MASK 0
109 #endif /* HAVE_PLURAL */
110 
111 #ifdef HAVE_RINGS
112  #define RING_MASK 4
113  #define ZERODIVISOR_MASK 8
114 #else
115  #define RING_MASK 0
116  #define ZERODIVISOR_MASK 0
117 #endif
118 #define ALLOW_PLURAL 1
119 #define NO_PLURAL 0
120 #define COMM_PLURAL 2
121 #define ALLOW_RING 4
122 #define NO_RING 0
123 #define NO_ZERODIVISOR 8
124 #define ALLOW_ZERODIVISOR 0
125 
126 // bit 4 for warning, if used at toplevel
127 #define WARN_RING 16
128 
129 static BOOLEAN check_valid(const int p, const int op);
130 
131 #ifdef SINGULAR_4_1
132 // helper routine to catch all library/test parts which need to be changed
133 // shall go away after the transition
134 static void iiReWrite(const char *s)
135 {
136  Print("please rewrite the use of >>%s<< in >>%s<<\n"
137  "%s is depreciated or changed in Singular 4-1\n",s,my_yylinebuf,s);
138 }
139 #endif
140 
141 /*=============== types =====================*/
143 {
144  short cmd;
145  short start;
146 };
147 
149 
150 struct _scmdnames
151 {
152  char *name;
153  short alias;
154  short tokval;
155  short toktype;
156 };
157 typedef struct _scmdnames cmdnames;
158 
159 
160 typedef char * (*Proc1)(char *);
161 struct sValCmd1
162 {
164  short cmd;
165  short res;
166  short arg;
167  short valid_for;
168 };
169 
171 struct sValCmd2
172 {
174  short cmd;
175  short res;
176  short arg1;
177  short arg2;
178  short valid_for;
179 };
180 
182 struct sValCmd3
183 {
185  short cmd;
186  short res;
187  short arg1;
188  short arg2;
189  short arg3;
190  short valid_for;
191 };
192 struct sValCmdM
193 {
195  short cmd;
196  short res;
197  short number_of_args; /* -1: any, -2: any >0, .. */
198  short valid_for;
199 };
200 
201 typedef struct
202 {
203  cmdnames *sCmds; /**< array of existing commands */
208  int nCmdUsed; /**< number of commands used */
209  int nCmdAllocated; /**< number of commands-slots allocated */
210  int nLastIdentifier; /**< valid indentifieres are slot 1..nLastIdentifier */
211 } SArithBase;
212 
213 /*---------------------------------------------------------------------*
214  * File scope Variables (Variables share by several functions in
215  * the same file )
216  *
217  *---------------------------------------------------------------------*/
218 static SArithBase sArithBase; /**< Base entry for arithmetic */
219 
220 /*---------------------------------------------------------------------*
221  * Extern Functions declarations
222  *
223  *---------------------------------------------------------------------*/
224 static int _gentable_sort_cmds(const void *a, const void *b);
225 extern int iiArithRemoveCmd(char *szName);
226 extern int iiArithAddCmd(const char *szName, short nAlias, short nTokval,
227  short nToktype, short nPos=-1);
228 
229 /*============= proc =======================*/
230 static int iiTabIndex(const jjValCmdTab dArithTab, const int len, const int op);
231 static Subexpr jjMakeSub(leftv e);
232 
233 /*============= vars ======================*/
234 extern int cmdtok;
235 extern BOOLEAN expected_parms;
236 
237 #define ii_div_by_0 "div. by 0"
238 
239 int iiOp; /* the current operation*/
240 
241 /*=================== simple helpers =================*/
242 static int iin_Int(number &n,coeffs cf)
243 {
244  long l=n_Int(n,cf);
245  int i=(int)l;
246  if ((long)i==l) return l;
247  return 0;
248 }
250 {
251  return pHead(p);
252 }
253 
254 int iiTokType(int op)
255 {
256  for (int i=0;i<sArithBase.nCmdUsed;i++)
257  {
258  if (sArithBase.sCmds[i].tokval==op)
259  return sArithBase.sCmds[i].toktype;
260  }
261  return 0;
262 }
263 
264 /*=================== operations with 2 args.: static proc =================*/
265 /* must be ordered: first operations for chars (infix ops),
266  * then alphabetically */
267 
269 {
270  bigintmat* aa= (bigintmat *)u->Data();
271  int bb = (int)(long)(v->Data());
272  if (errorreported) return TRUE;
273  bigintmat *cc=NULL;
274  switch (iiOp)
275  {
276  case '+': cc=bimAdd(aa,bb); break;
277  case '-': cc=bimSub(aa,bb); break;
278  case '*': cc=bimMult(aa,bb); break;
279  }
280  res->data=(char *)cc;
281  return cc==NULL;
282 }
284 {
285  return jjOP_BIM_I(res, v, u);
286 }
288 {
289  bigintmat* aa= (bigintmat *)u->Data();
290  number bb = (number)(v->Data());
291  if (errorreported) return TRUE;
292  bigintmat *cc=NULL;
293  switch (iiOp)
294  {
295  case '*': cc=bimMult(aa,bb,coeffs_BIGINT); break;
296  }
297  res->data=(char *)cc;
298  return cc==NULL;
299 }
301 {
302  return jjOP_BIM_BI(res, v, u);
303 }
305 {
306  intvec* aa= (intvec *)u->CopyD(INTVEC_CMD);
307  int bb = (int)(long)(v->Data());
308  if (errorreported) return TRUE;
309  switch (iiOp)
310  {
311  case '+': (*aa) += bb; break;
312  case '-': (*aa) -= bb; break;
313  case '*': (*aa) *= bb; break;
314  case '/':
315  case INTDIV_CMD: (*aa) /= bb; break;
316  case '%': (*aa) %= bb; break;
317  }
318  res->data=(char *)aa;
319  return FALSE;
320 }
322 {
323  return jjOP_IV_I(res,v,u);
324 }
326 {
327  intvec* aa= (intvec *)u->CopyD(INTVEC_CMD);
328  int bb = (int)(long)(v->Data());
329  int i=si_min(aa->rows(),aa->cols());
330  switch (iiOp)
331  {
332  case '+': for (;i>0;i--) IMATELEM(*aa,i,i) += bb;
333  break;
334  case '-': for (;i>0;i--) IMATELEM(*aa,i,i) -= bb;
335  break;
336  }
337  res->data=(char *)aa;
338  return FALSE;
339 }
341 {
342  return jjOP_IM_I(res,v,u);
343 }
345 {
346  int l=(int)(long)v->Data();
347  if (l>=0)
348  {
349  int d=(int)(long)u->Data();
350  intvec *vv=new intvec(l);
351  int i;
352  for(i=l-1;i>=0;i--) { (*vv)[i]=d; }
353  res->data=(char *)vv;
354  }
355  return (l<0);
356 }
358 {
359  res->data=(char *)new intvec((int)(long)u->Data(),(int)(long)v->Data());
360  return FALSE;
361 }
362 static void jjEQUAL_REST(leftv res,leftv u,leftv v);
364 {
365  intvec* a = (intvec * )(u->Data());
366  intvec* b = (intvec * )(v->Data());
367  int r=a->compare(b);
368  switch (iiOp)
369  {
370  case '<':
371  res->data = (char *) (r<0);
372  break;
373  case '>':
374  res->data = (char *) (r>0);
375  break;
376  case LE:
377  res->data = (char *) (r<=0);
378  break;
379  case GE:
380  res->data = (char *) (r>=0);
381  break;
382  case EQUAL_EQUAL:
383  case NOTEQUAL: /* negation handled by jjEQUAL_REST */
384  res->data = (char *) (r==0);
385  break;
386  }
387  jjEQUAL_REST(res,u,v);
388  if(r==-2) { WerrorS("size incompatible"); return TRUE; }
389  return FALSE;
390 }
392 {
393  bigintmat* a = (bigintmat * )(u->Data());
394  bigintmat* b = (bigintmat * )(v->Data());
395  int r=a->compare(b);
396  switch (iiOp)
397  {
398  case '<':
399  res->data = (char *) (r<0);
400  break;
401  case '>':
402  res->data = (char *) (r>0);
403  break;
404  case LE:
405  res->data = (char *) (r<=0);
406  break;
407  case GE:
408  res->data = (char *) (r>=0);
409  break;
410  case EQUAL_EQUAL:
411  case NOTEQUAL: /* negation handled by jjEQUAL_REST */
412  res->data = (char *) (r==0);
413  break;
414  }
415  jjEQUAL_REST(res,u,v);
416  if(r==-2) { WerrorS("size incompatible"); return TRUE; }
417  return FALSE;
418 }
420 {
421  intvec* a = (intvec * )(u->Data());
422  int b = (int)(long)(v->Data());
423  int r=a->compare(b);
424  switch (iiOp)
425  {
426  case '<':
427  res->data = (char *) (r<0);
428  break;
429  case '>':
430  res->data = (char *) (r>0);
431  break;
432  case LE:
433  res->data = (char *) (r<=0);
434  break;
435  case GE:
436  res->data = (char *) (r>=0);
437  break;
438  case EQUAL_EQUAL:
439  case NOTEQUAL: /* negation handled by jjEQUAL_REST */
440  res->data = (char *) (r==0);
441  break;
442  }
443  jjEQUAL_REST(res,u,v);
444  return FALSE;
445 }
447 {
448  poly p=(poly)u->Data();
449  poly q=(poly)v->Data();
450  int r=pCmp(p,q);
451  if (r==0)
452  {
453  number h=nSub(pGetCoeff(p),pGetCoeff(q));
454  /* compare lead coeffs */
455  r = -1+nIsZero(h)+2*nGreaterZero(h); /* -1: <, 0:==, 1: > */
456  nDelete(&h);
457  }
458  else if (p==NULL)
459  {
460  if (q==NULL)
461  {
462  /* compare 0, 0 */
463  r=0;
464  }
465  else if(pIsConstant(q))
466  {
467  /* compare 0, const */
468  r = 1-2*nGreaterZero(pGetCoeff(q)); /* -1: <, 1: > */
469  }
470  }
471  else if (q==NULL)
472  {
473  if (pIsConstant(p))
474  {
475  /* compare const, 0 */
476  r = -1+2*nGreaterZero(pGetCoeff(p)); /* -1: <, 1: > */
477  }
478  }
479  switch (iiOp)
480  {
481  case '<':
482  res->data = (char *) (r < 0);
483  break;
484  case '>':
485  res->data = (char *) (r > 0);
486  break;
487  case LE:
488  res->data = (char *) (r <= 0);
489  break;
490  case GE:
491  res->data = (char *) (r >= 0);
492  break;
493  //case EQUAL_EQUAL:
494  //case NOTEQUAL: /* negation handled by jjEQUAL_REST */
495  // res->data = (char *) (r == 0);
496  // break;
497  }
498  jjEQUAL_REST(res,u,v);
499  return FALSE;
500 }
502 {
503  char* a = (char * )(u->Data());
504  char* b = (char * )(v->Data());
505  int result = strcmp(a,b);
506  switch (iiOp)
507  {
508  case '<':
509  res->data = (char *) (result < 0);
510  break;
511  case '>':
512  res->data = (char *) (result > 0);
513  break;
514  case LE:
515  res->data = (char *) (result <= 0);
516  break;
517  case GE:
518  res->data = (char *) (result >= 0);
519  break;
520  case EQUAL_EQUAL:
521  case NOTEQUAL: /* negation handled by jjEQUAL_REST */
522  res->data = (char *) (result == 0);
523  break;
524  }
525  jjEQUAL_REST(res,u,v);
526  return FALSE;
527 }
529 {
530  if (u->Next()!=NULL)
531  {
532  u=u->next;
533  res->next = (leftv)omAllocBin(sleftv_bin);
534  return iiExprArith2(res->next,u,iiOp,v);
535  }
536  else if (v->Next()!=NULL)
537  {
538  v=v->next;
539  res->next = (leftv)omAllocBin(sleftv_bin);
540  return iiExprArith2(res->next,u,iiOp,v);
541  }
542  return FALSE;
543 }
545 {
546  int b=(int)(long)u->Data();
547  int e=(int)(long)v->Data();
548  int rc = 1;
549  BOOLEAN overflow=FALSE;
550  if (e >= 0)
551  {
552  if (b==0)
553  {
554  rc=(e==0);
555  }
556  else if ((e==0)||(b==1))
557  {
558  rc= 1;
559  }
560  else if (b== -1)
561  {
562  if (e&1) rc= -1;
563  else rc= 1;
564  }
565  else
566  {
567  int oldrc;
568  while ((e--)!=0)
569  {
570  oldrc=rc;
571  rc *= b;
572  if (!overflow)
573  {
574  if(rc/b!=oldrc) overflow=TRUE;
575  }
576  }
577  if (overflow)
578  WarnS("int overflow(^), result may be wrong");
579  }
580  res->data = (char *)((long)rc);
581  if (u!=NULL) return jjOP_REST(res,u,v);
582  return FALSE;
583  }
584  else
585  {
586  WerrorS("exponent must be non-negative");
587  return TRUE;
588  }
589 }
591 {
592  int e=(int)(long)v->Data();
593  number n=(number)u->Data();
594  if (e>=0)
595  {
596  n_Power(n,e,(number*)&res->data,coeffs_BIGINT);
597  }
598  else
599  {
600  WerrorS("exponent must be non-negative");
601  return TRUE;
602  }
603  if (u!=NULL) return jjOP_REST(res,u,v);
604  return FALSE;
605 }
607 {
608  int e=(int)(long)v->Data();
609  number n=(number)u->Data();
610  int d=0;
611  if (e<0)
612  {
613  n=nInvers(n);
614  e=-e;
615  d=1;
616  }
617  number r;
618  nPower(n,e,(number*)&r);
619  res->data=(char*)r;
620  if (d) nDelete(&n);
621  if (u!=NULL) return jjOP_REST(res,u,v);
622  return FALSE;
623 }
625 {
626  int v_i=(int)(long)v->Data();
627  if (v_i<0)
628  {
629  WerrorS("exponent must be non-negative");
630  return TRUE;
631  }
632  poly u_p=(poly)u->CopyD(POLY_CMD);
633  if ((u_p!=NULL)
634  && ((v_i!=0) &&
635  ((long)pTotaldegree(u_p) > (signed long)currRing->bitmask / (signed long)v_i/2)))
636  {
637  Werror("OVERFLOW in power(d=%ld, e=%d, max=%ld)",
638  pTotaldegree(u_p),v_i,currRing->bitmask/2);
639  pDelete(&u_p);
640  return TRUE;
641  }
642  res->data = (char *)pPower(u_p,v_i);
643  if (u!=NULL) return jjOP_REST(res,u,v);
644  return errorreported; /* pPower may set errorreported via Werror */
645 }
647 {
648  res->data = (char *)id_Power((ideal)(u->Data()),(int)(long)(v->Data()), currRing);
649  if (u!=NULL) return jjOP_REST(res,u,v);
650  return FALSE;
651 }
653 {
654  u=u->next;
655  v=v->next;
656  if (u==NULL)
657  {
658  if (v==NULL) return FALSE; /* u==NULL, v==NULL */
659  if (iiOp=='-') /* u==NULL, v<>NULL, iiOp=='-'*/
660  {
661  do
662  {
663  if (res->next==NULL)
664  res->next = (leftv)omAlloc0Bin(sleftv_bin);
665  leftv tmp_v=v->next;
666  v->next=NULL;
667  BOOLEAN b=iiExprArith1(res->next,v,'-');
668  v->next=tmp_v;
669  if (b)
670  return TRUE;
671  v=tmp_v;
672  res=res->next;
673  } while (v!=NULL);
674  return FALSE;
675  }
676  loop /* u==NULL, v<>NULL, iiOp=='+' */
677  {
678  res->next = (leftv)omAlloc0Bin(sleftv_bin);
679  res=res->next;
680  res->data = v->CopyD();
681  res->rtyp = v->Typ();
682  v=v->next;
683  if (v==NULL) return FALSE;
684  }
685  }
686  if (v!=NULL) /* u<>NULL, v<>NULL */
687  {
688  do
689  {
690  res->next = (leftv)omAlloc0Bin(sleftv_bin);
691  leftv tmp_u=u->next; u->next=NULL;
692  leftv tmp_v=v->next; v->next=NULL;
693  BOOLEAN b=iiExprArith2(res->next,u,iiOp,v);
694  u->next=tmp_u;
695  v->next=tmp_v;
696  if (b)
697  return TRUE;
698  u=tmp_u;
699  v=tmp_v;
700  res=res->next;
701  } while ((u!=NULL) && (v!=NULL));
702  return FALSE;
703  }
704  loop /* u<>NULL, v==NULL */
705  {
706  res->next = (leftv)omAlloc0Bin(sleftv_bin);
707  res=res->next;
708  res->data = u->CopyD();
709  res->rtyp = u->Typ();
710  u=u->next;
711  if (u==NULL) return FALSE;
712  }
713 }
715 {
716  idhdl packhdl;
717  switch(u->Typ())
718  {
719  case 0:
720  {
721  int name_err=0;
722  if(isupper(u->name[0]))
723  {
724  const char *c=u->name+1;
725  while((*c!='\0')&&(islower(*c)||(isdigit(*c)))) c++;
726  if (*c!='\0')
727  name_err=1;
728  else
729  {
730  Print("%s of type 'ANY'. Trying load.\n", u->name);
731  if(iiTryLoadLib(u, u->name))
732  {
733  Werror("'%s' no such package", u->name);
734  return TRUE;
735  }
736  syMake(u,u->name,NULL);
737  }
738  }
739  else name_err=1;
740  if(name_err)
741  { Werror("'%s' is an invalid package name",u->name);return TRUE;}
742  // and now, after the loading: use next case !!! no break !!!
743  }
744  case PACKAGE_CMD:
745  packhdl = (idhdl)u->data;
746  if((!IDPACKAGE(packhdl)->loaded)
747  && (IDPACKAGE(packhdl)->language > LANG_TOP))
748  {
749  Werror("'%s' not loaded", u->name);
750  return TRUE;
751  }
752  if(v->rtyp == IDHDL)
753  {
754  v->name = omStrDup(v->name);
755  }
756  else if (v->rtyp!=0)
757  {
758  WerrorS("reserved name with ::");
759  return TRUE;
760  }
761  v->req_packhdl=IDPACKAGE(packhdl);
762  syMake(v, v->name, packhdl);
763  memcpy(res, v, sizeof(sleftv));
764  memset(v, 0, sizeof(sleftv));
765  break;
766  case DEF_CMD:
767  break;
768  default:
769  WerrorS("<package>::<id> expected");
770  return TRUE;
771  }
772  return FALSE;
773 }
775 {
776  unsigned int a=(unsigned int)(unsigned long)u->Data();
777  unsigned int b=(unsigned int)(unsigned long)v->Data();
778  unsigned int c=a+b;
779  res->data = (char *)((long)c);
780  if (((Sy_bit(31)&a)==(Sy_bit(31)&b))&&((Sy_bit(31)&a)!=(Sy_bit(31)&c)))
781  {
782  WarnS("int overflow(+), result may be wrong");
783  }
784  return jjPLUSMINUS_Gen(res,u,v);
785 }
787 {
788  res->data = (char *)(n_Add((number)u->Data(), (number)v->Data(),coeffs_BIGINT));
789  return jjPLUSMINUS_Gen(res,u,v);
790 }
792 {
793  res->data = (char *)(nAdd((number)u->Data(), (number)v->Data()));
794  return jjPLUSMINUS_Gen(res,u,v);
795 }
797 {
798  res->data = (char *)(pAdd((poly)u->CopyD(POLY_CMD) , (poly)v->CopyD(POLY_CMD)));
799  return jjPLUSMINUS_Gen(res,u,v);
800 }
802 {
803  res->data = (char *)ivAdd((intvec*)(u->Data()), (intvec*)(v->Data()));
804  if (res->data==NULL)
805  {
806  WerrorS("intmat size not compatible");
807  return TRUE;
808  }
809  return jjPLUSMINUS_Gen(res,u,v);
810 }
812 {
813  res->data = (char *)bimAdd((bigintmat*)(u->Data()), (bigintmat*)(v->Data()));
814  if (res->data==NULL)
815  {
816  WerrorS("bigintmat/cmatrix not compatible");
817  return TRUE;
818  }
819  return jjPLUSMINUS_Gen(res,u,v);
820 }
822 {
823  matrix A=(matrix)u->Data(); matrix B=(matrix)v->Data();
824  res->data = (char *)(mp_Add(A , B, currRing));
825  if (res->data==NULL)
826  {
827  Werror("matrix size not compatible(%dx%d, %dx%d)",
828  MATROWS(A),MATCOLS(A),MATROWS(B),MATCOLS(B));
829  return TRUE;
830  }
831  return jjPLUSMINUS_Gen(res,u,v);
832 }
834 {
835  matrix m=(matrix)u->Data();
837  if (iiOp=='+')
838  res->data = (char *)mp_Add(m , p,currRing);
839  else
840  res->data = (char *)mp_Sub(m , p,currRing);
841  idDelete((ideal *)&p);
842  return jjPLUSMINUS_Gen(res,u,v);
843 }
845 {
846  return jjPLUS_MA_P(res,v,u);
847 }
849 {
850  char* a = (char * )(u->Data());
851  char* b = (char * )(v->Data());
852  char* r = (char * )omAlloc(strlen(a) + strlen(b) + 1);
853  strcpy(r,a);
854  strcat(r,b);
855  res->data=r;
856  return jjPLUSMINUS_Gen(res,u,v);
857 }
859 {
860  res->data = (char *)idAdd((ideal)u->Data(),(ideal)v->Data());
861  return jjPLUSMINUS_Gen(res,u,v);
862 }
864 {
865  void *ap=u->Data(); void *bp=v->Data();
866  int aa=(int)(long)ap;
867  int bb=(int)(long)bp;
868  int cc=aa-bb;
869  unsigned int a=(unsigned int)(unsigned long)ap;
870  unsigned int b=(unsigned int)(unsigned long)bp;
871  unsigned int c=a-b;
872  if (((Sy_bit(31)&a)!=(Sy_bit(31)&b))&&((Sy_bit(31)&a)!=(Sy_bit(31)&c)))
873  {
874  WarnS("int overflow(-), result may be wrong");
875  }
876  res->data = (char *)((long)cc);
877  return jjPLUSMINUS_Gen(res,u,v);
878 }
880 {
881  res->data = (char *)(n_Sub((number)u->Data(), (number)v->Data(),coeffs_BIGINT));
882  return jjPLUSMINUS_Gen(res,u,v);
883 }
885 {
886  res->data = (char *)(nSub((number)u->Data(), (number)v->Data()));
887  return jjPLUSMINUS_Gen(res,u,v);
888 }
890 {
891  res->data = (char *)(pSub((poly)u->CopyD(POLY_CMD) , (poly)v->CopyD(POLY_CMD)));
892  return jjPLUSMINUS_Gen(res,u,v);
893 }
895 {
896  res->data = (char *)ivSub((intvec*)(u->Data()), (intvec*)(v->Data()));
897  if (res->data==NULL)
898  {
899  WerrorS("intmat size not compatible");
900  return TRUE;
901  }
902  return jjPLUSMINUS_Gen(res,u,v);
903 }
905 {
906  res->data = (char *)bimSub((bigintmat*)(u->Data()), (bigintmat*)(v->Data()));
907  if (res->data==NULL)
908  {
909  WerrorS("bigintmat/cmatrix not compatible");
910  return TRUE;
911  }
912  return jjPLUSMINUS_Gen(res,u,v);
913 }
915 {
916  matrix A=(matrix)u->Data(); matrix B=(matrix)v->Data();
917  res->data = (char *)(mp_Sub(A , B, currRing));
918  if (res->data==NULL)
919  {
920  Werror("matrix size not compatible(%dx%d, %dx%d)",
921  MATROWS(A),MATCOLS(A),MATROWS(B),MATCOLS(B));
922  return TRUE;
923  }
924  return jjPLUSMINUS_Gen(res,u,v);
925  return FALSE;
926 }
928 {
929  int a=(int)(long)u->Data();
930  int b=(int)(long)v->Data();
931  int64 c=(int64)a * (int64)b;
932  if ((c>INT_MAX)||(c<INT_MIN))
933  WarnS("int overflow(*), result may be wrong");
934  res->data = (char *)((long)((int)c));
935  if ((u->Next()!=NULL) || (v->Next()!=NULL))
936  return jjOP_REST(res,u,v);
937  return FALSE;
938 }
940 {
941  res->data = (char *)(n_Mult( (number)u->Data(), (number)v->Data(),coeffs_BIGINT));
942  if ((v->next!=NULL) || (u->next!=NULL))
943  return jjOP_REST(res,u,v);
944  return FALSE;
945 }
947 {
948  res->data = (char *)(nMult( (number)u->Data(), (number)v->Data()));
949  number n=(number)res->data;
950  nNormalize(n);
951  res->data=(char *)n;
952  if ((v->next!=NULL) || (u->next!=NULL))
953  return jjOP_REST(res,u,v);
954  return FALSE;
955 }
957 {
958  poly a;
959  poly b;
960  if (v->next==NULL)
961  {
962  a=(poly)u->CopyD(POLY_CMD); // works also for VECTOR_CMD
963  if (u->next==NULL)
964  {
965  b=(poly)v->CopyD(POLY_CMD); // works also for VECTOR_CMD
966  if ((a!=NULL) && (b!=NULL)
967  && ((long)pTotaldegree(a)>si_max((long)rVar(currRing),(long)currRing->bitmask/2)-(long)pTotaldegree(b)))
968  {
969  Warn("possible OVERFLOW in mult(d=%ld, d=%ld, max=%ld)",
970  pTotaldegree(a),pTotaldegree(b),currRing->bitmask/2);
971  }
972  res->data = (char *)(pMult( a, b));
973  pNormalize((poly)res->data);
974  return FALSE;
975  }
976  // u->next exists: copy v
977  b=pCopy((poly)v->Data());
978  if ((a!=NULL) && (b!=NULL)
979  && (pTotaldegree(a)+pTotaldegree(b)>si_max((long)rVar(currRing),(long)currRing->bitmask/2)))
980  {
981  Warn("possible OVERFLOW in mult(d=%ld, d=%ld, max=%ld)",
982  pTotaldegree(a),pTotaldegree(b),currRing->bitmask/2);
983  }
984  res->data = (char *)(pMult( a, b));
985  pNormalize((poly)res->data);
986  return jjOP_REST(res,u,v);
987  }
988  // v->next exists: copy u
989  a=pCopy((poly)u->Data());
990  b=(poly)v->CopyD(POLY_CMD); // works also for VECTOR_CMD
991  if ((a!=NULL) && (b!=NULL)
992  && ((unsigned long)(pTotaldegree(a)+pTotaldegree(b))>=currRing->bitmask/2))
993  {
994  pDelete(&a);
995  pDelete(&b);
996  WerrorS("OVERFLOW");
997  return TRUE;
998  }
999  res->data = (char *)(pMult( a, b));
1000  pNormalize((poly)res->data);
1001  return jjOP_REST(res,u,v);
1002 }
1004 {
1005  res->data = (char *)idMult((ideal)u->Data(),(ideal)v->Data());
1006  id_Normalize((ideal)res->data,currRing);
1007  if ((v->next!=NULL) || (u->next!=NULL))
1008  return jjOP_REST(res,u,v);
1009  return FALSE;
1010 }
1012 {
1013  res->data = (char *)ivMult((intvec*)(u->Data()), (intvec*)(v->Data()));
1014  if (res->data==NULL)
1015  {
1016  WerrorS("intmat size not compatible");
1017  return TRUE;
1018  }
1019  if ((v->next!=NULL) || (u->next!=NULL))
1020  return jjOP_REST(res,u,v);
1021  return FALSE;
1022 }
1024 {
1025  res->data = (char *)bimMult((bigintmat*)(u->Data()), (bigintmat*)(v->Data()));
1026  if (res->data==NULL)
1027  {
1028  WerrorS("bigintmat/cmatrix not compatible");
1029  return TRUE;
1030  }
1031  if ((v->next!=NULL) || (u->next!=NULL))
1032  return jjOP_REST(res,u,v);
1033  return FALSE;
1034 }
1036 {
1038  if (nMap==NULL) return TRUE;
1039  number n=nMap((number)v->Data(),coeffs_BIGINT,currRing->cf);
1040  poly p=pNSet(n);
1041  ideal I= (ideal)mp_MultP((matrix)u->CopyD(MATRIX_CMD),p,currRing);
1042  res->data = (char *)I;
1043  return FALSE;
1044 }
1046 {
1047  return jjTIMES_MA_BI1(res,v,u);
1048 }
1050 {
1051  poly p=(poly)v->CopyD(POLY_CMD);
1052  int r=pMaxComp(p);/* recompute the rank for the case ideal*vector*/
1053  ideal I= (ideal)mp_MultP((matrix)u->CopyD(MATRIX_CMD),p,currRing);
1054  if (r>0) I->rank=r;
1056  res->data = (char *)I;
1057  return FALSE;
1058 }
1060 {
1061  poly p=(poly)u->CopyD(POLY_CMD);
1062  int r=pMaxComp(p);/* recompute the rank for the case ideal*vector*/
1063  ideal I= (ideal)pMultMp(p,(matrix)v->CopyD(MATRIX_CMD),currRing);
1064  if (r>0) I->rank=r;
1066  res->data = (char *)I;
1067  return FALSE;
1068 }
1070 {
1071  number n=(number)v->CopyD(NUMBER_CMD);
1072  poly p=pNSet(n);
1073  res->data = (char *)mp_MultP((matrix)u->CopyD(MATRIX_CMD),p,currRing);
1074  id_Normalize((ideal)res->data,currRing);
1075  return FALSE;
1076 }
1078 {
1079  return jjTIMES_MA_N1(res,v,u);
1080 }
1082 {
1083  res->data = (char *)mp_MultI((matrix)u->CopyD(MATRIX_CMD),(int)(long)v->Data(),currRing);
1084  id_Normalize((ideal)res->data,currRing);
1085  return FALSE;
1086 }
1088 {
1089  return jjTIMES_MA_I1(res,v,u);
1090 }
1092 {
1093  matrix A=(matrix)u->Data(); matrix B=(matrix)v->Data();
1094  res->data = (char *)mp_Mult(A,B,currRing);
1095  if (res->data==NULL)
1096  {
1097  Werror("matrix size not compatible(%dx%d, %dx%d) in *",
1098  MATROWS(A),MATCOLS(A),MATROWS(B),MATCOLS(B));
1099  return TRUE;
1100  }
1101  id_Normalize((ideal)res->data,currRing);
1102  if ((v->next!=NULL) || (u->next!=NULL))
1103  return jjOP_REST(res,u,v);
1104  return FALSE;
1105 }
1107 {
1108  number h=n_Sub((number)u->Data(),(number)v->Data(),coeffs_BIGINT);
1109  res->data = (char *) (n_GreaterZero(h,coeffs_BIGINT)||(n_IsZero(h,coeffs_BIGINT)));
1110  n_Delete(&h,coeffs_BIGINT);
1111  return FALSE;
1112 }
1114 {
1115  res->data = (char *)(long)((int)((long)u->Data()) >= (int)((long)v->Data()));
1116  return FALSE;
1117 }
1119 {
1120  res->data = (char *)(long) (nGreater((number)u->Data(),(number)v->Data())
1121  || nEqual((number)u->Data(),(number)v->Data()));
1122  return FALSE;
1123 }
1125 {
1126  number h=n_Sub((number)u->Data(),(number)v->Data(),coeffs_BIGINT);
1127  res->data = (char *)(long) (n_GreaterZero(h,coeffs_BIGINT)&&(!n_IsZero(h,coeffs_BIGINT)));
1128  n_Delete(&h,coeffs_BIGINT);
1129  return FALSE;
1130 }
1132 {
1133  res->data = (char *)(long)((int)((long)u->Data()) > (int)((long)v->Data()));
1134  return FALSE;
1135 }
1137 {
1138  res->data = (char *)(long)(nGreater((number)u->Data(),(number)v->Data()));
1139  return FALSE;
1140 }
1142 {
1143  return jjGE_BI(res,v,u);
1144 }
1146 {
1147  res->data = (char *)(long)((int)((long)u->Data()) <= (int)((long)v->Data()));
1148  return FALSE;
1149 }
1151 {
1152  return jjGE_N(res,v,u);
1153 }
1155 {
1156  return jjGT_BI(res,v,u);
1157 }
1159 {
1160  res->data = (char *)(long)((int)((long)u->Data()) < (int)((long)v->Data()));
1161  return FALSE;
1162 }
1164 {
1165  return jjGT_N(res,v,u);
1166 }
1168 {
1169  if (iiOp=='/') Warn("int division with `/`: use `div` instead in line >>%s<<",my_yylinebuf);
1170  int a= (int)(long)u->Data();
1171  int b= (int)(long)v->Data();
1172  if (b==0)
1173  {
1175  return TRUE;
1176  }
1177  int c=a%b;
1178  int r=0;
1179  switch (iiOp)
1180  {
1181  case '%':
1182  r=c; break;
1183  case '/':
1184  case INTDIV_CMD:
1185  r=((a-c) /b); break;
1186  }
1187  res->data=(void *)((long)r);
1188  return FALSE;
1189 }
1191 {
1192  number q=(number)v->Data();
1193  if (n_IsZero(q,coeffs_BIGINT))
1194  {
1196  return TRUE;
1197  }
1198  q = n_Div((number)u->Data(),q,coeffs_BIGINT);
1200  res->data = (char *)q;
1201  return FALSE;
1202 }
1204 {
1205  number q=(number)v->Data();
1206  if (nIsZero(q))
1207  {
1209  return TRUE;
1210  }
1211  q = nDiv((number)u->Data(),q);
1212  nNormalize(q);
1213  res->data = (char *)q;
1214  return FALSE;
1215 }
1217 {
1218  poly q=(poly)v->Data();
1219  if (q==NULL)
1220  {
1222  return TRUE;
1223  }
1224  poly p=(poly)(u->Data());
1225  if (p==NULL)
1226  {
1227  res->data=NULL;
1228  return FALSE;
1229  }
1230  if ((pNext(q)!=NULL) && (!rField_is_Ring(currRing)))
1231  { /* This means that q != 0 consists of at least two terms.
1232  Moreover, currRing is over a field. */
1233  if(pGetComp(p)==0)
1234  {
1235  res->data=(void*)(singclap_pdivide(p /*(poly)(u->Data())*/ ,
1236  q /*(poly)(v->Data())*/ ,currRing));
1237  }
1238  else
1239  {
1240  int comps=pMaxComp(p);
1241  ideal I=idInit(comps,1);
1242  p=pCopy(p);
1243  poly h;
1244  int i;
1245  // conversion to a list of polys:
1246  while (p!=NULL)
1247  {
1248  i=pGetComp(p)-1;
1249  h=pNext(p);
1250  pNext(p)=NULL;
1251  pSetComp(p,0);
1252  I->m[i]=pAdd(I->m[i],p);
1253  p=h;
1254  }
1255  // division and conversion to vector:
1256  h=NULL;
1257  p=NULL;
1258  for(i=comps-1;i>=0;i--)
1259  {
1260  if (I->m[i]!=NULL)
1261  {
1262  h=singclap_pdivide(I->m[i],q,currRing);
1263  pSetCompP(h,i+1);
1264  p=pAdd(p,h);
1265  }
1266  }
1267  idDelete(&I);
1268  res->data=(void *)p;
1269  }
1270  }
1271  else
1272  { /* This means that q != 0 consists of just one term,
1273  or that currRing is over a coefficient ring. */
1274 #ifdef HAVE_RINGS
1275  if (!rField_is_Domain(currRing))
1276  {
1277  WerrorS("division only defined over coefficient domains");
1278  return TRUE;
1279  }
1280  if (pNext(q)!=NULL)
1281  {
1282  WerrorS("division over a coefficient domain only implemented for terms");
1283  return TRUE;
1284  }
1285 #endif
1286  res->data = (char *)pDivideM(pCopy(p),pHead(q));
1287  }
1288  pNormalize((poly)res->data);
1289  return FALSE;
1290 }
1292 {
1293  poly q=(poly)v->Data();
1294  if (q==NULL)
1295  {
1297  return TRUE;
1298  }
1299  matrix m=(matrix)(u->Data());
1300  int r=m->rows();
1301  int c=m->cols();
1302  matrix mm=mpNew(r,c);
1303  int i,j;
1304  for(i=r;i>0;i--)
1305  {
1306  for(j=c;j>0;j--)
1307  {
1308  if (pNext(q)!=NULL)
1309  {
1310  MATELEM(mm,i,j) = singclap_pdivide( MATELEM(m,i,j) ,
1311  q /*(poly)(v->Data())*/, currRing );
1312  }
1313  else
1314  MATELEM(mm,i,j) = pDivideM(pCopy(MATELEM(m,i,j)),pHead(q));
1315  }
1316  }
1317  id_Normalize((ideal)mm,currRing);
1318  res->data=(char *)mm;
1319  return FALSE;
1320 }
1322 {
1323  res->data = (char *)((long)n_Equal((number)u->Data(),(number)v->Data(),coeffs_BIGINT));
1324  jjEQUAL_REST(res,u,v);
1325  return FALSE;
1326 }
1328 {
1329  res->data = (char *)((int)((long)u->Data()) == (int)((long)v->Data()));
1330  jjEQUAL_REST(res,u,v);
1331  return FALSE;
1332 }
1334 {
1335  res->data = (char *)((long)mp_Equal((matrix)u->Data(),(matrix)v->Data(),currRing));
1336  jjEQUAL_REST(res,u,v);
1337  return FALSE;
1338 }
1340 {
1341  res->data = (char *)((long)nEqual((number)u->Data(),(number)v->Data()));
1342  jjEQUAL_REST(res,u,v);
1343  return FALSE;
1344 }
1346 {
1347  poly p=(poly)u->Data();
1348  poly q=(poly)v->Data();
1349  res->data = (char *) ((long)pEqualPolys(p,q));
1350  jjEQUAL_REST(res,u,v);
1351  return FALSE;
1352 }
1354 {
1355  if ((res->data) && (u->next!=NULL) && (v->next!=NULL))
1356  {
1357  int save_iiOp=iiOp;
1358  if (iiOp==NOTEQUAL)
1359  iiExprArith2(res,u->next,EQUAL_EQUAL,v->next);
1360  else
1361  iiExprArith2(res,u->next,iiOp,v->next);
1362  iiOp=save_iiOp;
1363  }
1364  if (iiOp==NOTEQUAL) res->data=(char *)(!(long)res->data);
1365 }
1367 {
1368  res->data = (char *)((long)u->Data() && (long)v->Data());
1369  return FALSE;
1370 }
1372 {
1373  res->data = (char *)((long)u->Data() || (long)v->Data());
1374  return FALSE;
1375 }
1377 {
1378  res->rtyp=u->rtyp; u->rtyp=0;
1379  res->data=u->data; u->data=NULL;
1380  res->name=u->name; u->name=NULL;
1381  res->e=u->e; u->e=NULL;
1382  if (res->e==NULL) res->e=jjMakeSub(v);
1383  else
1384  {
1385  Subexpr sh=res->e;
1386  while (sh->next != NULL) sh=sh->next;
1387  sh->next=jjMakeSub(v);
1388  }
1389  if (u->next!=NULL)
1390  {
1392  BOOLEAN bo=iiExprArith2(rn,u->next,iiOp,v);
1393  res->next=rn;
1394  return bo;
1395  }
1396  return FALSE;
1397 }
1399 {
1400  if ((u->rtyp!=IDHDL)||(u->e!=NULL))
1401  {
1402  WerrorS("indexed object must have a name");
1403  return TRUE;
1404  }
1405  intvec * iv=(intvec *)v->Data();
1406  leftv p=NULL;
1407  int i;
1408  sleftv t;
1409  memset(&t,0,sizeof(t));
1410  t.rtyp=INT_CMD;
1411  for (i=0;i<iv->length(); i++)
1412  {
1413  t.data=(char *)((long)(*iv)[i]);
1414  if (p==NULL)
1415  {
1416  p=res;
1417  }
1418  else
1419  {
1421  p=p->next;
1422  }
1423  p->rtyp=IDHDL;
1424  p->data=u->data;
1425  p->name=u->name;
1426  p->flag=u->flag;
1427  p->e=jjMakeSub(&t);
1428  }
1429  u->rtyp=0;
1430  u->data=NULL;
1431  u->name=NULL;
1432  return FALSE;
1433 }
1435 {
1436  poly p=(poly)u->Data();
1437  int i=(int)(long)v->Data();
1438  int j=0;
1439  while (p!=NULL)
1440  {
1441  j++;
1442  if (j==i)
1443  {
1444  res->data=(char *)pHead(p);
1445  return FALSE;
1446  }
1447  pIter(p);
1448  }
1449  return FALSE;
1450 }
1452 {
1453  poly p=(poly)u->Data();
1454  poly r=NULL;
1455  intvec *iv=(intvec *)v->CopyD(INTVEC_CMD);
1456  int i;
1457  int sum=0;
1458  for(i=iv->length()-1;i>=0;i--)
1459  sum+=(*iv)[i];
1460  int j=0;
1461  while ((p!=NULL) && (sum>0))
1462  {
1463  j++;
1464  for(i=iv->length()-1;i>=0;i--)
1465  {
1466  if (j==(*iv)[i])
1467  {
1468  r=pAdd(r,pHead(p));
1469  sum-=j;
1470  (*iv)[i]=0;
1471  break;
1472  }
1473  }
1474  pIter(p);
1475  }
1476  delete iv;
1477  res->data=(char *)r;
1478  return FALSE;
1479 }
1481 {
1482  poly p=(poly)u->CopyD(VECTOR_CMD);
1483  poly r=p; // pointer to the beginning of component i
1484  poly o=NULL;
1485  int i=(int)(long)v->Data();
1486  while (p!=NULL)
1487  {
1488  if (pGetComp(p)!=i)
1489  {
1490  if (r==p) r=pNext(p);
1491  if (o!=NULL)
1492  {
1493  if (pNext(o)!=NULL) pLmDelete(&pNext(o));
1494  p=pNext(o);
1495  }
1496  else
1497  pLmDelete(&p);
1498  }
1499  else
1500  {
1501  pSetComp(p, 0);
1502  p_SetmComp(p, currRing);
1503  o=p;
1504  p=pNext(o);
1505  }
1506  }
1507  res->data=(char *)r;
1508  return FALSE;
1509 }
1511 {
1512  poly p=(poly)u->CopyD(VECTOR_CMD);
1513  if (p!=NULL)
1514  {
1515  poly r=pOne();
1516  poly hp=r;
1517  intvec *iv=(intvec *)v->Data();
1518  int i;
1519  loop
1520  {
1521  for(i=0;i<iv->length();i++)
1522  {
1523  if (((int)pGetComp(p))==(*iv)[i])
1524  {
1525  poly h;
1526  pSplit(p,&h);
1527  pNext(hp)=p;
1528  p=h;
1529  pIter(hp);
1530  break;
1531  }
1532  }
1533  if (p==NULL) break;
1534  if (i==iv->length())
1535  {
1536  pLmDelete(&p);
1537  if (p==NULL) break;
1538  }
1539  }
1540  pLmDelete(&r);
1541  res->data=(char *)r;
1542  }
1543  return FALSE;
1544 }
1547 {
1548  if(u->name==NULL) return TRUE;
1549  char * nn = (char *)omAlloc(strlen(u->name) + 14);
1550  sprintf(nn,"%s(%d)",u->name,(int)(long)v->Data());
1551  omFree((ADDRESS)u->name);
1552  u->name=NULL;
1553  char *n=omStrDup(nn);
1554  omFree((ADDRESS)nn);
1555  syMake(res,n);
1556  if (u->next!=NULL) return jjKLAMMER_rest(res,u->next,v);
1557  return FALSE;
1558 }
1560 {
1561  intvec * iv=(intvec *)v->Data();
1562  leftv p=NULL;
1563  int i;
1564  long slen = strlen(u->name) + 14;
1565  char *n = (char*) omAlloc(slen);
1566 
1567  for (i=0;i<iv->length(); i++)
1568  {
1569  if (p==NULL)
1570  {
1571  p=res;
1572  }
1573  else
1574  {
1576  p=p->next;
1577  }
1578  sprintf(n,"%s(%d)",u->name,(*iv)[i]);
1579  syMake(p,omStrDup(n));
1580  }
1581  omFree((ADDRESS)u->name);
1582  u->name = NULL;
1583  omFreeSize(n, slen);
1584  if (u->next!=NULL) return jjKLAMMER_rest(res,u->next,v);
1585  return FALSE;
1586 }
1588 {
1590  memset(tmp,0,sizeof(sleftv));
1591  BOOLEAN b;
1592  if (v->Typ()==INTVEC_CMD)
1593  b=jjKLAMMER_IV(tmp,u,v);
1594  else
1595  b=jjKLAMMER(tmp,u,v);
1596  if (b)
1597  {
1598  omFreeBin(tmp,sleftv_bin);
1599  return TRUE;
1600  }
1601  leftv h=res;
1602  while (h->next!=NULL) h=h->next;
1603  h->next=tmp;
1604  return FALSE;
1605 }
1607 {
1608  void *d;
1609  Subexpr e;
1610  int typ;
1611  BOOLEAN t=FALSE;
1612  idhdl tmp_proc=NULL;
1613  if ((u->rtyp!=IDHDL)||(u->e!=NULL))
1614  {
1615  tmp_proc=(idhdl)omAlloc0(sizeof(idrec));
1616  tmp_proc->id="_auto";
1617  tmp_proc->typ=PROC_CMD;
1618  tmp_proc->data.pinf=(procinfo *)u->Data();
1619  tmp_proc->ref=1;
1620  d=u->data; u->data=(void *)tmp_proc;
1621  e=u->e; u->e=NULL;
1622  t=TRUE;
1623  typ=u->rtyp; u->rtyp=IDHDL;
1624  }
1625  BOOLEAN sl;
1626  if (u->req_packhdl==currPack)
1627  sl = iiMake_proc((idhdl)u->data,NULL,v);
1628  else
1629  sl = iiMake_proc((idhdl)u->data,u->req_packhdl,v);
1630  if (t)
1631  {
1632  u->rtyp=typ;
1633  u->data=d;
1634  u->e=e;
1635  omFreeSize(tmp_proc,sizeof(idrec));
1636  }
1637  if (sl) return TRUE;
1638  memcpy(res,&iiRETURNEXPR,sizeof(sleftv));
1639  iiRETURNEXPR.Init();
1640  return FALSE;
1641 }
1643 {
1644  //Print("try to map %s with %s\n",$3.Name(),$1.Name());
1645  leftv sl=NULL;
1646  if ((v->e==NULL)&&(v->name!=NULL))
1647  {
1648  map m=(map)u->Data();
1649  sl=iiMap(m,v->name);
1650  }
1651  else
1652  {
1653  Werror("%s(<name>) expected",u->Name());
1654  }
1655  if (sl==NULL) return TRUE;
1656  memcpy(res,sl,sizeof(sleftv));
1658  return FALSE;
1659 }
1661 {
1662  intvec *c=(intvec*)u->Data();
1663  intvec* p=(intvec*)v->Data();
1664  int rl=p->length();
1665  number *x=(number *)omAlloc(rl*sizeof(number));
1666  number *q=(number *)omAlloc(rl*sizeof(number));
1667  int i;
1668  for(i=rl-1;i>=0;i--)
1669  {
1670  q[i]=n_Init((*p)[i], coeffs_BIGINT);
1671  x[i]=n_Init((*c)[i], coeffs_BIGINT);
1672  }
1673  CFArray iv(rl);
1674  number n=n_ChineseRemainderSym(x,q,rl,FALSE,iv,coeffs_BIGINT);
1675  for(i=rl-1;i>=0;i--)
1676  {
1677  n_Delete(&(q[i]),coeffs_BIGINT);
1678  n_Delete(&(x[i]),coeffs_BIGINT);
1679  }
1680  omFree(x); omFree(q);
1681  res->data=(char *)n;
1682  return FALSE;
1683 }
1684 #if 0
1685 static BOOLEAN jjCHINREM_P(leftv res, leftv u, leftv v)
1686 {
1687  lists c=(lists)u->CopyD(); // list of poly
1688  intvec* p=(intvec*)v->Data();
1689  int rl=p->length();
1690  poly r=NULL,h, result=NULL;
1691  number *x=(number *)omAlloc(rl*sizeof(number));
1692  number *q=(number *)omAlloc(rl*sizeof(number));
1693  int i;
1694  for(i=rl-1;i>=0;i--)
1695  {
1696  q[i]=nlInit((*p)[i]);
1697  }
1698  loop
1699  {
1700  for(i=rl-1;i>=0;i--)
1701  {
1702  if (c->m[i].Typ()!=POLY_CMD)
1703  {
1704  Werror("poly expected at pos %d",i+1);
1705  for(i=rl-1;i>=0;i--)
1706  {
1707  nlDelete(&(q[i]),currRing);
1708  }
1709  omFree(x); omFree(q); // delete c
1710  return TRUE;
1711  }
1712  h=((poly)c->m[i].Data());
1713  if (r==NULL) r=h;
1714  else if (pLmCmp(r,h)==-1) r=h;
1715  }
1716  if (r==NULL) break;
1717  for(i=rl-1;i>=0;i--)
1718  {
1719  h=((poly)c->m[i].Data());
1720  if (pLmCmp(r,h)==0)
1721  {
1722  x[i]=pGetCoeff(h);
1723  h=pLmFreeAndNext(h);
1724  c->m[i].data=(char*)h;
1725  }
1726  else
1727  x[i]=nlInit(0);
1728  }
1729  number n=n_ChineseRemainder(x,q,rl,currRing->cf);
1730  for(i=rl-1;i>=0;i--)
1731  {
1732  nlDelete(&(x[i]),currRing);
1733  }
1734  h=pHead(r);
1735  pSetCoeff(h,n);
1736  result=pAdd(result,h);
1737  }
1738  for(i=rl-1;i>=0;i--)
1739  {
1740  nlDelete(&(q[i]),currRing);
1741  }
1742  omFree(x); omFree(q);
1743  res->data=(char *)result;
1744  return FALSE;
1745 }
1746 #endif
1747 static BOOLEAN jjALIGN_V(leftv res, leftv u, leftv v)
1748 {
1749  poly p=(poly)u->CopyD();
1750  int s=(int)(long)v->Data();
1751  if (s+p_MinComp(p,currRing)<=0)
1752  { p_Delete(&p,currRing);return TRUE;}
1753  p_Shift(&p,s,currRing);
1754  res->data=p;
1755  return FALSE;
1756 }
1757 static BOOLEAN jjALIGN_M(leftv res, leftv u, leftv v)
1758 {
1759  ideal M=(ideal)u->CopyD();
1760  int s=(int)(long)v->Data();
1761  for(int i=IDELEMS(M)-1; i>=0;i--)
1762  {
1763  if (s+p_MinComp(M->m[i],currRing)<=0)
1764  { id_Delete(&M,currRing);return TRUE;}
1765  }
1766  id_Shift(M,s,currRing);
1767  res->data=M;
1768  return FALSE;
1769 }
1771 {
1772  coeffs cf;
1773  lists c=(lists)u->CopyD(); // list of ideal or bigint/int
1774  lists pl=NULL;
1775  intvec *p=NULL;
1776  if (v->Typ()==LIST_CMD) pl=(lists)v->Data();
1777  else p=(intvec*)v->Data();
1778  int rl=c->nr+1;
1779  ideal result;
1780  ideal *x=(ideal *)omAlloc(rl*sizeof(ideal));
1781  number *xx=NULL;
1782  int i;
1783  int return_type=c->m[0].Typ();
1784  if ((return_type!=IDEAL_CMD)
1785  && (return_type!=MODUL_CMD)
1786  && (return_type!=MATRIX_CMD)
1787  && (return_type!=POLY_CMD))
1788  {
1789  if((return_type!=BIGINT_CMD)&&(return_type!=INT_CMD))
1790  {
1791  WerrorS("poly/ideal/module/matrix expected");
1792  omFree(x); // delete c
1793  return TRUE;
1794  }
1795  else
1796  return_type=BIGINT_CMD;
1797  }
1798  if (return_type==BIGINT_CMD)
1799  cf=coeffs_BIGINT;
1800  else
1801  {
1802  cf=currRing->cf;
1803  if (nCoeff_is_Extension(cf) && (cf->extRing!=NULL))
1804  cf=cf->extRing->cf;
1805  }
1806  nMapFunc nMap=n_SetMap(coeffs_BIGINT,cf);
1807  if (return_type!=BIGINT_CMD)
1808  {
1809  for(i=rl-1;i>=0;i--)
1810  {
1811  if (c->m[i].Typ()!=return_type)
1812  {
1813  Werror("%s expected at pos %d",Tok2Cmdname(return_type),i+1);
1814  omFree(x); // delete c
1815  return TRUE;
1816  }
1817  if (return_type==POLY_CMD)
1818  {
1819  x[i]=idInit(1,1);
1820  x[i]->m[0]=(poly)c->m[i].CopyD();
1821  }
1822  else
1823  {
1824  x[i]=(ideal)c->m[i].CopyD();
1825  }
1826  //c->m[i].Init();
1827  }
1828  }
1829  else
1830  {
1831  if (nMap==NULL)
1832  {
1833  Werror("not implemented: map bigint -> %s", nCoeffString(cf));
1834  return TRUE;
1835  }
1836  xx=(number *)omAlloc(rl*sizeof(number));
1837  for(i=rl-1;i>=0;i--)
1838  {
1839  if (c->m[i].Typ()==INT_CMD)
1840  {
1841  xx[i]=n_Init(((int)(long)c->m[i].Data()),cf);
1842  }
1843  else if (c->m[i].Typ()==BIGINT_CMD)
1844  {
1845  xx[i]=nMap((number)c->m[i].Data(),coeffs_BIGINT,cf);
1846  }
1847  else
1848  {
1849  Werror("bigint expected at pos %d",i+1);
1850  omFree(x); // delete c
1851  omFree(xx); // delete c
1852  return TRUE;
1853  }
1854  }
1855  }
1856  number *q=(number *)omAlloc(rl*sizeof(number));
1857  if (p!=NULL)
1858  {
1859  for(i=rl-1;i>=0;i--)
1860  {
1861  q[i]=n_Init((*p)[i], cf);
1862  }
1863  }
1864  else
1865  {
1866  for(i=rl-1;i>=0;i--)
1867  {
1868  if (pl->m[i].Typ()==INT_CMD)
1869  {
1870  q[i]=n_Init((int)(long)pl->m[i].Data(),cf);
1871  }
1872  else if (pl->m[i].Typ()==BIGINT_CMD)
1873  {
1874  q[i]=nMap((number)(pl->m[i].Data()),coeffs_BIGINT,cf);
1875  }
1876  else
1877  {
1878  Werror("bigint expected at pos %d",i+1);
1879  for(i++;i<rl;i++)
1880  {
1881  n_Delete(&(q[i]),cf);
1882  }
1883  omFree(x); // delete c
1884  omFree(q); // delete pl
1885  if (xx!=NULL) omFree(xx); // delete c
1886  return TRUE;
1887  }
1888  }
1889  }
1890  if (return_type==BIGINT_CMD)
1891  {
1892  CFArray i_v(rl);
1893  number n=n_ChineseRemainderSym(xx,q,rl,TRUE,i_v,coeffs_BIGINT);
1894  res->data=(char *)n;
1895  }
1896  else
1897  {
1898  result=id_ChineseRemainder(x,q,rl,currRing);
1899  // deletes also x
1900  c->Clean();
1901  if ((return_type==POLY_CMD) &&(result!=NULL))
1902  {
1903  res->data=(char *)result->m[0];
1904  result->m[0]=NULL;
1905  idDelete(&result);
1906  }
1907  else
1908  res->data=(char *)result;
1909  }
1910  for(i=rl-1;i>=0;i--)
1911  {
1912  n_Delete(&(q[i]),cf);
1913  }
1914  omFree(q);
1915  res->rtyp=return_type;
1916  return result==NULL;
1917 }
1918 static BOOLEAN jjCOEF(leftv res, leftv u, leftv v)
1919 {
1920  poly p=(poly)v->Data();
1921  if ((p==NULL)||(pNext(p)!=NULL)) return TRUE;
1922  res->data=(char *)mp_CoeffProc((poly)u->Data(),p /*(poly)v->Data()*/,currRing);
1923  return FALSE;
1924 }
1926 {
1927  int i=pVar((poly)v->Data());
1928  if (i==0)
1929  {
1930  WerrorS("ringvar expected");
1931  return TRUE;
1932  }
1933  res->data=(char *)mp_Coeffs((ideal)u->CopyD(),i,currRing);
1934  return FALSE;
1935 }
1937 {
1938  poly p = pInit();
1939  int i;
1940  for (i=1; i<=currRing->N; i++)
1941  {
1942  pSetExp(p, i, 1);
1943  }
1944  pSetm(p);
1945  res->data = (void*)idCoeffOfKBase((ideal)(u->Data()),
1946  (ideal)(v->Data()), p);
1947  pDelete(&p);
1948  return FALSE;
1949 }
1951 {
1952  res->data=(char *)idDiffOp((ideal)u->Data(),(ideal)v->Data(),FALSE);
1953  return FALSE;
1954 }
1956 {
1957  short *iv=iv2array((intvec *)v->Data(),currRing);
1958  ideal I=(ideal)u->Data();
1959  int d=-1;
1960  int i;
1961  for(i=IDELEMS(I);i>=0;i--) d=si_max(d,(int)p_DegW(I->m[i],iv,currRing));
1962  omFreeSize( (ADDRESS)iv, (rVar(currRing)+1)*sizeof(short) );
1963  res->data = (char *)((long)d);
1964  return FALSE;
1965 }
1966 static BOOLEAN jjDEG_IV(leftv res, leftv u, leftv v)
1967 {
1968  poly p=(poly)u->Data();
1969  if (p!=NULL)
1970  {
1971  short *iv=iv2array((intvec *)v->Data(),currRing);
1972  const long d = p_DegW(p,iv,currRing);
1973  omFreeSize( (ADDRESS)iv, (rVar(currRing)+1)*sizeof(short) );
1974  res->data = (char *)(d);
1975  }
1976  else
1977  res->data=(char *)(long)(-1);
1978  return FALSE;
1979 }
1980 static BOOLEAN jjDIFF_P(leftv res, leftv u, leftv v)
1981 {
1982  int i=pVar((poly)v->Data());
1983  if (i==0)
1984  {
1985  WerrorS("ringvar expected");
1986  return TRUE;
1987  }
1988  res->data=(char *)pDiff((poly)(u->Data()),i);
1989  return FALSE;
1990 }
1991 static BOOLEAN jjDIFF_ID(leftv res, leftv u, leftv v)
1992 {
1993  int i=pVar((poly)v->Data());
1994  if (i==0)
1995  {
1996  WerrorS("ringvar expected");
1997  return TRUE;
1998  }
1999  res->data=(char *)idDiff((matrix)(u->Data()),i);
2000  return FALSE;
2001 }
2003 {
2004  res->data=(char *)idDiffOp((ideal)u->Data(),(ideal)v->Data());
2005  return FALSE;
2006 }
2007 static BOOLEAN jjDIM2(leftv res, leftv v, leftv w)
2008 {
2009  assumeStdFlag(v);
2010 #ifdef HAVE_RINGS
2011  if (rField_is_Ring(currRing))
2012  {
2013  //ring origR = currRing;
2014  //ring tempR = rCopy(origR);
2015  //coeffs new_cf=nInitChar(n_Q,NULL);
2016  //nKillChar(tempR->cf);
2017  //tempR->cf=new_cf;
2018  //rComplete(tempR);
2019  ideal vid = (ideal)v->Data();
2020  int i = idPosConstant(vid);
2021  if ((i != -1) && (n_IsUnit(pGetCoeff(vid->m[i]),currRing->cf)))
2022  { /* ideal v contains unit; dim = -1 */
2023  res->data = (char *)-1;
2024  return FALSE;
2025  }
2026  //rChangeCurrRing(tempR);
2027  //ideal vv = idrCopyR(vid, origR, currRing);
2028  ideal vv = id_Copy(vid, currRing);
2029  //ideal ww = idrCopyR((ideal)w->Data(), origR, currRing);
2030  ideal ww = id_Copy((ideal)w->Data(), currRing);
2031  /* drop degree zero generator from vv (if any) */
2032  if (i != -1) pDelete(&vv->m[i]);
2033  long d = (long)scDimInt(vv, ww);
2034  if (rField_is_Ring_Z(currRing) && (i == -1)) d++;
2035  res->data = (char *)d;
2036  idDelete(&vv); idDelete(&ww);
2037  //rChangeCurrRing(origR);
2038  //rDelete(tempR);
2039  return FALSE;
2040  }
2041 #endif
2042  if(currRing->qideal==NULL)
2043  res->data = (char *)((long)scDimInt((ideal)(v->Data()),(ideal)w->Data()));
2044  else
2045  {
2046  ideal q=idSimpleAdd(currRing->qideal,(ideal)w->Data());
2047  res->data = (char *)((long)scDimInt((ideal)(v->Data()),q));
2048  idDelete(&q);
2049  }
2050  return FALSE;
2051 }
2053 {
2054  ideal vi=(ideal)v->Data();
2055  int vl= IDELEMS(vi);
2056  ideal ui=(ideal)u->Data();
2057  int ul= IDELEMS(ui);
2058  ideal R; matrix U;
2059  ideal m = idLift(vi,ui,&R, FALSE,hasFlag(v,FLAG_STD),TRUE,&U);
2060  if (m==NULL) return TRUE;
2061  // now make sure that all matices have the corect size:
2063  int i;
2064  if (MATCOLS(U) != ul)
2065  {
2066  int mul=si_min(ul,MATCOLS(U));
2067  matrix UU=mpNew(ul,ul);
2068  int j;
2069  for(i=mul;i>0;i--)
2070  {
2071  for(j=mul;j>0;j--)
2072  {
2073  MATELEM(UU,i,j)=MATELEM(U,i,j);
2074  MATELEM(U,i,j)=NULL;
2075  }
2076  }
2077  idDelete((ideal *)&U);
2078  U=UU;
2079  }
2080  // make sure that U is a diagonal matrix of units
2081  for(i=ul;i>0;i--)
2082  {
2083  if(MATELEM(U,i,i)==NULL) MATELEM(U,i,i)=pOne();
2084  }
2086  L->Init(3);
2087  L->m[0].rtyp=MATRIX_CMD; L->m[0].data=(void *)T;
2088  L->m[1].rtyp=u->Typ(); L->m[1].data=(void *)R;
2089  L->m[2].rtyp=MATRIX_CMD; L->m[2].data=(void *)U;
2090  res->data=(char *)L;
2091  return FALSE;
2092 }
2093 static BOOLEAN jjELIMIN(leftv res, leftv u, leftv v)
2094 {
2095  res->data=(char *)idElimination((ideal)u->Data(),(poly)v->Data());
2096  //setFlag(res,FLAG_STD);
2097  return v->next!=NULL; //do not allow next like in eliminate(I,a(1..4))
2098 }
2100 {
2101  poly p=pOne();
2102  intvec *iv=(intvec*)v->Data();
2103  for(int i=iv->length()-1; i>=0; i--)
2104  {
2105  pSetExp(p,(*iv)[i],1);
2106  }
2107  pSetm(p);
2108  res->data=(char *)idElimination((ideal)u->Data(),p);
2109  pLmDelete(&p);
2110  //setFlag(res,FLAG_STD);
2111  return FALSE;
2112 }
2114 {
2115  //Print("exportto %s -> %s\n",v->Name(),u->Name() );
2116  return iiExport(v,0,IDPACKAGE((idhdl)u->data));
2117 }
2119 {
2120  WerrorS((char *)u->Data());
2121  extern int inerror;
2122  inerror=3;
2123  return TRUE;
2124 }
2126 {
2127  number uu=(number)u->Data();number vv=(number)v->Data();
2129  number a,b;
2130  number p0=n_ExtGcd(uu,vv,&a,&b,coeffs_BIGINT);
2131  L->Init(3);
2132  L->m[0].rtyp=BIGINT_CMD; L->m[0].data=(void *)p0;
2133  L->m[1].rtyp=BIGINT_CMD; L->m[1].data=(void *)a;
2134  L->m[2].rtyp=BIGINT_CMD; L->m[2].data=(void *)b;
2135  res->rtyp=LIST_CMD;
2136  res->data=(char *)L;
2137  return FALSE;
2138 }
2140 {
2141  int uu=(int)(long)u->Data();int vv=(int)(long)v->Data();
2142  int p0=ABS(uu),p1=ABS(vv);
2143  int f0 = 1, f1 = 0, g0 = 0, g1 = 1, q, r;
2144 
2145  while ( p1!=0 )
2146  {
2147  q=p0 / p1;
2148  r=p0 % p1;
2149  p0 = p1; p1 = r;
2150  r = g0 - g1 * q;
2151  g0 = g1; g1 = r;
2152  r = f0 - f1 * q;
2153  f0 = f1; f1 = r;
2154  }
2155  int a = f0;
2156  int b = g0;
2157  if ( uu /*(int)(long)u->Data()*/ < 0 ) a=-a;
2158  if ( vv /*(int)(long)v->Data()*/ < 0 ) b=-b;
2160  L->Init(3);
2161  L->m[0].rtyp=INT_CMD; L->m[0].data=(void *)(long)p0;
2162  L->m[1].rtyp=INT_CMD; L->m[1].data=(void *)(long)a;
2163  L->m[2].rtyp=INT_CMD; L->m[2].data=(void *)(long)b;
2164  res->rtyp=LIST_CMD;
2165  res->data=(char *)L;
2166  return FALSE;
2167 }
2169 {
2170  poly r,pa,pb;
2171  BOOLEAN ret=singclap_extgcd((poly)u->Data(),(poly)v->Data(),r,pa,pb,currRing);
2172  if (ret) return TRUE;
2174  L->Init(3);
2175  res->data=(char *)L;
2176  L->m[0].data=(void *)r;
2177  L->m[0].rtyp=POLY_CMD;
2178  L->m[1].data=(void *)pa;
2179  L->m[1].rtyp=POLY_CMD;
2180  L->m[2].data=(void *)pb;
2181  L->m[2].rtyp=POLY_CMD;
2182  return FALSE;
2183 }
2184 extern int singclap_factorize_retry;
2185 static BOOLEAN jjFAC_P2(leftv res, leftv u,leftv dummy)
2186 {
2187  intvec *v=NULL;
2188  int sw=(int)(long)dummy->Data();
2189  int fac_sw=sw;
2190  if ((sw<0)||(sw>2)) fac_sw=1;
2191  singclap_factorize_retry=0;
2192  ideal f=singclap_factorize((poly)(u->CopyD()), &v, fac_sw,currRing);
2193  if (f==NULL)
2194  return TRUE;
2195  switch(sw)
2196  {
2197  case 0:
2198  case 2:
2199  {
2201  l->Init(2);
2202  l->m[0].rtyp=IDEAL_CMD;
2203  l->m[0].data=(void *)f;
2204  l->m[1].rtyp=INTVEC_CMD;
2205  l->m[1].data=(void *)v;
2206  res->data=(void *)l;
2207  res->rtyp=LIST_CMD;
2208  return FALSE;
2209  }
2210  case 1:
2211  res->data=(void *)f;
2212  return FALSE;
2213  case 3:
2214  {
2215  poly p=f->m[0];
2216  int i=IDELEMS(f);
2217  f->m[0]=NULL;
2218  while(i>1)
2219  {
2220  i--;
2221  p=pMult(p,f->m[i]);
2222  f->m[i]=NULL;
2223  }
2224  res->data=(void *)p;
2225  res->rtyp=POLY_CMD;
2226  }
2227  return FALSE;
2228  }
2229  WerrorS("invalid switch");
2230  return TRUE;
2231 }
2233 {
2234  ideal_list p,h;
2235  h=kStdfac((ideal)v->Data(),NULL,testHomog,NULL,(ideal)w->Data());
2236  p=h;
2237  int l=0;
2238  while (p!=NULL) { p=p->next;l++; }
2240  L->Init(l);
2241  l=0;
2242  while(h!=NULL)
2243  {
2244  L->m[l].data=(char *)h->d;
2245  L->m[l].rtyp=IDEAL_CMD;
2246  p=h->next;
2247  omFreeSize(h,sizeof(*h));
2248  h=p;
2249  l++;
2250  }
2251  res->data=(void *)L;
2252  return FALSE;
2253 }
2255 {
2256  if (rField_is_Q(currRing))
2257  {
2258  number uu=(number)u->Data();
2259  number vv=(number)v->Data();
2260  res->data=(char *)n_Farey(uu,vv,currRing->cf);
2261  return FALSE;
2262  }
2263  else return TRUE;
2264 }
2266 {
2267  ideal uu=(ideal)u->Data();
2268  number vv=(number)v->Data();
2269  res->data=(void*)id_Farey(uu,vv,currRing);
2270  res->rtyp=u->Typ();
2271  return FALSE;
2272 }
2273 static BOOLEAN jjFETCH(leftv res, leftv u, leftv v)
2274 {
2275  ring r=(ring)u->Data();
2276  idhdl w;
2277  int op=iiOp;
2278  nMapFunc nMap;
2279 
2280  if ((w=r->idroot->get(v->Name(),myynest))!=NULL)
2281  {
2282  int *perm=NULL;
2283  int *par_perm=NULL;
2284  int par_perm_size=0;
2285  BOOLEAN bo;
2286  if ((nMap=n_SetMap(r->cf,currRing->cf))==NULL)
2287  {
2288  // Allow imap/fetch to be make an exception only for:
2289  if ( (rField_is_Q_a(r) && // Q(a..) -> Q(a..) || Q || Zp || Zp(a)
2292  ||
2293  (rField_is_Zp_a(r) && // Zp(a..) -> Zp(a..) || Zp
2294  (rField_is_Zp(currRing, r->cf->ch) ||
2295  rField_is_Zp_a(currRing, r->cf->ch))) )
2296  {
2297  par_perm_size=rPar(r);
2298  }
2299  else
2300  {
2301  goto err_fetch;
2302  }
2303  }
2304  if ((iiOp!=FETCH_CMD) || (r->N!=currRing->N) || (rPar(r)!=rPar(currRing)))
2305  {
2306  perm=(int *)omAlloc0((r->N+1)*sizeof(int));
2307  if (par_perm_size!=0)
2308  par_perm=(int *)omAlloc0(par_perm_size*sizeof(int));
2309  op=IMAP_CMD;
2310  if (iiOp==IMAP_CMD)
2311  {
2312  int r_par=0;
2313  char ** r_par_names=NULL;
2314  if (r->cf->extRing!=NULL)
2315  {
2316  r_par=r->cf->extRing->N;
2317  r_par_names=r->cf->extRing->names;
2318  }
2319  int c_par=0;
2320  char ** c_par_names=NULL;
2321  if (currRing->cf->extRing!=NULL)
2322  {
2323  c_par=currRing->cf->extRing->N;
2324  c_par_names=currRing->cf->extRing->names;
2325  }
2326  maFindPerm(r->names, r->N, r_par_names, r_par,
2327  currRing->names,currRing->N,c_par_names, c_par,
2328  perm,par_perm, currRing->cf->type);
2329  }
2330  else
2331  {
2332  int i;
2333  if (par_perm_size!=0)
2334  for(i=si_min(rPar(r),rPar(currRing))-1;i>=0;i--) par_perm[i]=-(i+1);
2335  for(i=si_min(r->N,currRing->N);i>0;i--) perm[i]=i;
2336  }
2337  }
2338  if ((iiOp==FETCH_CMD) &&(BVERBOSE(V_IMAP)))
2339  {
2340  int i;
2341  for(i=0;i<si_min(r->N,currRing->N);i++)
2342  {
2343  Print("// var nr %d: %s -> %s\n",i,r->names[i],currRing->names[i]);
2344  }
2345  for(i=0;i<si_min(rPar(r),rPar(currRing));i++) // possibly empty loop
2346  {
2347  Print("// par nr %d: %s -> %s\n",
2348  i,rParameter(r)[i],rParameter(currRing)[i]);
2349  }
2350  }
2351  if (IDTYP(w)==ALIAS_CMD) w=(idhdl)IDDATA(w);
2352  sleftv tmpW;
2353  memset(&tmpW,0,sizeof(sleftv));
2354  tmpW.rtyp=IDTYP(w);
2355  tmpW.data=IDDATA(w);
2356  if ((bo=maApplyFetch(op,NULL,res,&tmpW, r,
2357  perm,par_perm,par_perm_size,nMap)))
2358  {
2359  Werror("cannot map %s of type %s(%d)",v->name, Tok2Cmdname(w->typ),w->typ);
2360  }
2361  if (perm!=NULL)
2362  omFreeSize((ADDRESS)perm,(r->N+1)*sizeof(int));
2363  if (par_perm!=NULL)
2364  omFreeSize((ADDRESS)par_perm,par_perm_size*sizeof(int));
2365  return bo;
2366  }
2367  else
2368  {
2369  Werror("identifier %s not found in %s",v->Fullname(),u->Fullname());
2370  }
2371  return TRUE;
2372 err_fetch:
2373  Werror("no identity map from %s (%s -> %s)",u->Fullname(),
2374  nCoeffString(r->cf),
2375  nCoeffString(currRing->cf));
2376  return TRUE;
2377 }
2378 static BOOLEAN jjFIND2(leftv res, leftv u, leftv v)
2379 {
2380  /*4
2381  * look for the substring what in the string where
2382  * return the position of the first char of what in where
2383  * or 0
2384  */
2385  char *where=(char *)u->Data();
2386  char *what=(char *)v->Data();
2387  char *found = strstr(where,what);
2388  if (found != NULL)
2389  {
2390  res->data=(char *)((found-where)+1);
2391  }
2392  /*else res->data=NULL;*/
2393  return FALSE;
2394 }
2395 static BOOLEAN jjFWALK(leftv res, leftv u, leftv v)
2396 {
2397  res->data=(char *)fractalWalkProc(u,v);
2398  setFlag( res, FLAG_STD );
2399  return FALSE;
2400 }
2401 static BOOLEAN jjGCD_I(leftv res, leftv u, leftv v)
2402 {
2403  int uu=(int)(long)u->Data();int vv=(int)(long)v->Data();
2404  int p0=ABS(uu),p1=ABS(vv);
2405  int r;
2406  while ( p1!=0 )
2407  {
2408  r=p0 % p1;
2409  p0 = p1; p1 = r;
2410  }
2411  res->rtyp=INT_CMD;
2412  res->data=(char *)(long)p0;
2413  return FALSE;
2414 }
2415 static BOOLEAN jjGCD_BI(leftv res, leftv u, leftv v)
2416 {
2417  number n1 = (number) u->Data();
2418  number n2 = (number) v->Data();
2419  res->data = n_Gcd(n1,n2,coeffs_BIGINT);
2420  return FALSE;
2421 }
2422 static BOOLEAN jjGCD_N(leftv res, leftv u, leftv v)
2423 {
2424  number a=(number) u->Data();
2425  number b=(number) v->Data();
2426  if (nIsZero(a))
2427  {
2428  if (nIsZero(b)) res->data=(char *)nInit(1);
2429  else res->data=(char *)nCopy(b);
2430  }
2431  else
2432  {
2433  if (nIsZero(b)) res->data=(char *)nCopy(a);
2434  //else res->data=(char *)n_Gcd(a, b, currRing->cf);
2435  else res->data=(char *)n_SubringGcd(a, b, currRing->cf);
2436  }
2437  return FALSE;
2438 }
2439 static BOOLEAN jjGCD_P(leftv res, leftv u, leftv v)
2440 {
2441  res->data=(void *)singclap_gcd((poly)(u->CopyD(POLY_CMD)),
2442  (poly)(v->CopyD(POLY_CMD)),currRing);
2443  return FALSE;
2444 }
2446 {
2447 #ifdef HAVE_RINGS
2449  {
2450  ring origR = currRing;
2451  ring tempR = rCopy(origR);
2452  coeffs new_cf=nInitChar(n_Q,NULL);
2453  nKillChar(tempR->cf);
2454  tempR->cf=new_cf;
2455  rComplete(tempR);
2456  ideal uid = (ideal)u->Data();
2457  rChangeCurrRing(tempR);
2458  ideal uu = idrCopyR(uid, origR, currRing);
2459  sleftv uuAsLeftv; memset(&uuAsLeftv, 0, sizeof(uuAsLeftv));
2460  uuAsLeftv.rtyp = IDEAL_CMD;
2461  uuAsLeftv.data = uu; uuAsLeftv.next = NULL;
2462  if (hasFlag(u, FLAG_STD)) setFlag(&uuAsLeftv,FLAG_STD);
2463  assumeStdFlag(&uuAsLeftv);
2464  Print("// NOTE: computation of Hilbert series etc. is being\n");
2465  Print("// performed for generic fibre, that is, over Q\n");
2466  intvec *module_w=(intvec*)atGet(&uuAsLeftv,"isHomog",INTVEC_CMD);
2467  intvec *iv=hFirstSeries(uu,module_w,currRing->qideal);
2468  int returnWithTrue = 1;
2469  switch((int)(long)v->Data())
2470  {
2471  case 1:
2472  res->data=(void *)iv;
2473  returnWithTrue = 0;
2474  case 2:
2475  res->data=(void *)hSecondSeries(iv);
2476  delete iv;
2477  returnWithTrue = 0;
2478  }
2479  if (returnWithTrue)
2480  {
2482  delete iv;
2483  }
2484  idDelete(&uu);
2485  rChangeCurrRing(origR);
2486  rDelete(tempR);
2487  if (returnWithTrue) return TRUE; else return FALSE;
2488  }
2489 #endif
2490  assumeStdFlag(u);
2491  intvec *module_w=(intvec*)atGet(u,"isHomog",INTVEC_CMD);
2492  intvec *iv=hFirstSeries((ideal)u->Data(),module_w,currRing->qideal);
2493  switch((int)(long)v->Data())
2494  {
2495  case 1:
2496  res->data=(void *)iv;
2497  return FALSE;
2498  case 2:
2499  res->data=(void *)hSecondSeries(iv);
2500  delete iv;
2501  return FALSE;
2502  }
2504  delete iv;
2505  return TRUE;
2506 }
2507 static BOOLEAN jjHOMOG_P(leftv res, leftv u, leftv v)
2508 {
2509  int i=pVar((poly)v->Data());
2510  if (i==0)
2511  {
2512  WerrorS("ringvar expected");
2513  return TRUE;
2514  }
2515  poly p=pOne(); pSetExp(p,i,1); pSetm(p);
2516  int d=pWTotaldegree(p);
2517  pLmDelete(p);
2518  if (d==1)
2519  res->data = (char *)p_Homogen((poly)u->Data(), i, currRing);
2520  else
2521  WerrorS("variable must have weight 1");
2522  return (d!=1);
2523 }
2525 {
2526  int i=pVar((poly)v->Data());
2527  if (i==0)
2528  {
2529  WerrorS("ringvar expected");
2530  return TRUE;
2531  }
2532  pFDegProc deg;
2533  if (currRing->pLexOrder && (currRing->order[0]==ringorder_lp))
2534  deg=p_Totaldegree;
2535  else
2536  deg=currRing->pFDeg;
2537  poly p=pOne(); pSetExp(p,i,1); pSetm(p);
2538  int d=deg(p,currRing);
2539  pLmDelete(p);
2540  if (d==1)
2541  res->data = (char *)id_Homogen((ideal)u->Data(), i, currRing);
2542  else
2543  WerrorS("variable must have weight 1");
2544  return (d!=1);
2545 }
2547 {
2548  intvec *w=new intvec(rVar(currRing));
2549  intvec *vw=(intvec*)u->Data();
2550  ideal v_id=(ideal)v->Data();
2551  pFDegProc save_FDeg=currRing->pFDeg;
2552  pLDegProc save_LDeg=currRing->pLDeg;
2553  BOOLEAN save_pLexOrder=currRing->pLexOrder;
2554  currRing->pLexOrder=FALSE;
2555  kHomW=vw;
2556  kModW=w;
2558  res->data=(void *)(long)idHomModule(v_id,currRing->qideal,&w);
2559  currRing->pLexOrder=save_pLexOrder;
2560  kHomW=NULL;
2561  kModW=NULL;
2562  pRestoreDegProcs(currRing,save_FDeg,save_LDeg);
2563  if (w!=NULL) delete w;
2564  return FALSE;
2565 }
2567 {
2568  assumeStdFlag(u);
2569  res->data=(void *)scIndIndset((ideal)(u->Data()),(int)(long)(v->Data()),
2570  currRing->qideal);
2571  return FALSE;
2572 }
2574 {
2575  res->data=(char *)idSect((ideal)u->Data(),(ideal)v->Data());
2577  return FALSE;
2578 }
2580 {
2581  const lists L = (lists)l->Data();
2582  const int n = L->nr; assume (n >= 0);
2583  std::vector<ideal> V(n + 1);
2584 
2585  for(int i = n; i >= 0; i--) V[i] = (ideal)(L->m[i].Data());
2586 
2587  res->data=interpolation(V, (intvec*)v->Data());
2588  setFlag(res,FLAG_STD);
2589  return errorreported;
2590 }
2592 {
2593  extern BOOLEAN jjStdJanetBasis(leftv res, leftv v,int flag);
2594  return jjStdJanetBasis(res,u,(int)(long)v->Data());
2595 }
2596 
2598 {
2599  extern BOOLEAN jjStdJanetBasis(leftv res, leftv v,int flag);
2600  return jjStdJanetBasis(res,v,0);
2601 }
2602 static BOOLEAN jjJET_P(leftv res, leftv u, leftv v)
2603 {
2604  res->data = (char *)pJet((poly)u->CopyD(), (int)(long)v->Data());
2605  return FALSE;
2606 }
2607 static BOOLEAN jjJET_ID(leftv res, leftv u, leftv v)
2608 {
2609  res->data = (char *)id_Jet((ideal)u->Data(),(int)(long)v->Data(),currRing);
2610  return FALSE;
2611 }
2612 static BOOLEAN jjKBASE2(leftv res, leftv u, leftv v)
2613 {
2614  assumeStdFlag(u);
2615  intvec *w_u=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
2616  res->data = (char *)scKBase((int)(long)v->Data(),
2617  (ideal)(u->Data()),currRing->qideal, w_u);
2618  if (w_u!=NULL)
2619  {
2620  atSet(res,omStrDup("isHomog"),ivCopy(w_u),INTVEC_CMD);
2621  }
2622  return FALSE;
2623 }
2624 static BOOLEAN jjPREIMAGE(leftv res, leftv u, leftv v, leftv w);
2625 static BOOLEAN jjKERNEL(leftv res, leftv u, leftv v)
2626 {
2627  return jjPREIMAGE(res,u,v,NULL);
2628 }
2629 static BOOLEAN jjKoszul(leftv res, leftv u, leftv v)
2630 {
2631  return mpKoszul(res, u,v,NULL);
2632 }
2634 {
2635  sleftv h;
2636  memset(&h,0,sizeof(sleftv));
2637  h.rtyp=INT_CMD;
2638  h.data=(void *)(long)IDELEMS((ideal)v->Data());
2639  return mpKoszul(res, u, &h, v);
2640 }
2641 static BOOLEAN jjLIFT(leftv res, leftv u, leftv v)
2642 {
2643  int ul= IDELEMS((ideal)u->Data());
2644  int vl= IDELEMS((ideal)v->Data());
2645  ideal m = idLift((ideal)u->Data(),(ideal)v->Data(),NULL,FALSE,
2646  hasFlag(u,FLAG_STD));
2647  if (m==NULL) return TRUE;
2648  res->data = (char *)id_Module2formatedMatrix(m,ul,vl,currRing);
2649  return FALSE;
2650 }
2651 static BOOLEAN jjLIFTSTD(leftv res, leftv u, leftv v)
2652 {
2653  if ((v->rtyp!=IDHDL)||(v->e!=NULL)) return TRUE;
2654  idhdl h=(idhdl)v->data;
2655  // CopyD for IDEAL_CMD and MODUL_CMD are identical:
2656  res->data = (char *)idLiftStd((ideal)u->Data(),
2657  &(h->data.umatrix),testHomog);
2658  setFlag(res,FLAG_STD); v->flag=0;
2659  return FALSE;
2660 }
2661 static BOOLEAN jjLOAD2(leftv /*res*/, leftv, leftv v)
2662 {
2663  return jjLOAD((char*)v->Data(),TRUE);
2664 }
2665 static BOOLEAN jjLOAD_E(leftv /*res*/, leftv v, leftv u)
2666 {
2667  char * s=(char *)u->Data();
2668  if(strcmp(s, "with")==0)
2669  return jjLOAD((char*)v->Data(), TRUE);
2670  if (strcmp(s,"try")==0)
2671  return jjLOAD_TRY((char*)v->Data());
2672  WerrorS("invalid second argument");
2673  WerrorS("load(\"libname\" [,option]);");
2674  return TRUE;
2675 }
2676 static BOOLEAN jjMODULO(leftv res, leftv u, leftv v)
2677 {
2678  intvec *w_u=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
2679  tHomog hom=testHomog;
2680  if (w_u!=NULL)
2681  {
2682  w_u=ivCopy(w_u);
2683  hom=isHomog;
2684  }
2685  intvec *w_v=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
2686  if (w_v!=NULL)
2687  {
2688  w_v=ivCopy(w_v);
2689  hom=isHomog;
2690  }
2691  if ((w_u!=NULL) && (w_v==NULL))
2692  w_v=ivCopy(w_u);
2693  if ((w_v!=NULL) && (w_u==NULL))
2694  w_u=ivCopy(w_v);
2695  ideal u_id=(ideal)u->Data();
2696  ideal v_id=(ideal)v->Data();
2697  if (w_u!=NULL)
2698  {
2699  if ((*w_u).compare((w_v))!=0)
2700  {
2701  WarnS("incompatible weights");
2702  delete w_u; w_u=NULL;
2703  hom=testHomog;
2704  }
2705  else
2706  {
2707  if ((!idTestHomModule(u_id,currRing->qideal,w_v))
2708  || (!idTestHomModule(v_id,currRing->qideal,w_v)))
2709  {
2710  WarnS("wrong weights");
2711  delete w_u; w_u=NULL;
2712  hom=testHomog;
2713  }
2714  }
2715  }
2716  res->data = (char *)idModulo(u_id,v_id ,hom,&w_u);
2717  if (w_u!=NULL)
2718  {
2719  atSet(res,omStrDup("isHomog"),w_u,INTVEC_CMD);
2720  }
2721  delete w_v;
2722  //if (TEST_OPT_RETURN_SB) setFlag(res,FLAG_STD);
2723  return FALSE;
2724 }
2725 static BOOLEAN jjMOD_BI(leftv res, leftv u, leftv v)
2726 {
2727  number q=(number)v->Data();
2728  if (n_IsZero(q,coeffs_BIGINT))
2729  {
2731  return TRUE;
2732  }
2733  res->data =(char *) n_IntMod((number)u->Data(),q,coeffs_BIGINT);
2734  return FALSE;
2735 }
2736 static BOOLEAN jjMOD_N(leftv res, leftv u, leftv v)
2737 {
2738  number q=(number)v->Data();
2739  if (nIsZero(q))
2740  {
2742  return TRUE;
2743  }
2744  res->data =(char *) n_IntMod((number)u->Data(),q,currRing->cf);
2745  return FALSE;
2746 }
2747 static BOOLEAN jjMONITOR2(leftv res, leftv u,leftv v);
2749 {
2750  return jjMONITOR2(res,v,NULL);
2751 }
2753 {
2754 #if 0
2755  char *opt=(char *)v->Data();
2756  int mode=0;
2757  while(*opt!='\0')
2758  {
2759  if (*opt=='i') mode |= SI_PROT_I;
2760  else if (*opt=='o') mode |= SI_PROT_O;
2761  opt++;
2762  }
2763  monitor((char *)(u->Data()),mode);
2764 #else
2765  si_link l=(si_link)u->Data();
2766  if (slOpen(l,SI_LINK_WRITE,u)) return TRUE;
2767  if(strcmp(l->m->type,"ASCII")!=0)
2768  {
2769  Werror("ASCII link required, not `%s`",l->m->type);
2770  slClose(l);
2771  return TRUE;
2772  }
2773  SI_LINK_SET_CLOSE_P(l); // febase handles the FILE*
2774  if ( l->name[0]!='\0') // "" is the stop condition
2775  {
2776  const char *opt;
2777  int mode=0;
2778  if (v==NULL) opt=(const char*)"i";
2779  else opt=(const char *)v->Data();
2780  while(*opt!='\0')
2781  {
2782  if (*opt=='i') mode |= SI_PROT_I;
2783  else if (*opt=='o') mode |= SI_PROT_O;
2784  opt++;
2785  }
2786  monitor((FILE *)l->data,mode);
2787  }
2788  else
2789  monitor(NULL,0);
2790  return FALSE;
2791 #endif
2792 }
2793 static BOOLEAN jjMONOM(leftv res, leftv v)
2794 {
2795  intvec *iv=(intvec *)v->Data();
2796  poly p=pOne();
2797  int i,e;
2798  BOOLEAN err=FALSE;
2799  for(i=si_min(currRing->N,iv->length()); i>0; i--)
2800  {
2801  e=(*iv)[i-1];
2802  if (e>=0) pSetExp(p,i,e);
2803  else err=TRUE;
2804  }
2805  if (iv->length()==(currRing->N+1))
2806  {
2807  res->rtyp=VECTOR_CMD;
2808  e=(*iv)[currRing->N];
2809  if (e>=0) pSetComp(p,e);
2810  else err=TRUE;
2811  }
2812  pSetm(p);
2813  res->data=(char*)p;
2814  if(err) { pDelete(&p); WerrorS("no negative exponent allowed"); }
2815  return err;
2816 }
2818 {
2819  // u: the name of the new type
2820  // v: the elements
2821  newstruct_desc d=newstructFromString((const char *)v->Data());
2822  if (d!=NULL) newstruct_setup((const char *)u->Data(),d);
2823  return d==NULL;
2824 }
2825 static BOOLEAN jjPARSTR2(leftv res, leftv u, leftv v)
2826 {
2827  idhdl h=(idhdl)u->data;
2828  int i=(int)(long)v->Data();
2829  int p=0;
2830  if ((0<i)
2831  && (rParameter(IDRING(h))!=NULL)
2832  && (i<=(p=rPar(IDRING(h)))))
2833  res->data=omStrDup(rParameter(IDRING(h))[i-1]);
2834  else
2835  {
2836  Werror("par number %d out of range 1..%d",i,p);
2837  return TRUE;
2838  }
2839  return FALSE;
2840 }
2841 #ifdef HAVE_PLURAL
2843 {
2844  if( currRing->qideal != NULL )
2845  {
2846  WerrorS("basering must NOT be a qring!");
2847  return TRUE;
2848  }
2849 
2850  if (iiOp==NCALGEBRA_CMD)
2851  {
2852  return nc_CallPlural(NULL,NULL,(poly)a->Data(),(poly)b->Data(),currRing,false,true,false,currRing);
2853  }
2854  else
2855  {
2856  ring r=rCopy(currRing);
2857  BOOLEAN result=nc_CallPlural(NULL,NULL,(poly)a->Data(),(poly)b->Data(),r,false,true,false,currRing);
2858  res->data=r;
2859  if (r->qideal!=NULL) res->rtyp=QRING_CMD;
2860  return result;
2861  }
2862 }
2864 {
2865  if( currRing->qideal != NULL )
2866  {
2867  WerrorS("basering must NOT be a qring!");
2868  return TRUE;
2869  }
2870 
2871  if (iiOp==NCALGEBRA_CMD)
2872  {
2873  return nc_CallPlural(NULL,(matrix)b->Data(),(poly)a->Data(),NULL,currRing,false,true,false,currRing);
2874  }
2875  else
2876  {
2877  ring r=rCopy(currRing);
2878  BOOLEAN result=nc_CallPlural(NULL,(matrix)b->Data(),(poly)a->Data(),NULL,r,false,true,false,currRing);
2879  res->data=r;
2880  if (r->qideal!=NULL) res->rtyp=QRING_CMD;
2881  return result;
2882  }
2883 }
2885 {
2886  if( currRing->qideal != NULL )
2887  {
2888  WerrorS("basering must NOT be a qring!");
2889  return TRUE;
2890  }
2891 
2892  if (iiOp==NCALGEBRA_CMD)
2893  {
2894  return nc_CallPlural((matrix)a->Data(),NULL,NULL,(poly)b->Data(),currRing,false,true,false,currRing);
2895  }
2896  else
2897  {
2898  ring r=rCopy(currRing);
2899  BOOLEAN result=nc_CallPlural((matrix)a->Data(),NULL,NULL,(poly)b->Data(),r,false,true,false,currRing);
2900  res->data=r;
2901  if (r->qideal!=NULL) res->rtyp=QRING_CMD;
2902  return result;
2903  }
2904 }
2906 {
2907  if( currRing->qideal != NULL )
2908  {
2909  WerrorS("basering must NOT be a qring!");
2910  return TRUE;
2911  }
2912 
2913  if (iiOp==NCALGEBRA_CMD)
2914  {
2915  return nc_CallPlural((matrix)a->Data(),(matrix)b->Data(),NULL,NULL,currRing,false,true,false,currRing);
2916  }
2917  else
2918  {
2919  ring r=rCopy(currRing);
2920  BOOLEAN result=nc_CallPlural((matrix)a->Data(),(matrix)b->Data(),NULL,NULL,r,false,true,false,currRing);
2921  res->data=r;
2922  if (r->qideal!=NULL) res->rtyp=QRING_CMD;
2923  return result;
2924  }
2925 }
2927 {
2928  res->data=NULL;
2929 
2930  if (rIsPluralRing(currRing))
2931  {
2932  const poly q = (poly)b->Data();
2933 
2934  if( q != NULL )
2935  {
2936  if( (poly)a->Data() != NULL )
2937  {
2938  poly p = (poly)a->CopyD(POLY_CMD); // p = copy!
2939  res->data = nc_p_Bracket_qq(p,q, currRing); // p will be destroyed!
2940  }
2941  }
2942  }
2943  return FALSE;
2944 }
2946 {
2947  /* number, poly, vector, ideal, module, matrix */
2948  ring r = (ring)a->Data();
2949  if (r == currRing)
2950  {
2951  res->data = b->Data();
2952  res->rtyp = b->rtyp;
2953  return FALSE;
2954  }
2955  if (!rIsLikeOpposite(currRing, r))
2956  {
2957  Werror("%s is not an opposite ring to current ring",a->Fullname());
2958  return TRUE;
2959  }
2960  idhdl w;
2961  if( ((w=r->idroot->get(b->Name(),myynest))!=NULL) && (b->e==NULL))
2962  {
2963  int argtype = IDTYP(w);
2964  switch (argtype)
2965  {
2966  case NUMBER_CMD:
2967  {
2968  /* since basefields are equal, we can apply nCopy */
2969  res->data = nCopy((number)IDDATA(w));
2970  res->rtyp = argtype;
2971  break;
2972  }
2973  case POLY_CMD:
2974  case VECTOR_CMD:
2975  {
2976  poly q = (poly)IDDATA(w);
2977  res->data = pOppose(r,q,currRing);
2978  res->rtyp = argtype;
2979  break;
2980  }
2981  case IDEAL_CMD:
2982  case MODUL_CMD:
2983  {
2984  ideal Q = (ideal)IDDATA(w);
2985  res->data = idOppose(r,Q,currRing);
2986  res->rtyp = argtype;
2987  break;
2988  }
2989  case MATRIX_CMD:
2990  {
2991  ring save = currRing;
2992  rChangeCurrRing(r);
2993  matrix m = (matrix)IDDATA(w);
2995  rChangeCurrRing(save);
2996  ideal S = idOppose(r,Q,currRing);
2997  id_Delete(&Q, r);
2998  res->data = id_Module2Matrix(S,currRing);
2999  res->rtyp = argtype;
3000  break;
3001  }
3002  default:
3003  {
3004  WerrorS("unsupported type in oppose");
3005  return TRUE;
3006  }
3007  }
3008  }
3009  else
3010  {
3011  Werror("identifier %s not found in %s",b->Fullname(),a->Fullname());
3012  return TRUE;
3013  }
3014  return FALSE;
3015 }
3016 #endif /* HAVE_PLURAL */
3017 
3018 static BOOLEAN jjQUOT(leftv res, leftv u, leftv v)
3019 {
3020  res->data = (char *)idQuot((ideal)u->Data(),(ideal)v->Data(),
3021  hasFlag(u,FLAG_STD),u->Typ()==v->Typ());
3022  id_DelMultiples((ideal)(res->data),currRing);
3024  return FALSE;
3025 }
3026 static BOOLEAN jjRANDOM(leftv res, leftv u, leftv v)
3027 {
3028  int i=(int)(long)u->Data();
3029  int j=(int)(long)v->Data();
3030  if (j-i <0) {WerrorS("invalid range for random"); return TRUE;}
3031  res->data =(char *)(long)((i > j) ? i : (siRand() % (j-i+1)) + i);
3032  return FALSE;
3033 }
3034 static BOOLEAN jjRANK2(leftv res, leftv u, leftv v)
3035 {
3036  matrix m =(matrix)u->Data();
3037  int isRowEchelon = (int)(long)v->Data();
3038  if (isRowEchelon != 1) isRowEchelon = 0;
3039  int rank = luRank(m, isRowEchelon);
3040  res->data =(char *)(long)rank;
3041  return FALSE;
3042 }
3043 static BOOLEAN jjREAD2(leftv res, leftv u, leftv v)
3044 {
3045  si_link l=(si_link)u->Data();
3046  leftv r=slRead(l,v);
3047  if (r==NULL)
3048  {
3049  const char *s;
3050  if ((l!=NULL)&&(l->name!=NULL)) s=l->name;
3051  else s=sNoName;
3052  Werror("cannot read from `%s`",s);
3053  return TRUE;
3054  }
3055  memcpy(res,r,sizeof(sleftv));
3057  return FALSE;
3058 }
3060 {
3061  ideal vi=(ideal)v->Data();
3062  if (currRing->qideal!=NULL || vi->ncols>1 || rIsPluralRing(currRing))
3063  assumeStdFlag(v);
3064  res->data = (char *)kNF(vi,currRing->qideal,(poly)u->Data());
3065  return FALSE;
3066 }
3068 {
3069  ideal ui=(ideal)u->Data();
3070  ideal vi=(ideal)v->Data();
3071  if (currRing->qideal!=NULL || vi->ncols>1 || rIsPluralRing(currRing))
3072  assumeStdFlag(v);
3073  res->data = (char *)kNF(vi,currRing->qideal,ui);
3074  return FALSE;
3075 }
3076 #if 0
3077 static BOOLEAN jjRES(leftv res, leftv u, leftv v)
3078 {
3079  int maxl=(int)(long)v->Data();
3080  if (maxl<0)
3081  {
3082  WerrorS("length for res must not be negative");
3083  return TRUE;
3084  }
3085  int l=0;
3086  //resolvente r;
3087  syStrategy r;
3088  intvec *weights=NULL;
3089  int wmaxl=maxl;
3090  ideal u_id=(ideal)u->Data();
3091 
3092  maxl--;
3093  if (/*(*/ maxl==-1 /*)*/) /*&& (iiOp!=MRES_CMD)*/
3094  {
3095  maxl = currRing->N-1+2*(iiOp==MRES_CMD);
3096  if (currRing->qideal!=NULL)
3097  {
3098  Warn(
3099  "full resolution in a qring may be infinite, setting max length to %d",
3100  maxl+1);
3101  }
3102  }
3103  weights=(intvec*)atGet(u,"isHomog",INTVEC_CMD);
3104  if (weights!=NULL)
3105  {
3106  if (!idTestHomModule(u_id,currRing->qideal,weights))
3107  {
3108  WarnS("wrong weights given:");weights->show();PrintLn();
3109  weights=NULL;
3110  }
3111  }
3112  intvec *ww=NULL;
3113  int add_row_shift=0;
3114  if (weights!=NULL)
3115  {
3116  ww=ivCopy(weights);
3117  add_row_shift = ww->min_in();
3118  (*ww) -= add_row_shift;
3119  }
3120  else
3121  idHomModule(u_id,currRing->qideal,&ww);
3122  weights=ww;
3123 
3124  if ((iiOp == RES_CMD) || (iiOp == MRES_CMD))
3125  {
3126  r=syResolution(u_id,maxl, ww, iiOp==MRES_CMD);
3127  }
3128  else if (iiOp==SRES_CMD)
3129  // r=sySchreyerResolvente(u_id,maxl+1,&l);
3130  r=sySchreyer(u_id,maxl+1);
3131  else if (iiOp == LRES_CMD)
3132  {
3133  int dummy;
3134  if((currRing->qideal!=NULL)||
3135  (!idHomIdeal (u_id,NULL)))
3136  {
3137  WerrorS
3138  ("`lres` not implemented for inhomogeneous input or qring");
3139  return TRUE;
3140  }
3141  r=syLaScala3(u_id,&dummy);
3142  }
3143  else if (iiOp == KRES_CMD)
3144  {
3145  int dummy;
3146  if((currRing->qideal!=NULL)||
3147  (!idHomIdeal (u_id,NULL)))
3148  {
3149  WerrorS
3150  ("`kres` not implemented for inhomogeneous input or qring");
3151  return TRUE;
3152  }
3153  r=syKosz(u_id,&dummy);
3154  }
3155  else
3156  {
3157  int dummy;
3158  if((currRing->qideal!=NULL)||
3159  (!idHomIdeal (u_id,NULL)))
3160  {
3161  WerrorS
3162  ("`hres` not implemented for inhomogeneous input or qring");
3163  return TRUE;
3164  }
3165  r=syHilb(u_id,&dummy);
3166  }
3167  if (r==NULL) return TRUE;
3168  //res->data=(void *)liMakeResolv(r,l,wmaxl,u->Typ(),weights);
3169  r->list_length=wmaxl;
3170  res->data=(void *)r;
3171  if ((r->weights!=NULL) && (r->weights[0]!=NULL))
3172  {
3173  intvec *w=ivCopy(r->weights[0]);
3174  if (weights!=NULL) (*w) += add_row_shift;
3175  atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
3176  w=NULL;
3177  }
3178  else
3179  {
3180 //#if 0
3181 // need to set weights for ALL components (sres)
3182  if (weights!=NULL)
3183  {
3184  atSet(res,omStrDup("isHomog"),ivCopy(weights),INTVEC_CMD);
3186  (r->weights)[0] = ivCopy(weights);
3187  }
3188 //#endif
3189  }
3190  if (ww!=NULL) { delete ww; ww=NULL; }
3191  return FALSE;
3192 }
3193 #else
3194 static BOOLEAN jjRES(leftv res, leftv u, leftv v)
3195 {
3196  int maxl=(int)(long)v->Data();
3197  if (maxl<0)
3198  {
3199  WerrorS("length for res must not be negative");
3200  return TRUE;
3201  }
3202  syStrategy r;
3203  intvec *weights=NULL;
3204  int wmaxl=maxl;
3205  ideal u_id=(ideal)u->Data();
3206 
3207  maxl--;
3208  if (/*(*/ maxl==-1 /*)*/) /*&& (iiOp!=MRES_CMD)*/
3209  {
3210  maxl = currRing->N-1+2*(iiOp==MRES_CMD);
3211  if (currRing->qideal!=NULL)
3212  {
3213  Warn(
3214  "full resolution in a qring may be infinite, setting max length to %d",
3215  maxl+1);
3216  }
3217  }
3218  weights=(intvec*)atGet(u,"isHomog",INTVEC_CMD);
3219  if (weights!=NULL)
3220  {
3221  if (!idTestHomModule(u_id,currRing->qideal,weights))
3222  {
3223  WarnS("wrong weights given:");weights->show();PrintLn();
3224  weights=NULL;
3225  }
3226  }
3227  intvec *ww=NULL;
3228  int add_row_shift=0;
3229  if (weights!=NULL)
3230  {
3231  ww=ivCopy(weights);
3232  add_row_shift = ww->min_in();
3233  (*ww) -= add_row_shift;
3234  }
3235  if ((iiOp == RES_CMD) || (iiOp == MRES_CMD))
3236  {
3237  r=syResolution(u_id,maxl, ww, iiOp==MRES_CMD);
3238  }
3239  else if (iiOp==SRES_CMD)
3240  // r=sySchreyerResolvente(u_id,maxl+1,&l);
3241  r=sySchreyer(u_id,maxl+1);
3242  else if (iiOp == LRES_CMD)
3243  {
3244  int dummy;
3245  if((currRing->qideal!=NULL)||
3246  (!idHomIdeal (u_id,NULL)))
3247  {
3248  WerrorS
3249  ("`lres` not implemented for inhomogeneous input or qring");
3250  return TRUE;
3251  }
3252  if(currRing->N == 1)
3253  WarnS("the current implementation of `lres` may not work in the case of a single variable");
3254  r=syLaScala3(u_id,&dummy);
3255  }
3256  else if (iiOp == KRES_CMD)
3257  {
3258  int dummy;
3259  if((currRing->qideal!=NULL)||
3260  (!idHomIdeal (u_id,NULL)))
3261  {
3262  WerrorS
3263  ("`kres` not implemented for inhomogeneous input or qring");
3264  return TRUE;
3265  }
3266  r=syKosz(u_id,&dummy);
3267  }
3268  else
3269  {
3270  int dummy;
3271  if((currRing->qideal!=NULL)||
3272  (!idHomIdeal (u_id,NULL)))
3273  {
3274  WerrorS
3275  ("`hres` not implemented for inhomogeneous input or qring");
3276  return TRUE;
3277  }
3278  ideal u_id_copy=idCopy(u_id);
3279  idSkipZeroes(u_id_copy);
3280  r=syHilb(u_id_copy,&dummy);
3281  idDelete(&u_id_copy);
3282  }
3283  if (r==NULL) return TRUE;
3284  //res->data=(void *)liMakeResolv(r,l,wmaxl,u->Typ(),weights);
3285  r->list_length=wmaxl;
3286  res->data=(void *)r;
3287  if ((weights!=NULL) && (ww!=NULL)) { delete ww; ww=NULL; }
3288  if ((r->weights!=NULL) && (r->weights[0]!=NULL))
3289  {
3290  ww=ivCopy(r->weights[0]);
3291  if (weights!=NULL) (*ww) += add_row_shift;
3292  atSet(res,omStrDup("isHomog"),ww,INTVEC_CMD);
3293  }
3294  else
3295  {
3296  if (weights!=NULL)
3297  {
3298  atSet(res,omStrDup("isHomog"),ivCopy(weights),INTVEC_CMD);
3299  }
3300  }
3301 
3302  // test the La Scala case' output
3303  assume( ((iiOp == LRES_CMD) || (iiOp == HRES_CMD)) == (r->syRing != NULL) );
3304  assume( (r->syRing != NULL) == (r->resPairs != NULL) );
3305 
3306  if(iiOp != HRES_CMD)
3307  assume( (r->minres != NULL) || (r->fullres != NULL) ); // is wrong for HRES_CMD...
3308  else
3309  assume( (r->orderedRes != NULL) || (r->res != NULL) ); // analog for hres...
3310 
3311  return FALSE;
3312 }
3313 #endif
3314 static BOOLEAN jjPFAC2(leftv res, leftv u, leftv v)
3315 {
3316  number n1; int i;
3317 
3318  if ((u->Typ() == BIGINT_CMD) ||
3319  ((u->Typ() == NUMBER_CMD) && rField_is_Q(currRing)))
3320  {
3321  n1 = (number)u->CopyD();
3322  }
3323  else if (u->Typ() == INT_CMD)
3324  {
3325  i = (int)(long)u->Data();
3326  n1 = n_Init(i, coeffs_BIGINT);
3327  }
3328  else
3329  {
3330  return TRUE;
3331  }
3332 
3333  i = (int)(long)v->Data();
3334 
3335  lists l = primeFactorisation(n1, i);
3336  n_Delete(&n1, coeffs_BIGINT);
3337  res->data = (char*)l;
3338  return FALSE;
3339 }
3340 static BOOLEAN jjRSUM(leftv res, leftv u, leftv v)
3341 {
3342  ring r;
3343  int i=rSum((ring)u->Data(),(ring)v->Data(),r);
3344  res->data = (char *)r;
3345  return (i==-1);
3346 }
3347 #define SIMPL_LMDIV 32
3348 #define SIMPL_LMEQ 16
3349 #define SIMPL_MULT 8
3350 #define SIMPL_EQU 4
3351 #define SIMPL_NULL 2
3352 #define SIMPL_NORM 1
3354 {
3355  int sw = (int)(long)v->Data();
3356  // CopyD for IDEAL_CMD and MODUL_CMD are identical:
3357  ideal id = (ideal)u->CopyD(IDEAL_CMD);
3358  if (sw & SIMPL_LMDIV)
3359  {
3360  id_DelDiv(id,currRing);
3361  }
3362  if (sw & SIMPL_LMEQ)
3363  {
3365  }
3366  if (sw & SIMPL_MULT)
3367  {
3369  }
3370  else if(sw & SIMPL_EQU)
3371  {
3372  id_DelEquals(id,currRing);
3373  }
3374  if (sw & SIMPL_NULL)
3375  {
3376  idSkipZeroes(id);
3377  }
3378  if (sw & SIMPL_NORM)
3379  {
3380  id_Norm(id,currRing);
3381  }
3382  res->data = (char * )id;
3383  return FALSE;
3384 }
3386 static BOOLEAN jjSQR_FREE2(leftv res, leftv u, leftv dummy)
3387 {
3388  intvec *v=NULL;
3389  int sw=(int)(long)dummy->Data();
3390  int fac_sw=sw;
3391  if (sw<0) fac_sw=1;
3392  singclap_factorize_retry=0;
3393  ideal f=singclap_sqrfree((poly)(u->CopyD()), &v, fac_sw, currRing);
3394  if (f==NULL)
3395  return TRUE;
3396  switch(sw)
3397  {
3398  case 0:
3399  case 2:
3400  {
3402  l->Init(2);
3403  l->m[0].rtyp=IDEAL_CMD;
3404  l->m[0].data=(void *)f;
3405  l->m[1].rtyp=INTVEC_CMD;
3406  l->m[1].data=(void *)v;
3407  res->data=(void *)l;
3408  res->rtyp=LIST_CMD;
3409  return FALSE;
3410  }
3411  case 1:
3412  res->data=(void *)f;
3413  return FALSE;
3414  case 3:
3415  {
3416  poly p=f->m[0];
3417  int i=IDELEMS(f);
3418  f->m[0]=NULL;
3419  while(i>1)
3420  {
3421  i--;
3422  p=pMult(p,f->m[i]);
3423  f->m[i]=NULL;
3424  }
3425  res->data=(void *)p;
3426  res->rtyp=POLY_CMD;
3427  }
3428  return FALSE;
3429  }
3430  WerrorS("invalid switch");
3431  return FALSE;
3432 }
3433 static BOOLEAN jjSTATUS2(leftv res, leftv u, leftv v)
3434 {
3435  res->data = omStrDup(slStatus((si_link) u->Data(), (char *) v->Data()));
3436  return FALSE;
3437 }
3439 {
3440  res->data = (void *)(long)slStatusSsiL((lists) u->Data(), (int)(long) v->Data());
3441  //return (res->data== (void*)(long)-2);
3442  return FALSE;
3443 }
3444 static BOOLEAN jjSIMPL_P(leftv res, leftv u, leftv v)
3445 {
3446  int sw = (int)(long)v->Data();
3447  // CopyD for POLY_CMD and VECTOR_CMD are identical:
3448  poly p = (poly)u->CopyD(POLY_CMD);
3449  if (sw & SIMPL_NORM)
3450  {
3451  pNorm(p);
3452  }
3453  res->data = (char * )p;
3454  return FALSE;
3455 }
3457 {
3458  ideal result;
3459  intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
3460  tHomog hom=testHomog;
3461  ideal u_id=(ideal)(u->Data());
3462  if (w!=NULL)
3463  {
3464  if (!idTestHomModule(u_id,currRing->qideal,w))
3465  {
3466  WarnS("wrong weights:");w->show();PrintLn();
3467  w=NULL;
3468  }
3469  else
3470  {
3471  w=ivCopy(w);
3472  hom=isHomog;
3473  }
3474  }
3475  result=kStd(u_id,currRing->qideal,hom,&w,(intvec *)v->Data());
3476  idSkipZeroes(result);
3477  res->data = (char *)result;
3478  setFlag(res,FLAG_STD);
3479  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
3480  return FALSE;
3481 }
3482 static BOOLEAN jjSTD_1(leftv res, leftv u, leftv v)
3483 {
3484  ideal result;
3485  assumeStdFlag(u);
3486  ideal i1=(ideal)(u->Data());
3487  ideal i0;
3488  int r=v->Typ();
3489  if ((/*v->Typ()*/r==POLY_CMD) ||(r==VECTOR_CMD))
3490  {
3491  i0=idInit(1,i1->rank); // TODO: rank is wrong (if v is a vector!)
3492  i0->m[0]=(poly)v->Data();
3493  int ii0=idElem(i0); /* size of i0 */
3494  i1=idSimpleAdd(i1,i0); //
3495  memset(i0->m,0,sizeof(poly)*IDELEMS(i0));
3496  idDelete(&i0);
3497  intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
3498  tHomog hom=testHomog;
3499 
3500  if (w!=NULL)
3501  {
3502  if (!idTestHomModule(i1,currRing->qideal,w))
3503  {
3504  // no warnung: this is legal, if i in std(i,p)
3505  // is homogeneous, but p not
3506  w=NULL;
3507  }
3508  else
3509  {
3510  w=ivCopy(w);
3511  hom=isHomog;
3512  }
3513  }
3514  BITSET save1;
3515  SI_SAVE_OPT1(save1);
3517  /* ii0 appears to be the position of the first element of il that
3518  does not belong to the old SB ideal */
3519  result=kStd(i1,currRing->qideal,hom,&w,NULL,0,ii0);
3520  SI_RESTORE_OPT1(save1);
3521  idDelete(&i1);
3522  idSkipZeroes(result);
3523  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
3524  res->data = (char *)result;
3525  }
3526  else /*IDEAL/MODULE*/
3527  {
3528  i0=(ideal)v->CopyD();
3529  int ii0=idElem(i0); /* size of i0 */
3530  i1=idSimpleAdd(i1,i0); //
3531  memset(i0->m,0,sizeof(poly)*IDELEMS(i0));
3532  idDelete(&i0);
3533  intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
3534  tHomog hom=testHomog;
3535 
3536  if (w!=NULL)
3537  {
3538  if (!idTestHomModule(i1,currRing->qideal,w))
3539  {
3540  // no warnung: this is legal, if i in std(i,p)
3541  // is homogeneous, but p not
3542  w=NULL;
3543  }
3544  else
3545  {
3546  w=ivCopy(w);
3547  hom=isHomog;
3548  }
3549  }
3550  if (ii0*4 >= 3*IDELEMS(i1)) // MAGIC: add few poly to large SB: 3/4
3551  {
3552  BITSET save1;
3553  SI_SAVE_OPT1(save1);
3555  /* ii0 appears to be the position of the first element of il that
3556  does not belong to the old SB ideal */
3557  result=kStd(i1,currRing->qideal,hom,&w,NULL,0,ii0);
3558  SI_RESTORE_OPT1(save1);
3559  }
3560  else
3561  {
3562  result=kStd(i1,currRing->qideal,hom,&w);
3563  }
3564  idDelete(&i1);
3565  idSkipZeroes(result);
3566  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
3567  res->data = (char *)result;
3568  }
3570  return FALSE;
3571 }
3572 static BOOLEAN jjVARSTR2(leftv res, leftv u, leftv v)
3573 {
3574  idhdl h=(idhdl)u->data;
3575  int i=(int)(long)v->Data();
3576  if ((0<i) && (i<=IDRING(h)->N))
3577  res->data=omStrDup(IDRING(h)->names[i-1]);
3578  else
3579  {
3580  Werror("var number %d out of range 1..%d",i,IDRING(h)->N);
3581  return TRUE;
3582  }
3583  return FALSE;
3584 }
3586 {
3587 // input: u: a list with links of type
3588 // ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch
3589 // v: timeout for select in milliseconds
3590 // or 0 for polling
3591 // returns: ERROR (via Werror): timeout negative
3592 // -1: the read state of all links is eof
3593 // 0: timeout (or polling): none ready
3594 // i>0: (at least) L[i] is ready
3595  lists Lforks = (lists)u->Data();
3596  int t = (int)(long)v->Data();
3597  if(t < 0)
3598  {
3599  WerrorS("negative timeout"); return TRUE;
3600  }
3601  int i = slStatusSsiL(Lforks, t*1000);
3602  if(i == -2) /* error */
3603  {
3604  return TRUE;
3605  }
3606  res->data = (void*)(long)i;
3607  return FALSE;
3608 }
3610 {
3611 // input: u: a list with links of type
3612 // ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch
3613 // v: timeout for select in milliseconds
3614 // or 0 for polling
3615 // returns: ERROR (via Werror): timeout negative
3616 // -1: the read state of all links is eof
3617 // 0: timeout (or polling): none ready
3618 // 1: all links are ready
3619 // (caution: at least one is ready, but some maybe dead)
3620  lists Lforks = (lists)u->CopyD();
3621  int timeout = 1000*(int)(long)v->Data();
3622  if(timeout < 0)
3623  {
3624  WerrorS("negative timeout"); return TRUE;
3625  }
3626  int t = getRTimer()/TIMER_RESOLUTION; // in seconds
3627  int i;
3628  int ret = -1;
3629  for(int nfinished = 0; nfinished < Lforks->nr+1; nfinished++)
3630  {
3631  i = slStatusSsiL(Lforks, timeout);
3632  if(i > 0) /* Lforks[i] is ready */
3633  {
3634  ret = 1;
3635  Lforks->m[i-1].CleanUp();
3636  Lforks->m[i-1].rtyp=DEF_CMD;
3637  Lforks->m[i-1].data=NULL;
3638  timeout = si_max(0,timeout - 1000*(getRTimer()/TIMER_RESOLUTION - t));
3639  }
3640  else /* terminate the for loop */
3641  {
3642  if(i == -2) /* error */
3643  {
3644  return TRUE;
3645  }
3646  if(i == 0) /* timeout */
3647  {
3648  ret = 0;
3649  }
3650  break;
3651  }
3652  }
3653  Lforks->Clean();
3654  res->data = (void*)(long)ret;
3655  return FALSE;
3656 }
3657 static BOOLEAN jjWEDGE(leftv res, leftv u, leftv v)
3658 {
3659  res->data = (char *)mp_Wedge((matrix)u->Data(),(int)(long)v->Data(),currRing);
3660  return FALSE;
3661 }
3662 #define jjWRONG2 (proc2)jjWRONG
3663 #define jjWRONG3 (proc3)jjWRONG
3665 {
3666  return TRUE;
3667 }
3668 
3669 /*=================== operations with 1 arg.: static proc =================*/
3670 /* must be ordered: first operations for chars (infix ops),
3671  * then alphabetically */
3672 
3673 static BOOLEAN jjDUMMY(leftv res, leftv u)
3674 {
3675  res->data = (char *)u->CopyD();
3676  return FALSE;
3677 }
3679 {
3680  return FALSE;
3681 }
3682 //static BOOLEAN jjPLUSPLUS(leftv res, leftv u)
3683 //{
3684 // res->data = (char *)((int)(long)u->Data()+1);
3685 // return FALSE;
3686 //}
3687 //static BOOLEAN jjMINUSMINUS(leftv res, leftv u)
3688 //{
3689 // res->data = (char *)((int)(long)u->Data()-1);
3690 // return FALSE;
3691 //}
3693 {
3694  if (IDTYP((idhdl)u->data)==INT_CMD)
3695  {
3696  int i=IDINT((idhdl)u->data);
3697  if (iiOp==PLUSPLUS) i++;
3698  else i--;
3699  IDDATA((idhdl)u->data)=(char *)(long)i;
3700  return FALSE;
3701  }
3702  return TRUE;
3703 }
3705 {
3706  number n=(number)u->CopyD(BIGINT_CMD);
3707  n=n_InpNeg(n,coeffs_BIGINT);
3708  res->data = (char *)n;
3709  return FALSE;
3710 }
3712 {
3713  res->data = (char *)(-(long)u->Data());
3714  return FALSE;
3715 }
3717 {
3718  number n=(number)u->CopyD(NUMBER_CMD);
3719  n=nInpNeg(n);
3720  res->data = (char *)n;
3721  return FALSE;
3722 }
3724 {
3725  res->data = (char *)pNeg((poly)u->CopyD(POLY_CMD));
3726  return FALSE;
3727 }
3729 {
3730  poly m1=pISet(-1);
3731  res->data = (char *)mp_MultP((matrix)u->CopyD(MATRIX_CMD),m1,currRing);
3732  return FALSE;
3733 }
3735 {
3736  intvec *iv=(intvec *)u->CopyD(INTVEC_CMD);
3737  (*iv)*=(-1);
3738  res->data = (char *)iv;
3739  return FALSE;
3740 }
3742 {
3743  bigintmat *bim=(bigintmat *)u->CopyD(BIGINTMAT_CMD);
3744  (*bim)*=(-1);
3745  res->data = (char *)bim;
3746  return FALSE;
3747 }
3748 static BOOLEAN jjPROC1(leftv res, leftv u)
3749 {
3750  return jjPROC(res,u,NULL);
3751 }
3753 {
3754  //matrix m=(matrix)v->Data();
3755  //lists l=mpBareiss(m,FALSE);
3756  intvec *iv;
3757  ideal m;
3758  sm_CallBareiss((ideal)v->Data(),0,0,m,&iv, currRing);
3760  l->Init(2);
3761  l->m[0].rtyp=MODUL_CMD;
3762  l->m[1].rtyp=INTVEC_CMD;
3763  l->m[0].data=(void *)m;
3764  l->m[1].data=(void *)iv;
3765  res->data = (char *)l;
3766  return FALSE;
3767 }
3768 //static BOOLEAN jjBAREISS_IM(leftv res, leftv v)
3769 //{
3770 // intvec *m=(intvec *)v->CopyD(INTMAT_CMD);
3771 // ivTriangMat(m);
3772 // res->data = (char *)m;
3773 // return FALSE;
3774 //}
3775 static BOOLEAN jjBI2N(leftv res, leftv u)
3776 {
3777  BOOLEAN bo=FALSE;
3778  number n=(number)u->CopyD();
3780  if (nMap!=NULL)
3781  res->data=nMap(n,coeffs_BIGINT,currRing->cf);
3782  else
3783  {
3784  Werror("cannot convert bigint to cring %s", nCoeffString(currRing->cf));
3785  bo=TRUE;
3786  }
3787  n_Delete(&n,coeffs_BIGINT);
3788  return bo;
3789 }
3790 static BOOLEAN jjBI2IM(leftv res, leftv u)
3791 {
3792  bigintmat *b=(bigintmat*)u->Data();
3793  res->data=(void *)bim2iv(b);
3794  return FALSE;
3795 }
3796 static BOOLEAN jjBI2P(leftv res, leftv u)
3797 {
3798  sleftv tmp;
3799  BOOLEAN bo=jjBI2N(&tmp,u);
3800  if (!bo)
3801  {
3802  number n=(number) tmp.data;
3803  if (nIsZero(n)) { res->data=NULL;nDelete(&n); }
3804  else
3805  {
3806  res->data=(void *)pNSet(n);
3807  }
3808  }
3809  return bo;
3810 }
3812 {
3813  return iiExprArithM(res,u,iiOp);
3814 }
3815 static BOOLEAN jjCHAR(leftv res, leftv v)
3816 {
3817  res->data = (char *)(long)rChar((ring)v->Data());
3818  return FALSE;
3819 }
3820 static BOOLEAN jjCOLS(leftv res, leftv v)
3821 {
3822  res->data = (char *)(long)MATCOLS((matrix)(v->Data()));
3823  return FALSE;
3824 }
3826 {
3827  res->data = (char *)(long)((bigintmat*)(v->Data()))->cols();
3828  return FALSE;
3829 }
3831 {
3832  res->data = (char *)(long)((intvec*)(v->Data()))->cols();
3833  return FALSE;
3834 }
3836 {
3837  // CopyD for POLY_CMD and VECTOR_CMD are identical:
3838  poly p=(poly)v->CopyD(POLY_CMD);
3839  if (p!=NULL) p_Cleardenom(p, currRing);
3840  res->data = (char *)p;
3841  return FALSE;
3842 }
3844 {
3845  res->data = (char *)(long)n_Size((number)v->Data(),coeffs_BIGINT);
3846  return FALSE;
3847 }
3849 {
3850  res->data = (char *)(long)nSize((number)v->Data());
3851  return FALSE;
3852 }
3854 {
3855  lists l=(lists)v->Data();
3856  res->data = (char *)(long)(lSize(l)+1);
3857  return FALSE;
3858 }
3860 {
3861  matrix m=(matrix)v->Data();
3862  res->data = (char *)(long)(MATROWS(m)*MATCOLS(m));
3863  return FALSE;
3864 }
3866 {
3867  res->data = (char *)(long)((intvec*)(v->Data()))->length();
3868  return FALSE;
3869 }
3871 {
3872  ring r=(ring)v->Data();
3873  int elems=-1;
3874  if (rField_is_Zp(r)||rField_is_GF(r)) elems=r->cf->ch;
3875  else if (rField_is_Zp_a(r) && (r->cf->type==n_algExt))
3876  {
3877  extern int ipower ( int b, int n ); /* factory/cf_util */
3878  elems=ipower(r->cf->ch,r->cf->extRing->pFDeg(r->cf->extRing->qideal->m[0],r->cf->extRing));
3879  }
3880  res->data = (char *)(long)elems;
3881  return FALSE;
3882 }
3883 static BOOLEAN jjDEG(leftv res, leftv v)
3884 {
3885  int dummy;
3886  poly p=(poly)v->Data();
3887  if (p!=NULL) res->data = (char *)currRing->pLDeg(p,&dummy,currRing);
3888  else res->data=(char *)-1;
3889  return FALSE;
3890 }
3891 static BOOLEAN jjDEG_M(leftv res, leftv u)
3892 {
3893  ideal I=(ideal)u->Data();
3894  int d=-1;
3895  int dummy;
3896  int i;
3897  for(i=IDELEMS(I)-1;i>=0;i--)
3898  if (I->m[i]!=NULL) d=si_max(d,(int)currRing->pLDeg(I->m[i],&dummy,currRing));
3899  res->data = (char *)(long)d;
3900  return FALSE;
3901 }
3902 static BOOLEAN jjDEGREE(leftv res, leftv v)
3903 {
3904  SPrintStart();
3905 #ifdef HAVE_RINGS
3907  {
3908  ring origR = currRing;
3909  ring tempR = rCopy(origR);
3910  coeffs new_cf=nInitChar(n_Q,NULL);
3911  nKillChar(tempR->cf);
3912  tempR->cf=new_cf;
3913  rComplete(tempR);
3914  ideal vid = (ideal)v->Data();
3915  rChangeCurrRing(tempR);
3916  ideal vv = idrCopyR(vid, origR, currRing);
3917  sleftv vvAsLeftv; memset(&vvAsLeftv, 0, sizeof(vvAsLeftv));
3918  vvAsLeftv.rtyp = IDEAL_CMD;
3919  vvAsLeftv.data = vv; vvAsLeftv.next = NULL;
3920  if (hasFlag(v, FLAG_STD)) setFlag(&vvAsLeftv,FLAG_STD);
3921  assumeStdFlag(&vvAsLeftv);
3922  Print("// NOTE: computation of degree is being performed for\n");
3923  Print("// generic fibre, that is, over Q\n");
3924  intvec *module_w=(intvec*)atGet(&vvAsLeftv,"isHomog",INTVEC_CMD);
3925  scDegree(vv,module_w,currRing->qideal);
3926  idDelete(&vv);
3927  rChangeCurrRing(origR);
3928  rDelete(tempR);
3929  }
3930 #endif
3931  assumeStdFlag(v);
3932  intvec *module_w=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
3933  scDegree((ideal)v->Data(),module_w,currRing->qideal);
3934  char *s=SPrintEnd();
3935  int l=strlen(s)-1;
3936  s[l]='\0';
3937  res->data=(void*)s;
3938  return FALSE;
3939 }
3941 {
3942  if ((v->rtyp==IDHDL)
3943  && ((myynest==IDLEV((idhdl)v->data))||(0==IDLEV((idhdl)v->data))))
3944  {
3945  res->data=(void *)(long)(IDLEV((idhdl)v->data)+1);
3946  }
3947  else if (v->rtyp!=0) res->data=(void *)(-1);
3948  return FALSE;
3949 }
3950 
3951 /// Return the denominator of the input number
3952 /// NOTE: the input number is normalized as a side effect
3954 {
3955  number n = reinterpret_cast<number>(v->Data());
3956  res->data = reinterpret_cast<void*>(n_GetDenom(n, currRing));
3957  return FALSE;
3958 }
3959 
3960 /// Return the numerator of the input number
3961 /// NOTE: the input number is normalized as a side effect
3963 {
3964  number n = reinterpret_cast<number>(v->Data());
3965  res->data = reinterpret_cast<void*>(n_GetNumerator(n, currRing));
3966  return FALSE;
3967 }
3968 
3969 static BOOLEAN jjDET(leftv res, leftv v)
3970 {
3971  matrix m=(matrix)v->Data();
3972  poly p;
3973  if (sm_CheckDet((ideal)m,m->cols(),TRUE, currRing))
3974  {
3976  p=sm_CallDet(I, currRing);
3977  idDelete(&I);
3978  }
3979  else
3980  p=singclap_det(m,currRing);
3981  res ->data = (char *)p;
3982  return FALSE;
3983 }
3984 static BOOLEAN jjDET_BI(leftv res, leftv v)
3985 {
3986  bigintmat * m=(bigintmat*)v->Data();
3987  int i,j;
3988  i=m->rows();j=m->cols();
3989  if(i==j)
3990  res->data = (char *)(long)singclap_det_bi(m,coeffs_BIGINT);
3991  else
3992  {
3993  Werror("det of %d x %d bigintmat",i,j);
3994  return TRUE;
3995  }
3996  return FALSE;
3997 }
3998 static BOOLEAN jjDET_I(leftv res, leftv v)
3999 {
4000  intvec * m=(intvec*)v->Data();
4001  int i,j;
4002  i=m->rows();j=m->cols();
4003  if(i==j)
4004  res->data = (char *)(long)singclap_det_i(m,currRing);
4005  else
4006  {
4007  Werror("det of %d x %d intmat",i,j);
4008  return TRUE;
4009  }
4010  return FALSE;
4011 }
4012 static BOOLEAN jjDET_S(leftv res, leftv v)
4013 {
4014  ideal I=(ideal)v->Data();
4015  poly p;
4016  if (IDELEMS(I)<1) return TRUE;
4017  if (sm_CheckDet(I,IDELEMS(I),FALSE, currRing))
4018  {
4020  p=singclap_det(m,currRing);
4021  idDelete((ideal *)&m);
4022  }
4023  else
4024  p=sm_CallDet(I, currRing);
4025  res->data = (char *)p;
4026  return FALSE;
4027 }
4028 static BOOLEAN jjDIM(leftv res, leftv v)
4029 {
4030  assumeStdFlag(v);
4031 #ifdef HAVE_RINGS
4032  if (rField_is_Ring(currRing))
4033  {
4034  //ring origR = currRing;
4035  //ring tempR = rCopy(origR);
4036  //coeffs new_cf=nInitChar(n_Q,NULL);
4037  //nKillChar(tempR->cf);
4038  //tempR->cf=new_cf;
4039  //rComplete(tempR);
4040  ideal vid = (ideal)v->Data();
4041  int i = idPosConstant(vid);
4042  if ((i != -1) && (n_IsUnit(pGetCoeff(vid->m[i]),currRing->cf)))
4043  { /* ideal v contains unit; dim = -1 */
4044  res->data = (char *)-1;
4045  return FALSE;
4046  }
4047  //rChangeCurrRing(tempR);
4048  //ideal vv = idrCopyR(vid, origR, currRing);
4049  ideal vv = id_Head(vid,currRing);
4050  /* drop degree zero generator from vv (if any) */
4051  if (i != -1) pDelete(&vv->m[i]);
4052  long d = (long)scDimInt(vv, currRing->qideal);
4053  if (rField_is_Ring_Z(currRing) && (i == -1)) d++;
4054  res->data = (char *)d;
4055  idDelete(&vv);
4056  //rChangeCurrRing(origR);
4057  //rDelete(tempR);
4058  return FALSE;
4059  }
4060 #endif
4061  res->data = (char *)(long)scDimInt((ideal)(v->Data()),currRing->qideal);
4062  return FALSE;
4063 }
4065 {
4066  si_link l = (si_link)v->Data();
4067  if (slDump(l))
4068  {
4069  const char *s;
4070  if ((l!=NULL)&&(l->name!=NULL)) s=l->name;
4071  else s=sNoName;
4072  Werror("cannot dump to `%s`",s);
4073  return TRUE;
4074  }
4075  else
4076  return FALSE;
4077 }
4078 static BOOLEAN jjE(leftv res, leftv v)
4079 {
4080  res->data = (char *)pOne();
4081  int co=(int)(long)v->Data();
4082  if (co>0)
4083  {
4084  pSetComp((poly)res->data,co);
4085  pSetm((poly)res->data);
4086  }
4087  else WerrorS("argument of gen must be positive");
4088  return (co<=0);
4089 }
4091 {
4092  char * d = (char *)v->Data();
4093  char * s = (char *)omAlloc(strlen(d) + 13);
4094  strcpy( s, (char *)d);
4095  strcat( s, "\n;RETURN();\n");
4096  newBuffer(s,BT_execute);
4097  return yyparse();
4098 }
4099 static BOOLEAN jjFACSTD(leftv res, leftv v)
4100 {
4102  if (currRing->cf->convSingNFactoryN!=NULL) /* conversion to factory*/
4103  {
4104  ideal_list p,h;
4105  h=kStdfac((ideal)v->Data(),NULL,testHomog,NULL);
4106  if (h==NULL)
4107  {
4108  L->Init(1);
4109  L->m[0].data=(char *)idInit(1);
4110  L->m[0].rtyp=IDEAL_CMD;
4111  }
4112  else
4113  {
4114  p=h;
4115  int l=0;
4116  while (p!=NULL) { p=p->next;l++; }
4117  L->Init(l);
4118  l=0;
4119  while(h!=NULL)
4120  {
4121  L->m[l].data=(char *)h->d;
4122  L->m[l].rtyp=IDEAL_CMD;
4123  p=h->next;
4124  omFreeSize(h,sizeof(*h));
4125  h=p;
4126  l++;
4127  }
4128  }
4129  }
4130  else
4131  {
4132  WarnS("no factorization implemented");
4133  L->Init(1);
4134  iiExprArith1(&(L->m[0]),v,STD_CMD);
4135  }
4136  res->data=(void *)L;
4137  return FALSE;
4138 }
4139 static BOOLEAN jjFAC_P(leftv res, leftv u)
4140 {
4141  intvec *v=NULL;
4142  singclap_factorize_retry=0;
4143  ideal f=singclap_factorize((poly)(u->CopyD()), &v, 0,currRing);
4144  if (f==NULL) return TRUE;
4145  ivTest(v);
4147  l->Init(2);
4148  l->m[0].rtyp=IDEAL_CMD;
4149  l->m[0].data=(void *)f;
4150  l->m[1].rtyp=INTVEC_CMD;
4151  l->m[1].data=(void *)v;
4152  res->data=(void *)l;
4153  return FALSE;
4154 }
4156 {
4157  si_link l = (si_link)v->Data();
4158  if (slGetDump(l))
4159  {
4160  const char *s;
4161  if ((l!=NULL)&&(l->name!=NULL)) s=l->name;
4162  else s=sNoName;
4163  Werror("cannot get dump from `%s`",s);
4164  return TRUE;
4165  }
4166  else
4167  return FALSE;
4168 }
4170 {
4171  assumeStdFlag(v);
4172  ideal I=(ideal)v->Data();
4173  res->data=(void *)iiHighCorner(I,0);
4174  return FALSE;
4175 }
4177 {
4178  assumeStdFlag(v);
4179  intvec *w=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
4180  BOOLEAN delete_w=FALSE;
4181  ideal I=(ideal)v->Data();
4182  int i;
4183  poly p=NULL,po=NULL;
4184  int rk=id_RankFreeModule(I,currRing);
4185  if (w==NULL)
4186  {
4187  w = new intvec(rk);
4188  delete_w=TRUE;
4189  }
4190  for(i=rk;i>0;i--)
4191  {
4192  p=iiHighCorner(I,i);
4193  if (p==NULL)
4194  {
4195  WerrorS("module must be zero-dimensional");
4196  if (delete_w) delete w;
4197  return TRUE;
4198  }
4199  if (po==NULL)
4200  {
4201  po=p;
4202  }
4203  else
4204  {
4205  // now po!=NULL, p!=NULL
4206  int d=(currRing->pFDeg(po,currRing)-(*w)[pGetComp(po)-1] - currRing->pFDeg(p,currRing)+(*w)[i-1]);
4207  if (d==0)
4208  d=pLmCmp(po,p);
4209  if (d > 0)
4210  {
4211  pDelete(&p);
4212  }
4213  else // (d < 0)
4214  {
4215  pDelete(&po); po=p;
4216  }
4217  }
4218  }
4219  if (delete_w) delete w;
4220  res->data=(void *)po;
4221  return FALSE;
4222 }
4224 {
4225 #ifdef HAVE_RINGS
4227  {
4228  ring origR = currRing;
4229  ring tempR = rCopy(origR);
4230  coeffs new_cf=nInitChar(n_Q,NULL);
4231  nKillChar(tempR->cf);
4232  tempR->cf=new_cf;
4233  rComplete(tempR);
4234  ideal vid = (ideal)v->Data();
4235  rChangeCurrRing(tempR);
4236  ideal vv = idrCopyR(vid, origR, currRing);
4237  sleftv vvAsLeftv; memset(&vvAsLeftv, 0, sizeof(vvAsLeftv));
4238  vvAsLeftv.rtyp = IDEAL_CMD;
4239  vvAsLeftv.data = vv; vvAsLeftv.next = NULL;
4240  if (hasFlag(v, FLAG_STD)) setFlag(&vvAsLeftv,FLAG_STD);
4241  assumeStdFlag(&vvAsLeftv);
4242  Print("// NOTE: computation of Hilbert series etc. is being\n");
4243  Print("// performed for generic fibre, that is, over Q\n");
4244  intvec *module_w=(intvec*)atGet(&vvAsLeftv,"isHomog",INTVEC_CMD);
4245  //scHilbertPoly(vv,currRing->qideal);
4246  hLookSeries(vv,module_w,currRing->qideal);
4247  idDelete(&vv);
4248  rChangeCurrRing(origR);
4249  rDelete(tempR);
4250  return FALSE;
4251  }
4252 #endif
4253  assumeStdFlag(v);
4254  intvec *module_w=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
4255  //scHilbertPoly((ideal)v->Data(),currRing->qideal);
4256  hLookSeries((ideal)v->Data(),module_w,currRing->qideal);
4257  return FALSE;
4258 }
4260 {
4261 #ifdef HAVE_RINGS
4263  {
4264  Print("// NOTE: computation of Hilbert series etc. is being\n");
4265  Print("// performed for generic fibre, that is, over Q\n");
4266  }
4267 #endif
4268  res->data=(void *)hSecondSeries((intvec *)v->Data());
4269  return FALSE;
4270 }
4271 static BOOLEAN jjHOMOG1(leftv res, leftv v)
4272 {
4273  intvec *w=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
4274  ideal v_id=(ideal)v->Data();
4275  if (w==NULL)
4276  {
4277  res->data=(void *)(long)idHomModule(v_id,currRing->qideal,&w);
4278  if (res->data!=NULL)
4279  {
4280  if (v->rtyp==IDHDL)
4281  {
4282  char *s_isHomog=omStrDup("isHomog");
4283  if (v->e==NULL)
4284  atSet((idhdl)(v->data),s_isHomog,w,INTVEC_CMD);
4285  else
4286  atSet((idhdl)(v->LData()),s_isHomog,w,INTVEC_CMD);
4287  }
4288  else if (w!=NULL) delete w;
4289  } // if res->data==NULL then w==NULL
4290  }
4291  else
4292  {
4293  res->data=(void *)(long)idTestHomModule(v_id,currRing->qideal,w);
4294  if((res->data==NULL) && (v->rtyp==IDHDL))
4295  {
4296  if (v->e==NULL)
4297  atKill((idhdl)(v->data),"isHomog");
4298  else
4299  atKill((idhdl)(v->LData()),"isHomog");
4300  }
4301  }
4302  return FALSE;
4303 }
4305 {
4306  res->data = (char *)idMaxIdeal((int)(long)v->Data());
4307  setFlag(res,FLAG_STD);
4308  return FALSE;
4309 }
4311 {
4312  matrix mat=(matrix)v->CopyD(MATRIX_CMD);
4313  IDELEMS((ideal)mat)=MATCOLS(mat)*MATROWS(mat);
4314  if (IDELEMS((ideal)mat)==0)
4315  {
4316  idDelete((ideal *)&mat);
4317  mat=(matrix)idInit(1,1);
4318  }
4319  else
4320  {
4321  MATROWS(mat)=1;
4322  mat->rank=1;
4323  idTest((ideal)mat);
4324  }
4325  res->data=(char *)mat;
4326  return FALSE;
4327 }
4329 {
4330  map m=(map)v->CopyD(MAP_CMD);
4331  omFree((ADDRESS)m->preimage);
4332  m->preimage=NULL;
4333  ideal I=(ideal)m;
4334  I->rank=1;
4335  res->data=(char *)I;
4336  return FALSE;
4337 }
4339 {
4340  if (currRing!=NULL)
4341  {
4342  ring q=(ring)v->Data();
4343  if (rSamePolyRep(currRing, q))
4344  {
4345  if (q->qideal==NULL)
4346  res->data=(char *)idInit(1,1);
4347  else
4348  res->data=(char *)idCopy(q->qideal);
4349  return FALSE;
4350  }
4351  }
4352  WerrorS("can only get ideal from identical qring");
4353  return TRUE;
4354 }
4355 static BOOLEAN jjIm2Iv(leftv res, leftv v)
4356 {
4357  intvec *iv = (intvec *)v->CopyD(INTMAT_CMD);
4358  iv->makeVector();
4359  res->data = iv;
4360  return FALSE;
4361 }
4362 static BOOLEAN jjIMPART(leftv res, leftv v)
4363 {
4364  res->data = (char *)n_ImPart((number)v->Data(),currRing->cf);
4365  return FALSE;
4366 }
4368 {
4369  assumeStdFlag(v);
4370  res->data=(void *)scIndIntvec((ideal)(v->Data()),currRing->qideal);
4371  return FALSE;
4372 }
4374 {
4375  ideal result=kInterRed((ideal)(v->Data()), currRing->qideal);
4376  #ifdef HAVE_RINGS
4378  Warn("interred: this command is experimental over the integers");
4379  #endif
4380  if (TEST_OPT_PROT) { PrintLn(); mflush(); }
4381  res->data = result;
4382  return FALSE;
4383 }
4385 {
4386  res->data = (char *)(long)pVar((poly)v->Data());
4387  return FALSE;
4388 }
4390 {
4391  res->data = (char *)(long)(r_IsRingVar((char *)v->Data(), currRing->names,
4392  currRing->N)+1);
4393  return FALSE;
4394 }
4396 {
4397  res->data = (char *)0;
4398  return FALSE;
4399 }
4401 {
4402  ideal i=idInit(currRing->N,1);
4403  int k;
4404  poly p=(poly)(v->Data());
4405  for (k=currRing->N;k>0;k--)
4406  {
4407  i->m[k-1]=pDiff(p,k);
4408  }
4409  res->data = (char *)i;
4410  return FALSE;
4411 }
4413 {
4414  if (!nCoeff_is_transExt(currRing->cf))
4415  {
4416  WerrorS("differentiation not defined in the coefficient ring");
4417  return TRUE;
4418  }
4419  number n = (number) u->Data();
4420  number k = (number) v->Data();
4421  res->data = ntDiff(n,k,currRing->cf);
4422  return FALSE;
4423 }
4424 /*2
4425  * compute Jacobi matrix of a module/matrix
4426  * Jacobi(M) := ( diff(Mt,var(1))|, ... ,| diff(Mt,var(currRing->N)) ),
4427  * where Mt := transpose(M)
4428  * Note that this is consistent with the current conventions for jacob in Singular,
4429  * whereas M2 computes its transposed.
4430  */
4432 {
4433  ideal id = (ideal)a->Data();
4434  id = idTransp(id);
4435  int W = IDELEMS(id);
4436 
4437  ideal result = idInit(W * currRing->N, id->rank);
4438  poly *p = result->m;
4439 
4440  for( int v = 1; v <= currRing->N; v++ )
4441  {
4442  poly* q = id->m;
4443  for( int i = 0; i < W; i++, p++, q++ )
4444  *p = pDiff( *q, v );
4445  }
4446  idDelete(&id);
4447 
4448  res->data = (char *)result;
4449  return FALSE;
4450 }
4451 
4452 
4453 static BOOLEAN jjKBASE(leftv res, leftv v)
4454 {
4455  assumeStdFlag(v);
4456  res->data = (char *)scKBase(-1,(ideal)(v->Data()),currRing->qideal);
4457  return FALSE;
4458 }
4459 static BOOLEAN jjL2R(leftv res, leftv v)
4460 {
4461  res->data=(char *)syConvList((lists)v->Data(),FALSE);
4462  if (res->data != NULL)
4463  return FALSE;
4464  else
4465  return TRUE;
4466 }
4468 {
4469  poly p=(poly)v->Data();
4470  if (p==NULL)
4471  {
4472  res->data=(char *)nInit(0);
4473  }
4474  else
4475  {
4476  res->data=(char *)nCopy(pGetCoeff(p));
4477  }
4478  return FALSE;
4479 }
4481 {
4482  poly p=(poly)v->Data();
4483  int s=currRing->N;
4484  if (v->Typ()==VECTOR_CMD) s++;
4485  intvec *iv=new intvec(s);
4486  if (p!=NULL)
4487  {
4488  for(int i = currRing->N;i;i--)
4489  {
4490  (*iv)[i-1]=pGetExp(p,i);
4491  }
4492  if (s!=currRing->N)
4493  (*iv)[currRing->N]=pGetComp(p);
4494  }
4495  res->data=(char *)iv;
4496  return FALSE;
4497 }
4499 {
4500  poly p=(poly)v->Data();
4501  if (p == NULL)
4502  {
4503  res->data = (char*) NULL;
4504  }
4505  else
4506  {
4507  poly lm = pLmInit(p);
4508  pSetCoeff(lm, nInit(1));
4509  res->data = (char*) lm;
4510  }
4511  return FALSE;
4512 }
4513 static BOOLEAN jjLOAD1(leftv /*res*/, leftv v)
4514 {
4515  return jjLOAD((char*)v->Data(),FALSE);
4516 }
4518 {
4519  ring r=rCompose((lists)v->Data());
4520  if (r==NULL) return TRUE;
4521  if (r->qideal!=NULL) res->rtyp=QRING_CMD;
4522  res->data=(char *)r;
4523  return FALSE;
4524 }
4525 static BOOLEAN jjPFAC1(leftv res, leftv v)
4526 {
4527  /* call method jjPFAC2 with second argument = 0 (meaning that no
4528  valid bound for the prime factors has been given) */
4529  sleftv tmp;
4530  memset(&tmp, 0, sizeof(tmp));
4531  tmp.rtyp = INT_CMD;
4532  return jjPFAC2(res, v, &tmp);
4533 }
4535 {
4536  /* computes the LU-decomposition of a matrix M;
4537  i.e., M = P * L * U, where
4538  - P is a row permutation matrix,
4539  - L is in lower triangular form,
4540  - U is in upper row echelon form
4541  Then, we also have P * M = L * U.
4542  A list [P, L, U] is returned. */
4543  matrix mat = (const matrix)v->Data();
4544  if (!idIsConstant((ideal)mat))
4545  {
4546  WerrorS("matrix must be constant");
4547  return TRUE;
4548  }
4549  matrix pMat;
4550  matrix lMat;
4551  matrix uMat;
4552 
4553  luDecomp(mat, pMat, lMat, uMat);
4554 
4556  ll->Init(3);
4557  ll->m[0].rtyp=MATRIX_CMD; ll->m[0].data=(void *)pMat;
4558  ll->m[1].rtyp=MATRIX_CMD; ll->m[1].data=(void *)lMat;
4559  ll->m[2].rtyp=MATRIX_CMD; ll->m[2].data=(void *)uMat;
4560  res->data=(char*)ll;
4561 
4562  return FALSE;
4563 }
4564 static BOOLEAN jjMEMORY(leftv res, leftv v)
4565 {
4566  omUpdateInfo();
4567  switch(((int)(long)v->Data()))
4568  {
4569  case 0:
4570  res->data=(char *)n_Init(om_Info.UsedBytes,coeffs_BIGINT);
4571  break;
4572  case 1:
4573  res->data = (char *)n_Init(om_Info.CurrentBytesSystem,coeffs_BIGINT);
4574  break;
4575  case 2:
4576  res->data = (char *)n_Init(om_Info.MaxBytesSystem,coeffs_BIGINT);
4577  break;
4578  default:
4579  omPrintStats(stdout);
4580  omPrintInfo(stdout);
4581  omPrintBinStats(stdout);
4582  res->data = (char *)0;
4583  res->rtyp = NONE;
4584  }
4585  return FALSE;
4586  res->data = (char *)0;
4587  return FALSE;
4588 }
4589 //static BOOLEAN jjMONITOR1(leftv res, leftv v)
4590 //{
4591 // return jjMONITOR2(res,v,NULL);
4592 //}
4593 static BOOLEAN jjMSTD(leftv res, leftv v)
4594 {
4595  int t=v->Typ();
4596  ideal r,m;
4597  r=kMin_std((ideal)v->Data(),currRing->qideal,testHomog,NULL,m);
4599  l->Init(2);
4600  l->m[0].rtyp=t;
4601  l->m[0].data=(char *)r;
4602  setFlag(&(l->m[0]),FLAG_STD);
4603  l->m[1].rtyp=t;
4604  l->m[1].data=(char *)m;
4605  res->data=(char *)l;
4606  return FALSE;
4607 }
4608 static BOOLEAN jjMULT(leftv res, leftv v)
4609 {
4610  assumeStdFlag(v);
4611  res->data = (char *)(long)scMultInt((ideal)(v->Data()),currRing->qideal);
4612  return FALSE;
4613 }
4615 {
4616  intvec *weights=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
4617 
4618  syStrategy tmp=(syStrategy)v->Data();
4619  tmp = syMinimize(tmp); // enrich itself!
4620 
4621  res->data=(char *)tmp;
4622 
4623  if (weights!=NULL)
4624  atSet(res, omStrDup("isHomog"),ivCopy(weights),INTVEC_CMD);
4625 
4626  return FALSE;
4627 }
4628 static BOOLEAN jjN2BI(leftv res, leftv v)
4629 {
4630  number n,i; i=(number)v->Data();
4632  if (nMap!=NULL)
4633  n=nMap(i,currRing->cf,coeffs_BIGINT);
4634  else goto err;
4635  res->data=(void *)n;
4636  return FALSE;
4637 err:
4638  WerrorS("cannot convert to bigint"); return TRUE;
4639 }
4640 static BOOLEAN jjNAMEOF(leftv res, leftv v)
4641 {
4642  res->data = (char *)v->name;
4643  if (res->data==NULL) res->data=omStrDup("");
4644  v->name=NULL;
4645  return FALSE;
4646 }
4647 static BOOLEAN jjNAMES(leftv res, leftv v)
4648 {
4649  res->data=ipNameList(((ring)v->Data())->idroot);
4650  return FALSE;
4651 }
4653 {
4654  res->data=ipNameListLev((IDROOT),(int)(long)v->Data());
4655  return FALSE;
4656 }
4657 static BOOLEAN jjNOT(leftv res, leftv v)
4658 {
4659  res->data=(char*)(long)((long)v->Data()==0 ? 1 : 0);
4660  return FALSE;
4661 }
4662 static BOOLEAN jjNVARS(leftv res, leftv v)
4663 {
4664  res->data = (char *)(long)(((ring)(v->Data()))->N);
4665  return FALSE;
4666 }
4668 {
4669  si_link l=(si_link)v->Data();
4670  if (iiOp==OPEN_CMD) return slOpen(l, SI_LINK_OPEN,v);
4671  else return slClose(l);
4672 }
4673 static BOOLEAN jjORD(leftv res, leftv v)
4674 {
4675  poly p=(poly)v->Data();
4676  res->data=(char *)( p==NULL ? -1 : currRing->pFDeg(p,currRing) );
4677  return FALSE;
4678 }
4679 static BOOLEAN jjPAR1(leftv res, leftv v)
4680 {
4681  int i=(int)(long)v->Data();
4682  int p=0;
4683  p=rPar(currRing);
4684  if ((0<i) && (i<=p))
4685  {
4686  res->data=(char *)n_Param(i,currRing);
4687  }
4688  else
4689  {
4690  Werror("par number %d out of range 1..%d",i,p);
4691  return TRUE;
4692  }
4693  return FALSE;
4694 }
4695 static BOOLEAN jjPARDEG(leftv res, leftv v)
4696 {
4697  number nn=(number)v->Data();
4698  res->data = (char *)(long)n_ParDeg(nn, currRing);
4699  return FALSE;
4700 }
4702 {
4703  if (currRing==NULL)
4704  {
4705  WerrorS("no ring active");
4706  return TRUE;
4707  }
4708  int i=(int)(long)v->Data();
4709  int p=0;
4710  if ((0<i) && (rParameter(currRing)!=NULL) && (i<=(p=rPar(currRing))))
4711  res->data=omStrDup(rParameter(currRing)[i-1]);
4712  else
4713  {
4714  Werror("par number %d out of range 1..%d",i,p);
4715  return TRUE;
4716  }
4717  return FALSE;
4718 }
4719 static BOOLEAN jjP2BI(leftv res, leftv v)
4720 {
4721  poly p=(poly)v->Data();
4722  if (p==NULL) { res->data=(char *)n_Init(0,coeffs_BIGINT); return FALSE; }
4723  if ((pNext(p)!=NULL)|| (!pIsConstant(p)))
4724  {
4725  WerrorS("poly must be constant");
4726  return TRUE;
4727  }
4728  number i=pGetCoeff(p);
4729  number n;
4731  if (nMap!=NULL)
4732  n=nMap(i,currRing->cf,coeffs_BIGINT);
4733  else goto err;
4734  res->data=(void *)n;
4735  return FALSE;
4736 err:
4737  WerrorS("cannot convert to bigint"); return TRUE;
4738 }
4739 static BOOLEAN jjP2I(leftv res, leftv v)
4740 {
4741  poly p=(poly)v->Data();
4742  if (p==NULL) { /*res->data=(char *)0;*/ return FALSE; }
4743  if ((pNext(p)!=NULL)|| (!pIsConstant(p)))
4744  {
4745  WerrorS("poly must be constant");
4746  return TRUE;
4747  }
4748  res->data = (char *)(long)iin_Int(pGetCoeff(p),currRing->cf);
4749  return FALSE;
4750 }
4752 {
4753  map mapping=(map)v->Data();
4754  syMake(res,omStrDup(mapping->preimage));
4755  return FALSE;
4756 }
4757 static BOOLEAN jjPRIME(leftv res, leftv v)
4758 {
4759  int i = IsPrime((int)(long)(v->Data()));
4760  res->data = (char *)(long)(i > 1 ? i : 2);
4761  return FALSE;
4762 }
4763 static BOOLEAN jjPRUNE(leftv res, leftv v)
4764 {
4765  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4766  ideal v_id=(ideal)v->Data();
4767  if (w!=NULL)
4768  {
4769  if (!idTestHomModule(v_id,currRing->qideal,w))
4770  {
4771  WarnS("wrong weights");
4772  w=NULL;
4773  // and continue at the non-homog case below
4774  }
4775  else
4776  {
4777  w=ivCopy(w);
4778  intvec **ww=&w;
4779  res->data = (char *)idMinEmbedding(v_id,FALSE,ww);
4780  atSet(res,omStrDup("isHomog"),*ww,INTVEC_CMD);
4781  return FALSE;
4782  }
4783  }
4784  res->data = (char *)idMinEmbedding(v_id);
4785  return FALSE;
4786 }
4787 static BOOLEAN jjP2N(leftv res, leftv v)
4788 {
4789  number n;
4790  poly p;
4791  if (((p=(poly)v->Data())!=NULL)
4792  && (pIsConstant(p)))
4793  {
4794  n=nCopy(pGetCoeff(p));
4795  }
4796  else
4797  {
4798  n=nInit(0);
4799  }
4800  res->data = (char *)n;
4801  return FALSE;
4802 }
4804 {
4805  char *s= (char *)v->Data();
4806  int i = 1;
4807  for(i=0; i<sArithBase.nCmdUsed; i++)
4808  {
4809  //Print("test %d, >>%s<<, tab:>>%s<<\n",i,s,sArithBase.sCmds[i].name);
4810  if (strcmp(s, sArithBase.sCmds[i].name) == 0)
4811  {
4812  res->data = (char *)1;
4813  return FALSE;
4814  }
4815  }
4816  //res->data = (char *)0;
4817  return FALSE;
4818 }
4819 static BOOLEAN jjRANK1(leftv res, leftv v)
4820 {
4821  matrix m =(matrix)v->Data();
4822  int rank = luRank(m, 0);
4823  res->data =(char *)(long)rank;
4824  return FALSE;
4825 }
4826 static BOOLEAN jjREAD(leftv res, leftv v)
4827 {
4828  return jjREAD2(res,v,NULL);
4829 }
4831 {
4832  res->data = (char *)(long)iiRegularity((lists)v->Data());
4833  return FALSE;
4834 }
4835 static BOOLEAN jjREPART(leftv res, leftv v)
4836 {
4837  res->data = (char *)n_RePart((number)v->Data(),currRing->cf);
4838  return FALSE;
4839 }
4841 {
4842  ring r=(ring)v->Data();
4843  if (r!=NULL)
4844  res->data = (char *)rDecompose((ring)v->Data());
4845  return (r==NULL)||(res->data==NULL);
4846 }
4847 static BOOLEAN jjROWS(leftv res, leftv v)
4848 {
4849  ideal i = (ideal)v->Data();
4850  res->data = (char *)i->rank;
4851  return FALSE;
4852 }
4854 {
4855  res->data = (char *)(long)((bigintmat*)(v->Data()))->rows();
4856  return FALSE;
4857 }
4859 {
4860  res->data = (char *)(long)((intvec*)(v->Data()))->rows();
4861  return FALSE;
4862 }
4863 static BOOLEAN jjRPAR(leftv res, leftv v)
4864 {
4865  res->data = (char *)(long)rPar(((ring)v->Data()));
4866  return FALSE;
4867 }
4869 {
4870 #ifdef HAVE_PLURAL
4871  const bool bIsSCA = rIsSCA(currRing);
4872 #else
4873  const bool bIsSCA = false;
4874 #endif
4875 
4876  if ((currRing->qideal!=NULL) && !bIsSCA)
4877  {
4878  WerrorS("qring not supported by slimgb at the moment");
4879  return TRUE;
4880  }
4882  {
4883  WerrorS("ordering must be global for slimgb");
4884  return TRUE;
4885  }
4886  intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
4887  // tHomog hom=testHomog;
4888  ideal u_id=(ideal)u->Data();
4889  if (w!=NULL)
4890  {
4891  if (!idTestHomModule(u_id,currRing->qideal,w))
4892  {
4893  WarnS("wrong weights");
4894  w=NULL;
4895  }
4896  else
4897  {
4898  w=ivCopy(w);
4899  // hom=isHomog;
4900  }
4901  }
4902 
4903  assume(u_id->rank>=id_RankFreeModule(u_id, currRing));
4904  res->data=(char *)t_rep_gb(currRing,
4905  u_id,u_id->rank);
4906  //res->data=(char *)t_rep_gb(currRing, u_id);
4907 
4909  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
4910  return FALSE;
4911 }
4912 static BOOLEAN jjSBA(leftv res, leftv v)
4913 {
4914  ideal result;
4915  ideal v_id=(ideal)v->Data();
4916  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4917  tHomog hom=testHomog;
4918  if (w!=NULL)
4919  {
4920  if (!idTestHomModule(v_id,currRing->qideal,w))
4921  {
4922  WarnS("wrong weights");
4923  w=NULL;
4924  }
4925  else
4926  {
4927  hom=isHomog;
4928  w=ivCopy(w);
4929  }
4930  }
4931  result=kSba(v_id,currRing->qideal,hom,&w,1,0);
4932  idSkipZeroes(result);
4933  res->data = (char *)result;
4935  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
4936  return FALSE;
4937 }
4938 static BOOLEAN jjSBA_1(leftv res, leftv v, leftv u)
4939 {
4940  ideal result;
4941  ideal v_id=(ideal)v->Data();
4942  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4943  tHomog hom=testHomog;
4944  if (w!=NULL)
4945  {
4946  if (!idTestHomModule(v_id,currRing->qideal,w))
4947  {
4948  WarnS("wrong weights");
4949  w=NULL;
4950  }
4951  else
4952  {
4953  hom=isHomog;
4954  w=ivCopy(w);
4955  }
4956  }
4957  result=kSba(v_id,currRing->qideal,hom,&w,(int)(long)u->Data(),0);
4958  idSkipZeroes(result);
4959  res->data = (char *)result;
4961  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
4962  return FALSE;
4963 }
4964 static BOOLEAN jjSBA_2(leftv res, leftv v, leftv u, leftv t)
4965 {
4966  ideal result;
4967  ideal v_id=(ideal)v->Data();
4968  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4969  tHomog hom=testHomog;
4970  if (w!=NULL)
4971  {
4972  if (!idTestHomModule(v_id,currRing->qideal,w))
4973  {
4974  WarnS("wrong weights");
4975  w=NULL;
4976  }
4977  else
4978  {
4979  hom=isHomog;
4980  w=ivCopy(w);
4981  }
4982  }
4983  result=kSba(v_id,currRing->qideal,hom,&w,(int)(long)u->Data(),(int)(long)t->Data());
4984  idSkipZeroes(result);
4985  res->data = (char *)result;
4987  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
4988  return FALSE;
4989 }
4990 static BOOLEAN jjSTD(leftv res, leftv v)
4991 {
4992  ideal result;
4993  ideal v_id=(ideal)v->Data();
4994  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4995  tHomog hom=testHomog;
4996  if (w!=NULL)
4997  {
4998  if (!idTestHomModule(v_id,currRing->qideal,w))
4999  {
5000  WarnS("wrong weights");
5001  w=NULL;
5002  }
5003  else
5004  {
5005  hom=isHomog;
5006  w=ivCopy(w);
5007  }
5008  }
5009  result=kStd(v_id,currRing->qideal,hom,&w);
5010  idSkipZeroes(result);
5011  res->data = (char *)result;
5013  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
5014  return FALSE;
5015 }
5017 {
5018  res->data = (char *)idSort((ideal)v->Data());
5019  return FALSE;
5020 }
5022 {
5023  singclap_factorize_retry=0;
5024  intvec *v=NULL;
5025  ideal f=singclap_sqrfree((poly)(u->CopyD()), &v, 0, currRing);
5026  if (f==NULL) return TRUE;
5027  ivTest(v);
5029  l->Init(2);
5030  l->m[0].rtyp=IDEAL_CMD;
5031  l->m[0].data=(void *)f;
5032  l->m[1].rtyp=INTVEC_CMD;
5033  l->m[1].data=(void *)v;
5034  res->data=(void *)l;
5035  return FALSE;
5036 }
5037 #if 1
5038 static BOOLEAN jjSYZYGY(leftv res, leftv v)
5039 {
5040  intvec *w=NULL;
5041  res->data = (char *)idSyzygies((ideal)v->Data(),testHomog,&w);
5042  if (w!=NULL) delete w;
5044  return FALSE;
5045 }
5046 #else
5047 // activate, if idSyz handle module weights correctly !
5048 static BOOLEAN jjSYZYGY(leftv res, leftv v)
5049 {
5050  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
5051  ideal v_id=(ideal)v->Data();
5052  tHomog hom=testHomog;
5053  int add_row_shift=0;
5054  if (w!=NULL)
5055  {
5056  w=ivCopy(w);
5057  add_row_shift=w->min_in();
5058  (*w)-=add_row_shift;
5059  if (idTestHomModule(v_id,currRing->qideal,w))
5060  hom=isHomog;
5061  else
5062  {
5063  //WarnS("wrong weights");
5064  delete w; w=NULL;
5065  hom=testHomog;
5066  }
5067  }
5068  res->data = (char *)idSyzygies(v_id,hom,&w);
5069  if (w!=NULL)
5070  {
5071  atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
5072  }
5073  return FALSE;
5074 }
5075 #endif
5077 {
5078  res->data = (char *)(long)ivTrace((intvec*)(v->Data()));
5079  return FALSE;
5080 }
5082 {
5083  res->data = (char *)(((bigintmat*)(v->Data()))->transpose());
5084  return FALSE;
5085 }
5087 {
5088  res->data = (char *)ivTranp((intvec*)(v->Data()));
5089  return FALSE;
5090 }
5091 #ifdef HAVE_PLURAL
5093 {
5094  ring r = (ring)a->Data();
5095  //if (rIsPluralRing(r))
5096  if (r->OrdSgn==1)
5097  {
5098  res->data = rOpposite(r);
5099  }
5100  else
5101  {
5102  WarnS("opposite only for global orderings");
5103  res->data = rCopy(r);
5104  }
5105  return FALSE;
5106 }
5108 {
5109  ring r = (ring)a->Data();
5110  if (rIsPluralRing(r))
5111  {
5112  // ideal i;
5113 // if (a->rtyp == QRING_CMD)
5114 // {
5115 // i = r->qideal;
5116 // r->qideal = NULL;
5117 // }
5118  ring s = rEnvelope(r);
5119 // if (a->rtyp == QRING_CMD)
5120 // {
5121 // ideal is = idOppose(r,i); /* twostd? */
5122 // is = idAdd(is,i);
5123 // s->qideal = i;
5124 // }
5125  res->data = s;
5126  }
5127  else res->data = rCopy(r);
5128  return FALSE;
5129 }
5131 {
5132  if (rIsPluralRing(currRing)) res->data=(ideal)twostd((ideal)a->Data());
5133  else res->data=(ideal)a->CopyD();
5134  setFlag(res,FLAG_STD);
5135  setFlag(res,FLAG_TWOSTD);
5136  return FALSE;
5137 }
5138 #endif
5139 
5140 static BOOLEAN jjTYPEOF(leftv res, leftv v)
5141 {
5142  int t=(int)(long)v->data;
5143  switch (t)
5144  {
5145  case CRING_CMD:
5146  case INT_CMD:
5147  case POLY_CMD:
5148  case VECTOR_CMD:
5149  case STRING_CMD:
5150  case INTVEC_CMD:
5151  case IDEAL_CMD:
5152  case MATRIX_CMD:
5153  case MODUL_CMD:
5154  case MAP_CMD:
5155  case PROC_CMD:
5156  case RING_CMD:
5157  case QRING_CMD:
5158  case INTMAT_CMD:
5159  case BIGINTMAT_CMD:
5160  case NUMBER_CMD:
5161  #ifdef SINGULAR_4_1
5162  case CNUMBER_CMD:
5163  #endif
5164  case BIGINT_CMD:
5165  case LIST_CMD:
5166  case PACKAGE_CMD:
5167  case LINK_CMD:
5168  case RESOLUTION_CMD:
5169  res->data=omStrDup(Tok2Cmdname(t)); break;
5170  case DEF_CMD:
5171  case NONE: res->data=omStrDup("none"); break;
5172  default:
5173  {
5174  if (t>MAX_TOK)
5175  res->data=omStrDup(getBlackboxName(t));
5176  else
5177  res->data=omStrDup("?unknown type?");
5178  break;
5179  }
5180  }
5181  return FALSE;
5182 }
5184 {
5185  res->data=(char *)(long)pIsUnivariate((poly)v->Data());
5186  return FALSE;
5187 }
5188 static BOOLEAN jjVAR1(leftv res, leftv v)
5189 {
5190  int i=(int)(long)v->Data();
5191  if ((0<i) && (i<=currRing->N))
5192  {
5193  poly p=pOne();
5194  pSetExp(p,i,1);
5195  pSetm(p);
5196  res->data=(char *)p;
5197  }
5198  else
5199  {
5200  Werror("var number %d out of range 1..%d",i,currRing->N);
5201  return TRUE;
5202  }
5203  return FALSE;
5204 }
5206 {
5207  if (currRing==NULL)
5208  {
5209  WerrorS("no ring active");
5210  return TRUE;
5211  }
5212  int i=(int)(long)v->Data();
5213  if ((0<i) && (i<=currRing->N))
5214  res->data=omStrDup(currRing->names[i-1]);
5215  else
5216  {
5217  Werror("var number %d out of range 1..%d",i,currRing->N);
5218  return TRUE;
5219  }
5220  return FALSE;
5221 }
5222 static BOOLEAN jjVDIM(leftv res, leftv v)
5223 {
5224  assumeStdFlag(v);
5225  res->data = (char *)(long)scMult0Int((ideal)v->Data(),currRing->qideal);
5226  return FALSE;
5227 }
5229 {
5230 // input: u: a list with links of type
5231 // ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch
5232 // returns: -1: the read state of all links is eof
5233 // i>0: (at least) u[i] is ready
5234  lists Lforks = (lists)u->Data();
5235  int i = slStatusSsiL(Lforks, -1);
5236  if(i == -2) /* error */
5237  {
5238  return TRUE;
5239  }
5240  res->data = (void*)(long)i;
5241  return FALSE;
5242 }
5244 {
5245 // input: u: a list with links of type
5246 // ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch
5247 // returns: -1: the read state of all links is eof
5248 // 1: all links are ready
5249 // (caution: at least one is ready, but some maybe dead)
5250  lists Lforks = (lists)u->CopyD();
5251  int i;
5252  int j = -1;
5253  for(int nfinished = 0; nfinished < Lforks->nr+1; nfinished++)
5254  {
5255  i = slStatusSsiL(Lforks, -1);
5256  if(i == -2) /* error */
5257  {
5258  return TRUE;
5259  }
5260  if(i == -1)
5261  {
5262  break;
5263  }
5264  j = 1;
5265  Lforks->m[i-1].CleanUp();
5266  Lforks->m[i-1].rtyp=DEF_CMD;
5267  Lforks->m[i-1].data=NULL;
5268  }
5269  res->data = (void*)(long)j;
5270  Lforks->Clean();
5271  return FALSE;
5272 }
5273 
5274 BOOLEAN jjLOAD(const char *s, BOOLEAN autoexport)
5275 {
5276  char libnamebuf[256];
5277  lib_types LT = type_of_LIB(s, libnamebuf);
5278 
5279 #ifdef HAVE_DYNAMIC_LOADING
5280  extern BOOLEAN load_modules(const char *newlib, char *fullpath, BOOLEAN autoexport);
5281 #endif /* HAVE_DYNAMIC_LOADING */
5282  switch(LT)
5283  {
5284  default:
5285  case LT_NONE:
5286  Werror("%s: unknown type", s);
5287  break;
5288  case LT_NOTFOUND:
5289  Werror("cannot open %s", s);
5290  break;
5291 
5292  case LT_SINGULAR:
5293  {
5294  char *plib = iiConvName(s);
5295  idhdl pl = IDROOT->get(plib,0);
5296  if (pl==NULL)
5297  {
5298  pl = enterid( plib,0, PACKAGE_CMD, &(basePack->idroot), TRUE );
5299  IDPACKAGE(pl)->language = LANG_SINGULAR;
5300  IDPACKAGE(pl)->libname=omStrDup(plib);
5301  }
5302  else if (IDTYP(pl)!=PACKAGE_CMD)
5303  {
5304  Werror("can not create package `%s`",plib);
5305  omFree(plib);
5306  return TRUE;
5307  }
5308  package savepack=currPack;
5309  currPack=IDPACKAGE(pl);
5310  IDPACKAGE(pl)->loaded=TRUE;
5311  char libnamebuf[256];
5312  FILE * fp = feFopen( s, "r", libnamebuf, TRUE );
5313  BOOLEAN bo=iiLoadLIB(fp, libnamebuf, s, pl, autoexport, TRUE);
5314  currPack=savepack;
5315  IDPACKAGE(pl)->loaded=(!bo);
5316  return bo;
5317  }
5318  case LT_BUILTIN:
5319  SModulFunc_t iiGetBuiltinModInit(const char*);
5320  return load_builtin(s,autoexport, iiGetBuiltinModInit(s));
5321  case LT_MACH_O:
5322  case LT_ELF:
5323  case LT_HPUX:
5324 #ifdef HAVE_DYNAMIC_LOADING
5325  return load_modules(s, libnamebuf, autoexport);
5326 #else /* HAVE_DYNAMIC_LOADING */
5327  WerrorS("Dynamic modules are not supported by this version of Singular");
5328  break;
5329 #endif /* HAVE_DYNAMIC_LOADING */
5330  }
5331  return TRUE;
5332 }
5333 static int WerrorS_dummy_cnt=0;
5334 static void WerrorS_dummy(const char *)
5335 {
5336  WerrorS_dummy_cnt++;
5337 }
5338 BOOLEAN jjLOAD_TRY(const char *s)
5339 {
5340  void (*WerrorS_save)(const char *s) = WerrorS_callback;
5342  WerrorS_dummy_cnt=0;
5343  BOOLEAN bo=jjLOAD(s,TRUE);
5344  if (TEST_OPT_PROT && (bo || (WerrorS_dummy_cnt>0)))
5345  Print("loading of >%s< failed\n",s);
5346  WerrorS_callback=WerrorS_save;
5347  errorreported=0;
5348  return FALSE;
5349 }
5350 
5351 static BOOLEAN jjstrlen(leftv res, leftv v)
5352 {
5353  res->data = (char *)strlen((char *)v->Data());
5354  return FALSE;
5355 }
5357 {
5358  res->data = (char *)(long)pLength((poly)v->Data());
5359  return FALSE;
5360 }
5361 static BOOLEAN jjidElem(leftv res, leftv v)
5362 {
5363  res->data = (char *)(long)idElem((ideal)v->Data());
5364  return FALSE;
5365 }
5367 {
5368  res->data = (char *)id_FreeModule((int)(long)v->Data(), currRing);
5369  return FALSE;
5370 }
5372 {
5373  res->data = (char *)id_Vec2Ideal((poly)v->Data(), currRing);
5374  return FALSE;
5375 }
5377 {
5378 #ifdef SINGULAR_4_1
5379  iiReWrite("charstr");
5380 #endif
5381  res->data = rCharStr((ring)v->Data());
5382  return FALSE;
5383 }
5384 static BOOLEAN jjpHead(leftv res, leftv v)
5385 {
5386  res->data = (char *)pHead((poly)v->Data());
5387  return FALSE;
5388 }
5389 static BOOLEAN jjidHead(leftv res, leftv v)
5390 {
5391  res->data = (char *)id_Head((ideal)v->Data(),currRing);
5392  setFlag(res,FLAG_STD);
5393  return FALSE;
5394 }
5396 {
5397  res->data = (char *)idMinBase((ideal)v->Data());
5398  return FALSE;
5399 }
5401 {
5402  res->data = (char *)syMinBase((ideal)v->Data());
5403  return FALSE;
5404 }
5406 {
5407  res->data = (char *)pMaxComp((poly)v->Data());
5408  return FALSE;
5409 }
5411 {
5412  res->data = (char *)mp_Trace((matrix)v->Data(),currRing);
5413  return FALSE;
5414 }
5416 {
5417  res->data = (char *)mp_Transp((matrix)v->Data(),currRing);
5418  return FALSE;
5419 }
5421 {
5422 #ifdef SINGULAR_4_1
5423  iiReWrite("ordstr");
5424 #endif
5425  res->data = rOrdStr((ring)v->Data());
5426  return FALSE;
5427 }
5429 {
5430 #ifdef SINGULAR_4_1
5431  iiReWrite("varstr");
5432 #endif
5433  res->data = rVarStr((ring)v->Data());
5434  return FALSE;
5435 }
5437 {
5438 #ifdef SINGULAR_4_1
5439  iiReWrite("varstr");
5440 #endif
5441  res->data = rParStr((ring)v->Data());
5442  return FALSE;
5443 }
5445 {
5446  res->data=(char *)(long)sySize((syStrategy)v->Data());
5447  return FALSE;
5448 }
5449 static BOOLEAN jjDIM_R(leftv res, leftv v)
5450 {
5451  res->data = (char *)(long)syDim((syStrategy)v->Data());
5452  return FALSE;
5453 }
5455 {
5456  res->data = (char *)idTransp((ideal)v->Data());
5457  return FALSE;
5458 }
5459 static BOOLEAN jjnInt(leftv res, leftv u)
5460 {
5461  number n=(number)u->CopyD(); // n_Int may call n_Normalize
5462  res->data=(char *)(long)iin_Int(n,currRing->cf);
5463  n_Delete(&n,currRing->cf);
5464  return FALSE;
5465 }
5466 static BOOLEAN jjnlInt(leftv res, leftv u)
5467 {
5468  number n=(number)u->Data();
5469  res->data=(char *)(long)iin_Int(n,coeffs_BIGINT );
5470  return FALSE;
5471 }
5472 /*=================== operations with 3 args.: static proc =================*/
5473 /* must be ordered: first operations for chars (infix ops),
5474  * then alphabetically */
5476 {
5477  char *s= (char *)u->Data();
5478  int r = (int)(long)v->Data();
5479  int c = (int)(long)w->Data();
5480  int l = strlen(s);
5481 
5482  if ( (r<1) || (r>l) || (c<0) )
5483  {
5484  Werror("wrong range[%d,%d] in string %s",r,c,u->Fullname());
5485  return TRUE;
5486  }
5487  res->data = (char *)omAlloc((long)(c+1));
5488  sprintf((char *)res->data,"%-*.*s",c,c,s+r-1);
5489  return FALSE;
5490 }
5492 {
5493  intvec *iv = (intvec *)u->Data();
5494  int r = (int)(long)v->Data();
5495  int c = (int)(long)w->Data();
5496  if ((r<1)||(r>iv->rows())||(c<1)||(c>iv->cols()))
5497  {
5498  Werror("wrong range[%d,%d] in intmat %s(%d x %d)",
5499  r,c,u->Fullname(),iv->rows(),iv->cols());
5500  return TRUE;
5501  }
5502  res->data=u->data; u->data=NULL;
5503  res->rtyp=u->rtyp; u->rtyp=0;
5504  res->name=u->name; u->name=NULL;
5505  Subexpr e=jjMakeSub(v);
5506  e->next=jjMakeSub(w);
5507  if (u->e==NULL) res->e=e;
5508  else
5509  {
5510  Subexpr h=u->e;
5511  while (h->next!=NULL) h=h->next;
5512  h->next=e;
5513  res->e=u->e;
5514  u->e=NULL;
5515  }
5516  return FALSE;
5517 }
5519 {
5520  bigintmat *bim = (bigintmat *)u->Data();
5521  int r = (int)(long)v->Data();
5522  int c = (int)(long)w->Data();
5523  if ((r<1)||(r>bim->rows())||(c<1)||(c>bim->cols()))
5524  {
5525  Werror("wrong range[%d,%d] in bigintmat %s(%d x %d)",
5526  r,c,u->Fullname(),bim->rows(),bim->cols());
5527  return TRUE;
5528  }
5529  res->data=u->data; u->data=NULL;
5530  res->rtyp=u->rtyp; u->rtyp=0;
5531  res->name=u->name; u->name=NULL;
5532  Subexpr e=jjMakeSub(v);
5533  e->next=jjMakeSub(w);
5534  if (u->e==NULL)
5535  res->e=e;
5536  else
5537  {
5538  Subexpr h=u->e;
5539  while (h->next!=NULL) h=h->next;
5540  h->next=e;
5541  res->e=u->e;
5542  u->e=NULL;
5543  }
5544  return FALSE;
5545 }
5547 {
5548  matrix m= (matrix)u->Data();
5549  int r = (int)(long)v->Data();
5550  int c = (int)(long)w->Data();
5551  //Print("gen. elem %d, %d\n",r,c);
5552  if ((r<1)||(r>MATROWS(m))||(c<1)||(c>MATCOLS(m)))
5553  {
5554  Werror("wrong range[%d,%d] in matrix %s(%d x %d)",r,c,u->Fullname(),
5555  MATROWS(m),MATCOLS(m));
5556  return TRUE;
5557  }
5558  res->data=u->data; u->data=NULL;
5559  res->rtyp=u->rtyp; u->rtyp=0;
5560  res->name=u->name; u->name=NULL;
5561  Subexpr e=jjMakeSub(v);
5562  e->next=jjMakeSub(w);
5563  if (u->e==NULL)
5564  res->e=e;
5565  else
5566  {
5567  Subexpr h=u->e;
5568  while (h->next!=NULL) h=h->next;
5569  h->next=e;
5570  res->e=u->e;
5571  u->e=NULL;
5572  }
5573  return FALSE;
5574 }
5576 {
5577  sleftv t;
5578  sleftv ut;
5579  leftv p=NULL;
5580  intvec *iv=(intvec *)w->Data();
5581  int l;
5582  BOOLEAN nok;
5583 
5584  if ((u->rtyp!=IDHDL)||(u->e!=NULL))
5585  {
5586  WerrorS("cannot build expression lists from unnamed objects");
5587  return TRUE;
5588  }
5589  memcpy(&ut,u,sizeof(ut));
5590  memset(&t,0,sizeof(t));
5591  t.rtyp=INT_CMD;
5592  for (l=0;l< iv->length(); l++)
5593  {
5594  t.data=(char *)(long)((*iv)[l]);
5595  if (p==NULL)
5596  {
5597  p=res;
5598  }
5599  else
5600  {
5602  p=p->next;
5603  }
5604  memcpy(u,&ut,sizeof(ut));
5605  if (u->Typ() == MATRIX_CMD)
5606  nok=jjBRACK_Ma(p,u,v,&t);
5607  else if (u->Typ() == BIGINTMAT_CMD)
5608  nok=jjBRACK_Bim(p,u,v,&t);
5609  else /* INTMAT_CMD */
5610  nok=jjBRACK_Im(p,u,v,&t);
5611  if (nok)
5612  {
5613  while (res->next!=NULL)
5614  {
5615  p=res->next->next;
5616  omFreeBin((ADDRESS)res->next, sleftv_bin);
5617  // res->e aufraeumen !!!!
5618  res->next=p;
5619  }
5620  return TRUE;
5621  }
5622  }
5623  return FALSE;
5624 }
5626 {
5627  sleftv t;
5628  sleftv ut;
5629  leftv p=NULL;
5630  intvec *iv=(intvec *)v->Data();
5631  int l;
5632  BOOLEAN nok;
5633 
5634  if ((u->rtyp!=IDHDL)||(u->e!=NULL))
5635  {
5636  WerrorS("cannot build expression lists from unnamed objects");
5637  return TRUE;
5638  }
5639  memcpy(&ut,u,sizeof(ut));
5640  memset(&t,0,sizeof(t));
5641  t.rtyp=INT_CMD;
5642  for (l=0;l< iv->length(); l++)
5643  {
5644  t.data=(char *)(long)((*iv)[l]);
5645  if (p==NULL)
5646  {
5647  p=res;
5648  }
5649  else
5650  {
5652  p=p->next;
5653  }
5654  memcpy(u,&ut,sizeof(ut));
5655  if (u->Typ() == MATRIX_CMD)
5656  nok=jjBRACK_Ma(p,u,&t,w);
5657  else if (u->Typ() == BIGINTMAT_CMD)
5658  nok=jjBRACK_Bim(p,u,&t,w);
5659  else /* INTMAT_CMD */
5660  nok=jjBRACK_Im(p,u,&t,w);
5661  if (nok)
5662  {
5663  while (res->next!=NULL)
5664  {
5665  p=res->next->next;
5666  omFreeBin((ADDRESS)res->next, sleftv_bin);
5667  // res->e aufraeumen !!
5668  res->next=p;
5669  }
5670  return TRUE;
5671  }
5672  }
5673  return FALSE;
5674 }
5676 {
5677  sleftv t1,t2,ut;
5678  leftv p=NULL;
5679  intvec *vv=(intvec *)v->Data();
5680  intvec *wv=(intvec *)w->Data();
5681  int vl;
5682  int wl;
5683  BOOLEAN nok;
5684 
5685  if ((u->rtyp!=IDHDL)||(u->e!=NULL))
5686  {
5687  WerrorS("cannot build expression lists from unnamed objects");
5688  return TRUE;
5689  }
5690  memcpy(&ut,u,sizeof(ut));
5691  memset(&t1,0,sizeof(sleftv));
5692  memset(&t2,0,sizeof(sleftv));
5693  t1.rtyp=INT_CMD;
5694  t2.rtyp=INT_CMD;
5695  for (vl=0;vl< vv->length(); vl++)
5696  {
5697  t1.data=(char *)(long)((*vv)[vl]);
5698  for (wl=0;wl< wv->length(); wl++)
5699  {
5700  t2.data=(char *)(long)((*wv)[wl]);
5701  if (p==NULL)
5702  {
5703  p=res;
5704  }
5705  else
5706  {
5708  p=p->next;
5709  }
5710  memcpy(u,&ut,sizeof(ut));
5711  if (u->Typ() == MATRIX_CMD)
5712  nok=jjBRACK_Ma(p,u,&t1,&t2);
5713  else if (u->Typ() == BIGINTMAT_CMD)
5714  nok=jjBRACK_Bim(p,u,&t1,&t2);
5715  else /* INTMAT_CMD */
5716  nok=jjBRACK_Im(p,u,&t1,&t2);
5717  if (nok)
5718  {
5719  res->CleanUp();
5720  return TRUE;
5721  }
5722  }
5723  }
5724  return FALSE;
5725 }
5726 static BOOLEAN jjPROC3(leftv res, leftv u, leftv v, leftv w)
5727 {
5729  memcpy(v->next,w,sizeof(sleftv));
5730  memset(w,0,sizeof(sleftv));
5731  return jjPROC(res,u,v);
5732 }
5733 static BOOLEAN jjBAREISS3(leftv res, leftv u, leftv v, leftv w)
5734 {
5735  intvec *iv;
5736  ideal m;
5738  int k=(int)(long)w->Data();
5739  if (k>=0)
5740  {
5741  sm_CallBareiss((ideal)u->Data(),(int)(long)v->Data(),(int)(long)w->Data(),m,&iv, currRing);
5742  l->Init(2);
5743  l->m[0].rtyp=MODUL_CMD;
5744  l->m[1].rtyp=INTVEC_CMD;
5745  l->m[0].data=(void *)m;
5746  l->m[1].data=(void *)iv;
5747  }
5748  else
5749  {
5750  m=sm_CallSolv((ideal)u->Data(), currRing);
5751  l->Init(1);
5752  l->m[0].rtyp=IDEAL_CMD;
5753  l->m[0].data=(void *)m;
5754  }
5755  res->data = (char *)l;
5756  return FALSE;
5757 }
5759 {
5760  if ((w->rtyp!=IDHDL)||(w->e!=NULL))
5761  {
5762  WerrorS("3rd argument must be a name of a matrix");
5763  return TRUE;
5764  }
5765  ideal i=(ideal)u->Data();
5766  int rank=(int)i->rank;
5767  BOOLEAN r=jjCOEFFS_Id(res,u,v);
5768  if (r) return TRUE;
5769  mp_Monomials((matrix)res->data, rank, pVar((poly)v->Data()),(matrix)w->Data(),currRing);
5770  return FALSE;
5771 }
5773 {
5774  res->data=(void*)idCoeffOfKBase((ideal)(u->Data()),
5775  (ideal)(v->Data()),(poly)(w->Data()));
5776  return FALSE;
5777 }
5779 {
5780  if ((w->rtyp!=IDHDL)||(w->e!=NULL))
5781  {
5782  WerrorS("3rd argument must be a name of a matrix");
5783  return TRUE;
5784  }
5785  // CopyD for POLY_CMD and VECTOR_CMD are identical:
5786  poly p=(poly)u->CopyD(POLY_CMD);
5787  ideal i=idInit(1,1);
5788  i->m[0]=p;
5789  sleftv t;
5790  memset(&t,0,sizeof(t));
5791  t.data=(char *)i;
5792  t.rtyp=IDEAL_CMD;
5793  int rank=1;
5794  if (u->Typ()==VECTOR_CMD)
5795  {
5796  i->rank=rank=pMaxComp(p);
5797  t.rtyp=MODUL_CMD;
5798  }
5799  BOOLEAN r=jjCOEFFS_Id(res,&t,v);
5800  t.CleanUp();
5801  if (r) return TRUE;
5802  mp_Monomials((matrix)res->data, rank, pVar((poly)v->Data()),(matrix)w->Data(),currRing);
5803  return FALSE;
5804 }
5806 {
5807  res->data=(char *)idElimination((ideal)u->Data(),(poly)v->Data(),
5808  (intvec *)w->Data());
5809  //setFlag(res,FLAG_STD);
5810  return FALSE;
5811 }
5812 static BOOLEAN jjFIND3(leftv res, leftv u, leftv v, leftv w)
5813 {
5814  /*4
5815  * look for the substring what in the string where
5816  * starting at position n
5817  * return the position of the first char of what in where
5818  * or 0
5819  */
5820  int n=(int)(long)w->Data();
5821  char *where=(char *)u->Data();
5822  char *what=(char *)v->Data();
5823  char *found;
5824  if ((1>n)||(n>(int)strlen(where)))
5825  {
5826  Werror("start position %d out of range",n);
5827  return TRUE;
5828  }
5829  found = strchr(where+n-1,*what);
5830  if (*(what+1)!='\0')
5831  {
5832  while((found !=NULL) && (strncmp(found+1,what+1,strlen(what+1))!=0))
5833  {
5834  found=strchr(found+1,*what);
5835  }
5836  }
5837  if (found != NULL)
5838  {
5839  res->data=(char *)((found-where)+1);
5840  }
5841  return FALSE;
5842 }
5843 static BOOLEAN jjFWALK3(leftv res, leftv u, leftv v, leftv w)
5844 {
5845  if ((int)(long)w->Data()==0)
5846  res->data=(char *)walkProc(u,v);
5847  else
5848  res->data=(char *)fractalWalkProc(u,v);
5849  setFlag( res, FLAG_STD );
5850  return FALSE;
5851 }
5852 static BOOLEAN jjHILBERT3(leftv res, leftv u, leftv v, leftv w)
5853 {
5854  intvec *wdegree=(intvec*)w->Data();
5855  if (wdegree->length()!=currRing->N)
5856  {
5857  Werror("weight vector must have size %d, not %d",
5858  currRing->N,wdegree->length());
5859  return TRUE;
5860  }
5861 #ifdef HAVE_RINGS
5863  {
5864  ring origR = currRing;
5865  ring tempR = rCopy(origR);
5866  coeffs new_cf=nInitChar(n_Q,NULL);
5867  nKillChar(tempR->cf);
5868  tempR->cf=new_cf;
5869  rComplete(tempR);
5870  ideal uid = (ideal)u->Data();
5871  rChangeCurrRing(tempR);
5872  ideal uu = idrCopyR(uid, origR, currRing);
5873  sleftv uuAsLeftv; memset(&uuAsLeftv, 0, sizeof(uuAsLeftv));
5874  uuAsLeftv.rtyp = IDEAL_CMD;
5875  uuAsLeftv.data = uu; uuAsLeftv.next = NULL;
5876  if (hasFlag(u, FLAG_STD)) setFlag(&uuAsLeftv,FLAG_STD);
5877  assumeStdFlag(&uuAsLeftv);
5878  Print("// NOTE: computation of Hilbert series etc. is being\n");
5879  Print("// performed for generic fibre, that is, over Q\n");
5880  intvec *module_w=(intvec*)atGet(&uuAsLeftv,"isHomog",INTVEC_CMD);
5881  intvec *iv=hFirstSeries(uu,module_w,currRing->qideal,wdegree);
5882  int returnWithTrue = 1;
5883  switch((int)(long)v->Data())
5884  {
5885  case 1:
5886  res->data=(void *)iv;
5887  returnWithTrue = 0;
5888  case 2:
5889  res->data=(void *)hSecondSeries(iv);
5890  delete iv;
5891  returnWithTrue = 0;
5892  }
5893  if (returnWithTrue)
5894  {
5896  delete iv;
5897  }
5898  idDelete(&uu);
5899  rChangeCurrRing(origR);
5900  rDelete(tempR);
5901  if (returnWithTrue) return TRUE; else return FALSE;
5902  }
5903 #endif
5904  assumeStdFlag(u);
5905  intvec *module_w=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
5906  intvec *iv=hFirstSeries((ideal)u->Data(),module_w,currRing->qideal,wdegree);
5907  switch((int)(long)v->Data())
5908  {
5909  case 1:
5910  res->data=(void *)iv;
5911  return FALSE;
5912  case 2:
5913  res->data=(void *)hSecondSeries(iv);
5914  delete iv;
5915  return FALSE;
5916  }
5918  delete iv;
5919  return TRUE;
5920 }
5921 static BOOLEAN jjHOMOG_ID_W(leftv res, leftv u, leftv v, leftv /*w*/)
5922 {
5923  PrintS("TODO\n");
5924  int i=pVar((poly)v->Data());
5925  if (i==0)
5926  {
5927  WerrorS("ringvar expected");
5928  return TRUE;
5929  }
5930  poly p=pOne(); pSetExp(p,i,1); pSetm(p);
5931  int d=pWTotaldegree(p);
5932  pLmDelete(p);
5933  if (d==1)
5934  res->data = (char *)id_Homogen((ideal)u->Data(), i, currRing);
5935  else
5936  WerrorS("variable must have weight 1");
5937  return (d!=1);
5938 }
5939 static BOOLEAN jjHOMOG_P_W(leftv res, leftv u, leftv v,leftv /*w*/)
5940 {
5941  PrintS("TODO\n");
5942  int i=pVar((poly)v->Data());
5943  if (i==0)
5944  {
5945  WerrorS("ringvar expected");
5946  return TRUE;
5947  }
5948  poly p=pOne(); pSetExp(p,i,1); pSetm(p);
5949  int d=pWTotaldegree(p);
5950  pLmDelete(p);
5951  if (d==1)
5952  res->data = (char *)p_Homogen((poly)u->Data(), i, currRing);
5953  else
5954  WerrorS("variable must have weight 1");
5955  return (d!=1);
5956 }
5958 {
5959  intvec* im= new intvec((int)(long)v->Data(),(int)(long)w->Data(), 0);
5960  intvec* arg = (intvec*) u->Data();
5961  int i, n = si_min(im->cols()*im->rows(), arg->cols()*arg->rows());
5962 
5963  for (i=0; i<n; i++)
5964  {
5965  (*im)[i] = (*arg)[i];
5966  }
5967 
5968  res->data = (char *)im;
5969  return FALSE;
5970 }
5971 static BOOLEAN jjJET_P_IV(leftv res, leftv u, leftv v, leftv w)
5972 {
5973  short *iw=iv2array((intvec *)w->Data(),currRing);
5974  res->data = (char *)ppJetW((poly)u->Data(),(int)(long)v->Data(),iw);
5975  omFreeSize( (ADDRESS)iw, (rVar(currRing)+1)*sizeof(short) );
5976  return FALSE;
5977 }
5978 static BOOLEAN jjJET_P_P(leftv res, leftv u, leftv v, leftv w)
5979 {
5980  if (!pIsUnit((poly)v->Data()))
5981  {
5982  WerrorS("2nd argument must be a unit");
5983  return TRUE;
5984  }
5985  res->data = (char *)p_Series((int)(long)w->Data(),(poly)u->CopyD(),(poly)v->CopyD(),NULL,currRing);
5986  return FALSE;
5987 }
5989 {
5990  res->data = (char *)id_JetW((ideal)u->Data(),(int)(long)v->Data(),
5991  (intvec *)w->Data(),currRing);
5992  return FALSE;
5993 }
5994 static BOOLEAN jjJET_ID_M(leftv res, leftv u, leftv v, leftv w)
5995 {
5996  if (!mp_IsDiagUnit((matrix)v->Data(), currRing))
5997  {
5998  WerrorS("2nd argument must be a diagonal matrix of units");
5999  return TRUE;
6000  }
6001  res->data = (char *)idSeries((int)(long)w->Data(),(ideal)u->CopyD(),
6002  (matrix)v->CopyD());
6003  return FALSE;
6004 }
6006 {
6007  /* true for fields and Z, false otherwise */
6008  if (rField_is_Ring_PtoM(currRing)) return FALSE;
6009  if (rField_is_Ring_2toM(currRing)) return FALSE;
6010  if (rField_is_Ring_ModN(currRing)) return FALSE;
6011  return TRUE;
6012 }
6014 {
6015  /* Here's the use pattern for the minor command:
6016  minor ( matrix_expression m, int_expression minorSize,
6017  optional ideal_expression IasSB, optional int_expression k,
6018  optional string_expression algorithm,
6019  optional int_expression cachedMinors,
6020  optional int_expression cachedMonomials )
6021  This method here assumes that there are at least two arguments.
6022  - If IasSB is present, it must be a std basis. All minors will be
6023  reduced w.r.t. IasSB.
6024  - If k is absent, all non-zero minors will be computed.
6025  If k is present and k > 0, the first k non-zero minors will be
6026  computed.
6027  If k is present and k < 0, the first |k| minors (some of which
6028  may be zero) will be computed.
6029  If k is present and k = 0, an error is reported.
6030  - If algorithm is absent, all the following arguments must be absent too.
6031  In this case, a heuristic picks the best-suited algorithm (among
6032  Bareiss, Laplace, and Laplace with caching).
6033  If algorithm is present, it must be one of "Bareiss", "bareiss",
6034  "Laplace", "laplace", "Cache", "cache". In the cases "Cache" and
6035  "cache" two more arguments may be given, determining how many entries
6036  the cache may have at most, and how many cached monomials there are at
6037  most. (Cached monomials are counted over all cached polynomials.)
6038  If these two additional arguments are not provided, 200 and 100000
6039  will be used as defaults.
6040  */
6041  matrix m;
6042  leftv u=v->next;
6043  v->next=NULL;
6044  int v_typ=v->Typ();
6045  if (v_typ==MATRIX_CMD)
6046  {
6047  m = (const matrix)v->Data();
6048  }
6049  else
6050  {
6051  if (v_typ==0)
6052  {
6053  Werror("`%s` is undefined",v->Fullname());
6054  return TRUE;
6055  }
6056  // try to convert to MATRIX:
6057  int ii=iiTestConvert(v_typ,MATRIX_CMD);
6058  BOOLEAN bo;
6059  sleftv tmp;
6060  if (ii>0) bo=iiConvert(v_typ,MATRIX_CMD,ii,v,&tmp);
6061  else bo=TRUE;
6062  if (bo)
6063  {
6064  Werror("cannot convert %s to matrix",Tok2Cmdname(v_typ));
6065  return TRUE;
6066  }
6067  m=(matrix)tmp.data;
6068  }
6069  const int mk = (const int)(long)u->Data();
6070  bool noIdeal = true; bool noK = true; bool noAlgorithm = true;
6071  bool noCacheMinors = true; bool noCacheMonomials = true;
6072  ideal IasSB; int k; char* algorithm; int cacheMinors; int cacheMonomials;
6073 
6074  /* here come the different cases of correct argument sets */
6075  if ((u->next != NULL) && (u->next->Typ() == IDEAL_CMD))
6076  {
6077  IasSB = (ideal)u->next->Data();
6078  noIdeal = false;
6079  if ((u->next->next != NULL) && (u->next->next->Typ() == INT_CMD))
6080  {
6081  k = (int)(long)u->next->next->Data();
6082  noK = false;
6083  assume(k != 0);
6084  if ((u->next->next->next != NULL) &&
6085  (u->next->next->next->Typ() == STRING_CMD))
6086  {
6087  algorithm = (char*)u->next->next->next->Data();
6088  noAlgorithm = false;
6089  if ((u->next->next->next->next != NULL) &&
6090  (u->next->next->next->next->Typ() == INT_CMD))
6091  {
6092  cacheMinors = (int)(long)u->next->next->next->next->Data();
6093  noCacheMinors = false;
6094  if ((u->next->next->next->next->next != NULL) &&
6095  (u->next->next->next->next->next->Typ() == INT_CMD))
6096  {
6097  cacheMonomials =
6098  (int)(long)u->next->next->next->next->next->Data();
6099  noCacheMonomials = false;
6100  }
6101  }
6102  }
6103  }
6104  }
6105  else if ((u->next != NULL) && (u->next->Typ() == INT_CMD))
6106  {
6107  k = (int)(long)u->next->Data();
6108  noK = false;
6109  assume(k != 0);
6110  if ((u->next->next != NULL) && (u->next->next->Typ() == STRING_CMD))
6111  {
6112  algorithm = (char*)u->next->next->Data();
6113  noAlgorithm = false;
6114  if ((u->next->next->next != NULL) &&
6115  (u->next->next->next->Typ() == INT_CMD))
6116  {
6117  cacheMinors = (int)(long)u->next->next->next->Data();
6118  noCacheMinors = false;
6119  if ((u->next->next->next->next != NULL) &&
6120  (u->next->next->next->next->Typ() == INT_CMD))
6121  {
6122  cacheMonomials = (int)(long)u->next->next->next->next->Data();
6123  noCacheMonomials = false;
6124  }
6125  }
6126  }
6127  }
6128  else if ((u->next != NULL) && (u->next->Typ() == STRING_CMD))
6129  {
6130  algorithm = (char*)u->next->Data();
6131  noAlgorithm = false;
6132  if ((u->next->next != NULL) && (u->next->next->Typ() == INT_CMD))
6133  {
6134  cacheMinors = (int)(long)u->next->next->Data();
6135  noCacheMinors = false;
6136  if ((u->next->next->next != NULL) &&
6137  (u->next->next->next->Typ() == INT_CMD))
6138  {
6139  cacheMonomials = (int)(long)u->next->next->next->Data();
6140  noCacheMonomials = false;
6141  }
6142  }
6143  }
6144 
6145  /* upper case conversion for the algorithm if present */
6146  if (!noAlgorithm)
6147  {
6148  if (strcmp(algorithm, "bareiss") == 0)
6149  algorithm = (char*)"Bareiss";
6150  if (strcmp(algorithm, "laplace") == 0)
6151  algorithm = (char*)"Laplace";
6152  if (strcmp(algorithm, "cache") == 0)
6153  algorithm = (char*)"Cache";
6154  }
6155 
6156  v->next=u;
6157  /* here come some tests */
6158  if (!noIdeal)
6159  {
6160  assumeStdFlag(u->next);
6161  }
6162  if ((!noK) && (k == 0))
6163  {
6164  WerrorS("Provided number of minors to be computed is zero.");
6165  return TRUE;
6166  }
6167  if ((!noAlgorithm) && (strcmp(algorithm, "Bareiss") != 0)
6168  && (strcmp(algorithm, "Laplace") != 0)
6169  && (strcmp(algorithm, "Cache") != 0))
6170  {
6171  WerrorS("Expected as algorithm one of 'B/bareiss', 'L/laplace', or 'C/cache'.");
6172  return TRUE;
6173  }
6174  if ((!noAlgorithm) && (strcmp(algorithm, "Bareiss") == 0)
6176  {
6177  Werror("Bareiss algorithm not defined over coefficient rings %s",
6178  "with zero divisors.");
6179  return TRUE;
6180  }
6181  res->rtyp=IDEAL_CMD;
6182  if ((mk < 1) || (mk > m->rows()) || (mk > m->cols()))
6183  {
6184  ideal I=idInit(1,1);
6185  if (mk<1) I->m[0]=p_One(currRing);
6186  //Werror("invalid size of minors: %d (matrix is (%d x %d))", mk,
6187  // m->rows(), m->cols());
6188  res->data=(void*)I;
6189  return FALSE;
6190  }
6191  if ((!noAlgorithm) && (strcmp(algorithm, "Cache") == 0)
6192  && (noCacheMinors || noCacheMonomials))
6193  {
6194  cacheMinors = 200;
6195  cacheMonomials = 100000;
6196  }
6197 
6198  /* here come the actual procedure calls */
6199  if (noAlgorithm)
6200  res->data = getMinorIdealHeuristic(m, mk, (noK ? 0 : k),
6201  (noIdeal ? 0 : IasSB), false);
6202  else if (strcmp(algorithm, "Cache") == 0)
6203  res->data = getMinorIdealCache(m, mk, (noK ? 0 : k),
6204  (noIdeal ? 0 : IasSB), 3, cacheMinors,
6205  cacheMonomials, false);
6206  else
6207  res->data = getMinorIdeal(m, mk, (noK ? 0 : k), algorithm,
6208  (noIdeal ? 0 : IasSB), false);
6209  if (v_typ!=MATRIX_CMD) idDelete((ideal *)&m);
6210  return FALSE;
6211 }
6213 {
6214  // u: the name of the new type
6215  // v: the parent type
6216  // w: the elements
6217  newstruct_desc d=newstructChildFromString((const char *)v->Data(),
6218  (const char *)w->Data());
6219  if (d!=NULL) newstruct_setup((const char *)u->Data(),d);
6220  return (d==NULL);
6221 }
6222 static BOOLEAN jjPREIMAGE(leftv res, leftv u, leftv v, leftv w)
6223 {
6224  // handles preimage(r,phi,i) and kernel(r,phi)
6225  idhdl h;
6226  ring rr;
6227  map mapping;
6228  BOOLEAN kernel_cmd= (iiOp==KERNEL_CMD);
6229 
6230  if ((v->name==NULL) || (!kernel_cmd && (w->name==NULL)))
6231  {
6232  WerrorS("2nd/3rd arguments must have names");
6233  return TRUE;
6234  }
6235  rr=(ring)u->Data();
6236  const char *ring_name=u->Name();
6237  if ((h=rr->idroot->get(v->name,myynest))!=NULL)
6238  {
6239  if (h->typ==MAP_CMD)
6240  {
6241  mapping=IDMAP(h);
6242  idhdl preim_ring=IDROOT->get(mapping->preimage,myynest);
6243  if ((preim_ring==NULL)
6244  || (IDRING(preim_ring)!=currRing))
6245  {
6246  Werror("preimage ring `%s` is not the basering",mapping->preimage);
6247  return TRUE;
6248  }
6249  }
6250  else if (h->typ==IDEAL_CMD)
6251  {
6252  mapping=IDMAP(h);
6253  }
6254  else
6255  {
6256  Werror("`%s` is no map nor ideal",IDID(h));
6257  return TRUE;
6258  }
6259  }
6260  else
6261  {
6262  Werror("`%s` is not defined in `%s`",v->name,ring_name);
6263  return TRUE;
6264  }
6265  ideal image;
6266  if (kernel_cmd) image=idInit(1,1);
6267  else
6268  {
6269  if ((h=rr->idroot->get(w->name,myynest))!=NULL)
6270  {
6271  if (h->typ==IDEAL_CMD)
6272  {
6273  image=IDIDEAL(h);
6274  }
6275  else
6276  {
6277  Werror("`%s` is no ideal",IDID(h));
6278  return TRUE;
6279  }
6280  }
6281  else
6282  {
6283  Werror("`%s` is not defined in `%s`",w->name,ring_name);
6284  return TRUE;
6285  }
6286  }
6287  if (((currRing->qideal!=NULL) && (rHasLocalOrMixedOrdering_currRing()))
6288  || ((rr->qideal!=NULL) && (rHasLocalOrMixedOrdering(rr))))
6289  {
6290  WarnS("preimage in local qring may be wrong: use Ring::preimageLoc instead");
6291  }
6292  res->data=(char *)maGetPreimage(rr,mapping,image,currRing);
6293  if (kernel_cmd) idDelete(&image);
6294  return (res->data==NULL/* is of type ideal, should not be NULL*/);
6295 }
6297 {
6298  int di, k;
6299  int i=(int)(long)u->Data();
6300  int r=(int)(long)v->Data();
6301  int c=(int)(long)w->Data();
6302  if ((r<=0) || (c<=0)) return TRUE;
6303  intvec *iv = new intvec(r, c, 0);
6304  if (iv->rows()==0)
6305  {
6306  delete iv;
6307  return TRUE;
6308  }
6309  if (i!=0)
6310  {
6311  if (i<0) i = -i;
6312  di = 2 * i + 1;
6313  for (k=0; k<iv->length(); k++)
6314  {
6315  (*iv)[k] = ((siRand() % di) - i);
6316  }
6317  }
6318  res->data = (char *)iv;
6319  return FALSE;
6320 }
6321 #ifdef SINGULAR_4_1
6323 // <coeff>, par1, par2 -> number2
6324 {
6325  coeffs cf=(coeffs)u->Data();
6326  if ((cf!=NULL) && (cf->cfRandom!=NULL))
6327  {
6328  number n= n_Random(siRand,(number)v->Data(),(number)w->Data(),cf);
6329  number2 nn=(number2)omAlloc(sizeof(*nn));
6330  nn->cf=cf;
6331  nn->n=n;
6332  res->data=nn;
6333  return FALSE;
6334  }
6335  return TRUE;
6336 }
6337 #endif
6339  int &ringvar, poly &monomexpr)
6340 {
6341  monomexpr=(poly)w->Data();
6342  poly p=(poly)v->Data();
6343 #if 0
6344  if (pLength(monomexpr)>1)
6345  {
6346  Werror("`%s` substitutes a ringvar only by a term",
6348  return TRUE;
6349  }
6350 #endif
6351  if ((ringvar=pVar(p))==0)
6352  {
6353  if ((p!=NULL) && (currRing->cf->extRing!=NULL))
6354  {
6355  number n = pGetCoeff(p);
6356  ringvar= -n_IsParam(n, currRing);
6357  }
6358  if(ringvar==0)
6359  {
6360  WerrorS("ringvar/par expected");
6361  return TRUE;
6362  }
6363  }
6364  return FALSE;
6365 }
6367 {
6368  int ringvar;
6369  poly monomexpr;
6370  BOOLEAN nok=jjSUBST_Test(v,w,ringvar,monomexpr);
6371  if (nok) return TRUE;
6372  poly p=(poly)u->Data();
6373  if (ringvar>0)
6374  {
6375  if ((monomexpr!=NULL) && (p!=NULL) && (pTotaldegree(p)!=0) &&
6376  ((unsigned long)pTotaldegree(monomexpr) > (currRing->bitmask / (unsigned long)pTotaldegree(p)/2)))
6377  {
6378  Warn("possible OVERFLOW in subst, max exponent is %ld, subtituting deg %d by deg %d",currRing->bitmask/2, pTotaldegree(monomexpr), pTotaldegree(p));
6379  //return TRUE;
6380  }
6381  if ((monomexpr==NULL)||(pNext(monomexpr)==NULL))
6382  res->data = pSubst((poly)u->CopyD(res->rtyp),ringvar,monomexpr);
6383  else
6384  res->data= pSubstPoly(p,ringvar,monomexpr);
6385  }
6386  else
6387  {
6388  res->data=pSubstPar(p,-ringvar,monomexpr);
6389  }
6390  return FALSE;
6391 }
6393 {
6394  int ringvar;
6395  poly monomexpr;
6396  BOOLEAN nok=jjSUBST_Test(v,w,ringvar,monomexpr);
6397  if (nok) return TRUE;
6398  ideal id=(ideal)u->Data();
6399  if (ringvar>0)
6400  {
6401  BOOLEAN overflow=FALSE;
6402  if (monomexpr!=NULL)
6403  {
6404  long deg_monexp=pTotaldegree(monomexpr);
6405  for(int i=IDELEMS(id)-1;i>=0;i--)
6406  {
6407  poly p=id->m[i];
6408  if ((p!=NULL) && (pTotaldegree(p)!=0) &&
6409  ((unsigned long)deg_monexp > (currRing->bitmask / (unsigned long)pTotaldegree(p)/2)))
6410  {
6411  overflow=TRUE;
6412  break;
6413  }
6414  }
6415  }
6416  if (overflow)
6417  Warn("possible OVERFLOW in subst, max exponent is %ld",currRing->bitmask/2);
6418  if ((monomexpr==NULL)||(pNext(monomexpr)==NULL))
6419  {
6420  if (res->rtyp==MATRIX_CMD) id=(ideal)mp_Copy((matrix)id,currRing);
6421  else id=id_Copy(id,currRing);
6422  res->data = id_Subst(id, ringvar, monomexpr, currRing);
6423  }
6424  else
6425  res->data = idSubstPoly(id,ringvar,monomexpr);
6426  }
6427  else
6428  {
6429  res->data = idSubstPar(id,-ringvar,monomexpr);
6430  }
6431  return FALSE;
6432 }
6433 // we do not want to have jjSUBST_Id_X inlined:
6434 static BOOLEAN jjSUBST_Id_X(leftv res, leftv u, leftv v,leftv w,
6435  int input_type);
6437 {
6438  return jjSUBST_Id_X(res,u,v,w,INT_CMD);
6439 }
6441 {
6442  return jjSUBST_Id_X(res,u,v,w,NUMBER_CMD);
6443 }
6444 static BOOLEAN jjSUBST_Id_X(leftv res, leftv u, leftv v,leftv w, int input_type)
6445 {
6446  sleftv tmp;
6447  memset(&tmp,0,sizeof(tmp));
6448  // do not check the result, conversion from int/number to poly works always
6449  iiConvert(input_type,POLY_CMD,iiTestConvert(input_type,POLY_CMD),w,&tmp);
6450  BOOLEAN b=jjSUBST_Id(res,u,v,&tmp);
6451  tmp.CleanUp();
6452  return b;
6453 }
6455 {
6456  int mi=(int)(long)v->Data();
6457  int ni=(int)(long)w->Data();
6458  if ((mi<1)||(ni<1))
6459  {
6460  Werror("converting ideal to matrix: dimensions must be positive(%dx%d)",mi,ni);
6461  return TRUE;
6462  }
6463  matrix m=mpNew(mi,ni);
6464  ideal I=(ideal)u->CopyD(IDEAL_CMD);
6465  int i=si_min(IDELEMS(I),mi*ni);
6466  //for(i=i-1;i>=0;i--)
6467  //{
6468  // m->m[i]=I->m[i];
6469  // I->m[i]=NULL;
6470  //}
6471  memcpy(m->m,I->m,i*sizeof(poly));
6472  memset(I->m,0,i*sizeof(poly));
6473  id_Delete(&I,currRing);
6474  res->data = (char *)m;
6475  return FALSE;
6476 }
6478 {
6479  int mi=(int)(long)v->Data();
6480  int ni=(int)(long)w->Data();
6481  if ((mi<1)||(ni<1))
6482  {
6483  Werror("converting module to matrix: dimensions must be positive(%dx%d)",mi,ni);
6484  return TRUE;
6485  }
6486  res->data = (char *)id_Module2formatedMatrix((ideal)u->CopyD(MODUL_CMD),
6487  mi,ni,currRing);
6488  return FALSE;
6489 }
6491 {
6492  int mi=(int)(long)v->Data();
6493  int ni=(int)(long)w->Data();
6494  if ((mi<1)||(ni<1))
6495  {
6496  Werror("converting matrix to matrix: dimensions must be positive(%dx%d)",mi,ni);
6497  return TRUE;
6498  }
6499  matrix m=mpNew(mi,ni);
6500  matrix I=(matrix)u->CopyD(MATRIX_CMD);
6501  int r=si_min(MATROWS(I),mi);
6502  int c=si_min(MATCOLS(I),ni);
6503  int i,j;
6504  for(i=r;i>0;i--)
6505  {
6506  for(j=c;j>0;j--)
6507  {
6508  MATELEM(m,i,j)=MATELEM(I,i,j);
6509  MATELEM(I,i,j)=NULL;
6510  }
6511  }
6512  id_Delete((ideal *)&I,currRing);
6513  res->data = (char *)m;
6514  return FALSE;
6515 }
6516 static BOOLEAN jjLIFT3(leftv res, leftv u, leftv v, leftv w)
6517 {
6518  if (w->rtyp!=IDHDL) return TRUE;
6519  int ul= IDELEMS((ideal)u->Data());
6520  int vl= IDELEMS((ideal)v->Data());
6521  ideal m
6522  = idLift((ideal)u->Data(),(ideal)v->Data(),NULL,FALSE,hasFlag(u,FLAG_STD),
6523  FALSE, (matrix *)(&(IDMATRIX((idhdl)(w->data)))));
6524  if (m==NULL) return TRUE;
6525  res->data = (char *)id_Module2formatedMatrix(m,ul,vl,currRing);
6526  return FALSE;
6527 }
6528 static BOOLEAN jjLIFTSTD3(leftv res, leftv u, leftv v, leftv w)
6529 {
6530  if ((v->rtyp!=IDHDL)||(v->e!=NULL)) return TRUE;
6531  if ((w->rtyp!=IDHDL)||(w->e!=NULL)) return TRUE;
6532  idhdl hv=(idhdl)v->data;
6533  idhdl hw=(idhdl)w->data;
6534  // CopyD for IDEAL_CMD and MODUL_CMD are identical:
6535  res->data = (char *)idLiftStd((ideal)u->Data(),
6536  &(hv->data.umatrix),testHomog,
6537  &(hw->data.uideal));
6538  setFlag(res,FLAG_STD); v->flag=0; w->flag=0;
6539  return FALSE;
6540 }
6542 {
6543  assumeStdFlag(v);
6544  if (!idIsZeroDim((ideal)v->Data()))
6545  {
6546  Werror("`%s` must be 0-dimensional",v->Name());
6547  return TRUE;
6548  }
6549  res->data = (char *)redNF((ideal)v->CopyD(),(poly)u->CopyD(),
6550  (poly)w->CopyD());
6551  return FALSE;
6552 }
6554 {
6555  assumeStdFlag(v);
6556  if (!idIsZeroDim((ideal)v->Data()))
6557  {
6558  Werror("`%s` must be 0-dimensional",v->Name());
6559  return TRUE;
6560  }
6561  res->data = (char *)redNF((ideal)v->CopyD(),(ideal)u->CopyD(),
6562  (matrix)w->CopyD());
6563  return FALSE;
6564 }
6566 {
6567  assumeStdFlag(v);
6568  res->data = (char *)kNF((ideal)v->Data(),currRing->qideal,(poly)u->Data(),
6569  0,(int)(long)w->Data());
6570  return FALSE;
6571 }
6573 {
6574  assumeStdFlag(v);
6575  res->data = (char *)kNF((ideal)v->Data(),currRing->qideal,(ideal)u->Data(),
6576  0,(int)(long)w->Data());
6577  return FALSE;
6578 }
6579 #ifdef OLD_RES
6580 static BOOLEAN jjRES3(leftv res, leftv u, leftv v, leftv w)
6581 {
6582  int maxl=(int)v->Data();
6583  ideal u_id=(ideal)u->Data();
6584  int l=0;
6585  resolvente r;
6586  intvec **weights=NULL;
6587  int wmaxl=maxl;
6588  maxl--;
6589  if ((maxl==-1) && (iiOp!=MRES_CMD))
6590  maxl = currRing->N-1;
6591  if ((iiOp == RES_CMD) || (iiOp == MRES_CMD))
6592  {
6593  intvec * iv=(intvec*)atGet(u,"isHomog",INTVEC_CMD);
6594  if (iv!=NULL)
6595  {
6596  l=1;
6597  if (!idTestHomModule(u_id,currRing->qideal,iv))
6598  {
6599  WarnS("wrong weights");
6600  iv=NULL;
6601  }
6602  else
6603  {
6604  weights = (intvec**)omAlloc0Bin(char_ptr_bin);
6605  weights[0] = ivCopy(iv);
6606  }
6607  }
6608  r=syResolvente(u_id,maxl,&l, &weights, iiOp==MRES_CMD);
6609  }
6610  else
6611  r=sySchreyerResolvente((ideal)u->Data(),maxl+1,&l);
6612  if (r==NULL) return TRUE;
6613  int t3=u->Typ();
6614  iiMakeResolv(r,l,wmaxl,w->name,t3,weights);
6615  return FALSE;
6616 }
6617 #endif
6618 static BOOLEAN jjRING3(leftv res, leftv u, leftv v, leftv w)
6619 {
6620  res->data=(void *)rInit(u,v,w);
6621  return (res->data==NULL);
6622 }
6623 static BOOLEAN jjSTATUS3(leftv res, leftv u, leftv v, leftv w)
6624 {
6625  int yes;
6626  jjSTATUS2(res, u, v);
6627  yes = (strcmp((char *) res->data, (char *) w->Data()) == 0);
6628  omFree((ADDRESS) res->data);
6629  res->data = (void *)(long)yes;
6630  return FALSE;
6631 }
6633 {
6634  intvec *vw=(intvec *)w->Data(); // weights of vars
6635  if (vw->length()!=currRing->N)
6636  {
6637  Werror("%d weights for %d variables",vw->length(),currRing->N);
6638  return TRUE;
6639  }
6640  ideal result;
6641  intvec *ww=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
6642  tHomog hom=testHomog;
6643  ideal u_id=(ideal)(u->Data());
6644  if (ww!=NULL)
6645  {
6646  if (!idTestHomModule(u_id,currRing->qideal,ww))
6647  {
6648  WarnS("wrong weights");
6649  ww=NULL;
6650  }
6651  else
6652  {
6653  ww=ivCopy(ww);
6654  hom=isHomog;
6655  }
6656  }
6657  result=kStd(u_id,
6658  currRing->qideal,
6659  hom,
6660  &ww, // module weights
6661  (intvec *)v->Data(), // hilbert series
6662  0,0, // syzComp, newIdeal
6663  vw); // weights of vars
6664  idSkipZeroes(result);
6665  res->data = (char *)result;
6666  setFlag(res,FLAG_STD);
6667  if (ww!=NULL) atSet(res,omStrDup("isHomog"),ww,INTVEC_CMD);
6668  return FALSE;
6669 }
6670 
6671 /*=================== operations with many arg.: static proc =================*/
6672 /* must be ordered: first operations for chars (infix ops),
6673  * then alphabetically */
6675 {
6676 #ifdef HAVE_SDB
6677  sdb_show_bp();
6678 #endif
6679  return FALSE;
6680 }
6682 {
6683 #ifdef HAVE_SDB
6684  if(v->Typ()==PROC_CMD)
6685  {
6686  int lineno=0;
6687  if((v->next!=NULL) && (v->next->Typ()==INT_CMD))
6688  {
6689  lineno=(int)(long)v->next->Data();
6690  }
6691  return sdb_set_breakpoint(v->Name(),lineno);
6692  }
6693  return TRUE;
6694 #else
6695  return FALSE;
6696 #endif
6697 }
6699 {
6700  return iiExprArith1(res,v,iiOp);
6701 }
6703 {
6704  leftv v=u->next;
6705  u->next=NULL;
6706  BOOLEAN b=iiExprArith2(res,u,iiOp,v, (iiOp > 255));
6707  u->next=v;
6708  return b;
6709 }
6711 {
6712  leftv v = u->next;
6713  leftv w = v->next;
6714  u->next = NULL;
6715  v->next = NULL;
6716  BOOLEAN b = iiExprArith3(res, iiOp, u, v, w);
6717  u->next = v;
6718  v->next = w;
6719  return b;
6720 }
6721 
6723 {
6725  if (iiCheckTypes(v,t))
6726  return TRUE;
6727  idhdl c=(idhdl)v->next->next->data;
6728  if (v->next->next->next->rtyp!=IDHDL) return TRUE;
6729  idhdl m=(idhdl)v->next->next->next->data;
6730  idDelete((ideal *)&(c->data.uideal));
6731  idDelete((ideal *)&(m->data.uideal));
6732  mp_Coef2((poly)v->Data(),(poly)v->next->Data(),
6733  (matrix *)&(c->data.umatrix),(matrix *)&(m->data.umatrix),currRing);
6734  return FALSE;
6735 }
6736 
6738 { // may have 3 or 4 arguments
6739  leftv v1=v;
6740  leftv v2=v1->next;
6741  leftv v3=v2->next;
6742  leftv v4=v3->next;
6743  assumeStdFlag(v2);
6744 
6745  int i1=iiTestConvert(v1->Typ(),MODUL_CMD);
6746  int i2=iiTestConvert(v2->Typ(),MODUL_CMD);
6747 
6748  if((i1==0)||(i2==0)
6749  ||(v3->Typ()!=INT_CMD)||((v4!=NULL)&&(v4->Typ()!=INTVEC_CMD)))
6750  {
6751  WarnS("<module>,<module>,<int>[,<intvec>] expected!");
6752  return TRUE;
6753  }
6754 
6755  sleftv w1,w2;
6756  iiConvert(v1->Typ(),MODUL_CMD,i1,v1,&w1);
6757  iiConvert(v2->Typ(),MODUL_CMD,i2,v2,&w2);
6758  ideal P=(ideal)w1.Data();
6759  ideal Q=(ideal)w2.Data();
6760 
6761  int n=(int)(long)v3->Data();
6762  short *w=NULL;
6763  if(v4!=NULL)
6764  {
6765  w = iv2array((intvec *)v4->Data(),currRing);
6766  short * w0 = w + 1;
6767  int i = currRing->N;
6768  while( (i > 0) && ((*w0) > 0) )
6769  {
6770  w0++;
6771  i--;
6772  }
6773  if(i>0)
6774  WarnS("not all weights are positive!");
6775  }
6776 
6777  matrix T;
6778  ideal R;
6779  idLiftW(P,Q,n,T,R,w);
6780 
6781  w1.CleanUp();
6782  w2.CleanUp();
6783  if(w!=NULL)
6784  omFreeSize( (ADDRESS)w, (rVar(currRing)+1)*sizeof(short) );
6785 
6787  L->Init(2);
6788  L->m[1].rtyp=v1->Typ();
6789  if(v1->Typ()==POLY_CMD||v1->Typ()==VECTOR_CMD)
6790  {
6791  if(v1->Typ()==POLY_CMD)
6792  p_Shift(&R->m[0],-1,currRing);
6793  L->m[1].data=(void *)R->m[0];
6794  R->m[0]=NULL;
6795  idDelete(&R);
6796  }
6797  else if(v1->Typ()==IDEAL_CMD||v1->Typ()==MATRIX_CMD)
6798  L->m[1].data=(void *)id_Module2Matrix(R,currRing);
6799  else
6800  {
6801  L->m[1].rtyp=MODUL_CMD;
6802  L->m[1].data=(void *)R;
6803  }
6804  L->m[0].rtyp=MATRIX_CMD;
6805  L->m[0].data=(char *)T;
6806 
6807  res->data=L;
6808  res->rtyp=LIST_CMD;
6809 
6810  return FALSE;
6811 }
6812 
6813 //BOOLEAN jjDISPATCH(leftv res, leftv v)
6814 //{
6815 // WerrorS("`dispatch`: not implemented");
6816 // return TRUE;
6817 //}
6818 
6819 //static BOOLEAN jjEXPORTTO_M(leftv res, leftv u)
6820 //{
6821 // int l=u->listLength();
6822 // if (l<2) return TRUE;
6823 // BOOLEAN b;
6824 // leftv v=u->next;
6825 // leftv zz=v;
6826 // leftv z=zz;
6827 // u->next=NULL;
6828 // do
6829 // {
6830 // leftv z=z->next;
6831 // b=iiExprArith2(res,u,iiOp,z, (iiOp > 255));
6832 // if (b) break;
6833 // } while (z!=NULL);
6834 // u->next=zz;
6835 // return b;
6836 //}
6838 {
6839  int s=1;
6840  leftv h=v;
6841  if (h!=NULL) s=exprlist_length(h);
6842  ideal id=idInit(s,1);
6843  int rank=1;
6844  int i=0;
6845  poly p;
6846  while (h!=NULL)
6847  {
6848  switch(h->Typ())
6849  {
6850  case POLY_CMD:
6851  {
6852  p=(poly)h->CopyD(POLY_CMD);
6853  break;
6854  }
6855  case INT_CMD:
6856  {
6857  number n=nInit((int)(long)h->Data());
6858  if (!nIsZero(n))
6859  {
6860  p=pNSet(n);
6861  }
6862  else
6863  {
6864  p=NULL;
6865  nDelete(&n);
6866  }
6867  break;
6868  }
6869  case BIGINT_CMD:
6870  {
6871  number b=(number)h->Data();
6873  if (nMap==NULL) return TRUE;
6874  number n=nMap(b,coeffs_BIGINT,currRing->cf);
6875  if (!nIsZero(n))
6876  {
6877  p=pNSet(n);
6878  }
6879  else
6880  {
6881  p=NULL;
6882  nDelete(&n);
6883  }
6884  break;
6885  }
6886  case NUMBER_CMD:
6887  {
6888  number n=(number)h->CopyD(NUMBER_CMD);
6889  if (!nIsZero(n))
6890  {
6891  p=pNSet(n);
6892  }
6893  else
6894  {
6895  p=NULL;
6896  nDelete(&n);
6897  }
6898  break;
6899  }
6900  case VECTOR_CMD:
6901  {
6902  p=(poly)h->CopyD(VECTOR_CMD);
6903  if (iiOp!=MODUL_CMD)
6904  {
6905  idDelete(&id);
6906  pDelete(&p);
6907  return TRUE;
6908  }
6909  rank=si_max(rank,(int)pMaxComp(p));
6910  break;
6911  }
6912  default:
6913  {
6914  idDelete(&id);
6915  return TRUE;
6916  }
6917  }
6918  if ((iiOp==MODUL_CMD)&&(p!=NULL)&&(pGetComp(p)==0))
6919  {
6920  pSetCompP(p,1);
6921  }
6922  id->m[i]=p;
6923  i++;
6924  h=h->next;
6925  }
6926  id->rank=rank;
6927  res->data=(char *)id;
6928  return FALSE;
6929 }
6931 {
6932  ring r=(ring)u->Data();
6933  leftv v=u->next;
6934  leftv perm_var_l=v->next;
6935  leftv perm_par_l=v->next->next;
6936  if ((perm_var_l->Typ()!=INTVEC_CMD)
6937  ||((perm_par_l!=NULL)&&(perm_par_l->Typ()!=INTVEC_CMD))
6938  ||((u->Typ()!=RING_CMD)&&(u->Typ()!=QRING_CMD)))
6939  {
6940  WerrorS("fetch(<ring>,<name>[,<intvec>[,<intvec>])");
6941  return TRUE;
6942  }
6943  intvec *perm_var_v=(intvec*)perm_var_l->Data();
6944  intvec *perm_par_v=NULL;
6945  if (perm_par_l!=NULL)
6946  perm_par_v=(intvec*)perm_par_l->Data();
6947  idhdl w;
6948  nMapFunc nMap;
6949 
6950  if ((w=r->idroot->get(v->Name(),myynest))!=NULL)
6951  {
6952  int *perm=NULL;
6953  int *par_perm=NULL;
6954  int par_perm_size=0;
6955  BOOLEAN bo;
6956  if ((nMap=n_SetMap(r->cf,currRing->cf))==NULL)
6957  {
6958  // Allow imap/fetch to be make an exception only for:
6959  if ( (rField_is_Q_a(r) && // Q(a..) -> Q(a..) || Q || Zp || Zp(a)
6962  ||
6963  (rField_is_Zp_a(r) && // Zp(a..) -> Zp(a..) || Zp
6964  (rField_is_Zp(currRing, r->cf->ch) ||
6965  rField_is_Zp_a(currRing, r->cf->ch))) )
6966  {
6967  par_perm_size=rPar(r);
6968  }
6969  else
6970  {
6971  goto err_fetch;
6972  }
6973  }
6974  else
6975  par_perm_size=rPar(r);
6976  perm=(int *)omAlloc0((rVar(r)+1)*sizeof(int));
6977  if (par_perm_size!=0)
6978  par_perm=(int *)omAlloc0(par_perm_size*sizeof(int));
6979  int i;
6980  if (perm_par_l==NULL)
6981  {
6982  if (par_perm_size!=0)
6983  for(i=si_min(rPar(r),rPar(currRing))-1;i>=0;i--) par_perm[i]=-(i+1);
6984  }
6985  else
6986  {
6987  if (par_perm_size==0) WarnS("source ring has no parameters");
6988  else
6989  {
6990  for(i=rPar(r)-1;i>=0;i--)
6991  {
6992  if (i<perm_par_v->length()) par_perm[i]=(*perm_par_v)[i];
6993  if ((par_perm[i]<-rPar(currRing))
6994  || (par_perm[i]>rVar(currRing)))
6995  {
6996  Warn("invalid entry for par %d: %d\n",i,par_perm[i]);
6997  par_perm[i]=0;
6998  }
6999  }
7000  }
7001  }
7002  for(i=rVar(r)-1;i>=0;i--)
7003  {
7004  if (i<perm_var_v->length()) perm[i+1]=(*perm_var_v)[i];
7005  if ((perm[i]<-rPar(currRing))
7006  || (perm[i]>rVar(currRing)))
7007  {
7008  Warn("invalid entry for var %d: %d\n",i,perm[i]);
7009  perm[i]=0;
7010  }
7011  }
7012  if (BVERBOSE(V_IMAP))
7013  {
7014  for(i=1;i<=si_min(rVar(r),rVar(currRing));i++)
7015  {
7016  if (perm[i]>0)
7017  Print("// var nr %d: %s -> var %s\n",i,r->names[i-1],currRing->names[perm[i]-1]);
7018  else if (perm[i]<0)
7019  Print("// var nr %d: %s -> par %s\n",i,r->names[i-1],rParameter(currRing)[-perm[i]-1]);
7020  }
7021  for(i=1;i<=si_min(rPar(r),rPar(currRing));i++) // possibly empty loop
7022  {
7023  if (par_perm[i-1]<0)
7024  Print("// par nr %d: %s -> par %s\n",
7025  i,rParameter(r)[i-1],rParameter(currRing)[-par_perm[i-1]-1]);
7026  else if (par_perm[i-1]>0)
7027  Print("// par nr %d: %s -> var %s\n",
7028  i,rParameter(r)[i-1],currRing->names[par_perm[i-1]-1]);
7029  }
7030  }
7031  if (IDTYP(w)==ALIAS_CMD) w=(idhdl)IDDATA(w);
7032  sleftv tmpW;
7033  memset(&tmpW,0,sizeof(sleftv));
7034  tmpW.rtyp=IDTYP(w);
7035  tmpW.data=IDDATA(w);
7036  if ((bo=maApplyFetch(IMAP_CMD,NULL,res,&tmpW, r,
7037  perm,par_perm,par_perm_size,nMap)))
7038  {
7039  Werror("cannot map %s of type %s(%d)",v->name, Tok2Cmdname(w->typ),w->typ);
7040  }
7041  if (perm!=NULL)
7042  omFreeSize((ADDRESS)perm,(rVar(r)+1)*sizeof(int));
7043  if (par_perm!=NULL)
7044  omFreeSize((ADDRESS)par_perm,par_perm_size*sizeof(int));
7045  return bo;
7046  }
7047  else
7048  {
7049  Werror("identifier %s not found in %s",v->Fullname(),u->Fullname());
7050  }
7051  return TRUE;
7052 err_fetch:
7053  Werror("no identity map from %s (%s -> %s)",u->Fullname(),
7054  nCoeffString(r->cf),
7055  nCoeffString(currRing->cf));
7056  return TRUE;
7057 }
7059 {
7060  leftv h=v;
7061  int l=v->listLength();
7062  resolvente r=(resolvente)omAlloc0(l*sizeof(ideal));
7063  BOOLEAN *copied=(BOOLEAN *)omAlloc0(l*sizeof(BOOLEAN));
7064  int t=0;
7065  // try to convert to IDEAL_CMD
7066  while (h!=NULL)
7067  {
7068  if (iiTestConvert(h->Typ(),IDEAL_CMD)!=0)
7069  {
7070  t=IDEAL_CMD;
7071  }
7072  else break;
7073  h=h->next;
7074  }
7075  // if failure, try MODUL_CMD
7076  if (t==0)
7077  {
7078  h=v;
7079  while (h!=NULL)
7080  {
7081  if (iiTestConvert(h->Typ(),MODUL_CMD)!=0)
7082  {
7083  t=MODUL_CMD;
7084  }
7085  else break;
7086  h=h->next;
7087  }
7088  }
7089  // check for success in converting
7090  if (t==0)
7091  {
7092  WerrorS("cannot convert to ideal or module");
7093  return TRUE;
7094  }
7095  // call idMultSect
7096  h=v;
7097  int i=0;
7098  sleftv tmp;
7099  while (h!=NULL)
7100  {
7101  if (h->Typ()==t)
7102  {
7103  r[i]=(ideal)h->Data(); /*no copy*/
7104  h=h->next;
7105  }
7106  else if(iiConvert(h->Typ(),t,iiTestConvert(h->Typ(),t),h,&tmp))
7107  {
7108  omFreeSize((ADDRESS)copied,l*sizeof(BOOLEAN));
7109  omFreeSize((ADDRESS)r,l*sizeof(ideal));
7110  Werror("cannot convert arg. %d to %s",i+1,Tok2Cmdname(t));
7111  return TRUE;
7112  }
7113  else
7114  {
7115  r[i]=(ideal)tmp.Data(); /*now it's a copy*/
7116  copied[i]=TRUE;
7117  h=tmp.next;
7118  }
7119  i++;
7120  }
7121  res->rtyp=t;
7122  res->data=(char *)idMultSect(r,i);
7123  while(i>0)
7124  {
7125  i--;
7126  if (copied[i]) idDelete(&(r[i]));
7127  }
7128  omFreeSize((ADDRESS)copied,l*sizeof(BOOLEAN));
7129  omFreeSize((ADDRESS)r,l*sizeof(ideal));
7130  return FALSE;
7131 }
7133 {
7134  /* computation of the inverse of a quadratic matrix A
7135  using the L-U-decomposition of A;
7136  There are two valid parametrisations:
7137  1) exactly one argument which is just the matrix A,
7138  2) exactly three arguments P, L, U which already
7139  realise the L-U-decomposition of A, that is,
7140  P * A = L * U, and P, L, and U satisfy the
7141  properties decribed in method 'jjLU_DECOMP';
7142  see there;
7143  If A is invertible, the list [1, A^(-1)] is returned,
7144  otherwise the list [0] is returned. Thus, the user may
7145  inspect the first entry of the returned list to see
7146  whether A is invertible. */
7147  matrix iMat; int invertible;
7148  short t1[]={1,MATRIX_CMD};
7149  short t2[]={3,MATRIX_CMD,MATRIX_CMD,MATRIX_CMD};
7150  if (iiCheckTypes(v,t1))
7151  {
7152  matrix aMat = (matrix)v->Data();
7153  int rr = aMat->rows();
7154  int cc = aMat->cols();
7155  if (rr != cc)
7156  {
7157  Werror("given matrix (%d x %d) is not quadratic, hence not invertible", rr, cc);
7158  return TRUE;
7159  }
7160  if (!idIsConstant((ideal)aMat))
7161  {
7162  WerrorS("matrix must be constant");
7163  return TRUE;
7164  }
7165  invertible = luInverse(aMat, iMat);
7166  }
7167  else if (iiCheckTypes(v,t2))
7168  {
7169  matrix pMat = (matrix)v->Data();
7170  matrix lMat = (matrix)v->next->Data();
7171  matrix uMat = (matrix)v->next->next->Data();
7172  int rr = uMat->rows();
7173  int cc = uMat->cols();
7174  if (rr != cc)
7175  {
7176  Werror("third matrix (%d x %d) is not quadratic, hence not invertible",
7177  rr, cc);
7178  return TRUE;
7179  }
7180  if (!idIsConstant((ideal)pMat)
7181  || (!idIsConstant((ideal)lMat))
7182  || (!idIsConstant((ideal)uMat))
7183  )
7184  {
7185  WerrorS("matricesx must be constant");
7186  return TRUE;
7187  }
7188  invertible = luInverseFromLUDecomp(pMat, lMat, uMat, iMat);
7189  }
7190  else
7191  {
7192  Werror("expected either one or three matrices");
7193  return TRUE;
7194  }
7195 
7196  /* build the return structure; a list with either one or two entries */
7198  if (invertible)
7199  {
7200  ll->Init(2);
7201  ll->m[0].rtyp=INT_CMD; ll->m[0].data=(void *)(long)invertible;
7202  ll->m[1].rtyp=MATRIX_CMD; ll->m[1].data=(void *)iMat;
7203  }
7204  else
7205  {
7206  ll->Init(1);
7207  ll->m[0].rtyp=INT_CMD; ll->m[0].data=(void *)(long)invertible;
7208  }
7209 
7210  res->data=(char*)ll;
7211  return FALSE;
7212 }
7214 {
7215  /* for solving a linear equation system A * x = b, via the
7216  given LU-decomposition of the matrix A;
7217  There is one valid parametrisation:
7218  1) exactly four arguments P, L, U, b;
7219  P, L, and U realise the L-U-decomposition of A, that is,
7220  P * A = L * U, and P, L, and U satisfy the
7221  properties decribed in method 'jjLU_DECOMP';
7222  see there;
7223  b is the right-hand side vector of the equation system;
7224  The method will return a list of either 1 entry or three entries:
7225  1) [0] if there is no solution to the system;
7226  2) [1, x, H] if there is at least one solution;
7227  x is any solution of the given linear system,
7228  H is the matrix with column vectors spanning the homogeneous
7229  solution space.
7230  The method produces an error if matrix and vector sizes do not fit. */
7231  short t[]={4,MATRIX_CMD,MATRIX_CMD,MATRIX_CMD,MATRIX_CMD};
7232  if (!iiCheckTypes(v,t))
7233  {
7234  WerrorS("expected exactly three matrices and one vector as input");
7235  return TRUE;
7236  }
7237  matrix pMat = (matrix)v->Data();
7238  matrix lMat = (matrix)v->next->Data();
7239  matrix uMat = (matrix)v->next->next->Data();
7240  matrix bVec = (matrix)v->next->next->next->Data();
7241  matrix xVec; int solvable; matrix homogSolSpace;
7242  if (pMat->rows() != pMat->cols())
7243  {
7244  Werror("first matrix (%d x %d) is not quadratic",
7245  pMat->rows(), pMat->cols());
7246  return TRUE;
7247  }
7248  if (lMat->rows() != lMat->cols())
7249  {
7250  Werror("second matrix (%d x %d) is not quadratic",
7251  lMat->rows(), lMat->cols());
7252  return TRUE;
7253  }
7254  if (lMat->rows() != uMat->rows())
7255  {
7256  Werror("second matrix (%d x %d) and third matrix (%d x %d) do not fit",
7257  lMat->rows(), lMat->cols(), uMat->rows(), uMat->cols());
7258  return TRUE;
7259  }
7260  if (uMat->rows() != bVec->rows())
7261  {
7262  Werror("third matrix (%d x %d) and vector (%d x 1) do not fit",
7263  uMat->rows(), uMat->cols(), bVec->rows());
7264  return TRUE;
7265  }
7266  if (!idIsConstant((ideal)pMat)
7267  ||(!idIsConstant((ideal)lMat))
7268  ||(!idIsConstant((ideal)uMat))
7269  )
7270  {
7271  WerrorS("matrices must be constant");
7272  return TRUE;
7273  }
7274  solvable = luSolveViaLUDecomp(pMat, lMat, uMat, bVec, xVec, homogSolSpace);
7275 
7276  /* build the return structure; a list with either one or three entries */
7278  if (solvable)
7279  {
7280  ll->Init(3);
7281  ll->m[0].rtyp=INT_CMD; ll->m[0].data=(void *)(long)solvable;
7282  ll->m[1].rtyp=MATRIX_CMD; ll->m[1].data=(void *)xVec;
7283  ll->m[2].rtyp=MATRIX_CMD; ll->m[2].data=(void *)homogSolSpace;
7284  }
7285  else
7286  {
7287  ll->Init(1);
7288  ll->m[0].rtyp=INT_CMD; ll->m[0].data=(void *)(long)solvable;
7289  }
7290 
7291  res->data=(char*)ll;
7292  return FALSE;
7293 }
7295 {
7296  int i=0;
7297  leftv h=v;
7298  if (h!=NULL) i=exprlist_length(h);
7299  intvec *iv=new intvec(i);
7300  i=0;
7301  while (h!=NULL)
7302  {
7303  if(h->Typ()==INT_CMD)
7304  {
7305  (*iv)[i]=(int)(long)h->Data();
7306  }
7307  else if (h->Typ()==INTVEC_CMD)
7308  {
7309  intvec *ivv=(intvec*)h->Data();
7310  for(int j=0;j<ivv->length();j++,i++)
7311  {
7312  (*iv)[i]=(*ivv)[j];
7313  }
7314  i--;
7315  }
7316  else
7317  {
7318  delete iv;
7319  return TRUE;
7320  }
7321  i++;
7322  h=h->next;
7323  }
7324  res->data=(char *)iv;
7325  return FALSE;
7326 }
7327 static BOOLEAN jjJET4(leftv res, leftv u)
7328 {
7329  short t1[]={4,POLY_CMD,POLY_CMD,POLY_CMD,INTVEC_CMD};
7330  short t2[]={4,VECTOR_CMD,POLY_CMD,POLY_CMD,INTVEC_CMD};
7331  short t3[]={4,IDEAL_CMD,MATRIX_CMD,INT_CMD,INTVEC_CMD};
7332  short t4[]={4,MODUL_CMD,MATRIX_CMD,INT_CMD,INTVEC_CMD};
7333  leftv u1=u;
7334  leftv u2=u1->next;
7335  leftv u3=u2->next;
7336  leftv u4=u3->next;
7337  if (iiCheckTypes(u,t1)||iiCheckTypes(u,t2))
7338  {
7339  if(!pIsUnit((poly)u2->Data()))
7340  {
7341  WerrorS("2nd argument must be a unit");
7342  return TRUE;
7343  }
7344  res->rtyp=u1->Typ();
7345  res->data=(char*)pSeries((int)(long)u3->Data(),pCopy((poly)u1->Data()),
7346  pCopy((poly)u2->Data()),(intvec*)u4->Data());
7347  return FALSE;
7348  }
7349  else
7350  if (iiCheckTypes(u,t3)||iiCheckTypes(u,t4))
7351  {
7352  if(!mp_IsDiagUnit((matrix)u2->Data(), currRing))
7353  {
7354  WerrorS("2nd argument must be a diagonal matrix of units");
7355  return TRUE;
7356  }
7357  res->rtyp=u1->Typ();
7358  res->data=(char*)idSeries(
7359  (int)(long)u3->Data(),
7360  idCopy((ideal)u1->Data()),
7361  mp_Copy((matrix)u2->Data(), currRing),
7362  (intvec*)u4->Data()
7363  );
7364  return FALSE;
7365  }
7366  else
7367  {
7368  Werror("%s(`poly`,`poly`,`int`,`intvec`) exppected",
7369  Tok2Cmdname(iiOp));
7370  return TRUE;
7371  }
7372 }
7374 {
7375  if ((yyInRingConstruction)
7376  && ((strcmp(u->Name(),"real")==0) || (strcmp(u->Name(),"complex")==0)))
7377  {
7378  memcpy(res,u,sizeof(sleftv));
7379  memset(u,0,sizeof(sleftv));
7380  return FALSE;
7381  }
7382  leftv v=u->next;
7383  BOOLEAN b;
7384  if(v==NULL)
7385  b=iiExprArith1(res,u,iiOp);
7386  else
7387  {
7388  u->next=NULL;
7389  b=iiExprArith2(res,u,iiOp,v);
7390  u->next=v;
7391  }
7392  return b;
7393 }
7395 {
7396  int sl=0;
7397  if (v!=NULL) sl = v->listLength();
7398  lists L;
7399  if((sl==1)&&(v->Typ()==RESOLUTION_CMD))
7400  {
7401  int add_row_shift = 0;
7402  intvec *weights=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
7403  if (weights!=NULL) add_row_shift=weights->min_in();
7404  L=syConvRes((syStrategy)v->Data(),FALSE,add_row_shift);
7405  }
7406  else
7407  {
7409  leftv h=NULL;
7410  int i;
7411  int rt;
7412 
7413  L->Init(sl);
7414  for (i=0;i<sl;i++)
7415  {
7416  if (h!=NULL)
7417  { /* e.g. not in the first step:
7418  * h is the pointer to the old sleftv,
7419  * v is the pointer to the next sleftv
7420  * (in this moment) */
7421  h->next=v;
7422  }
7423  h=v;
7424  v=v->next;
7425  h->next=NULL;
7426  rt=h->Typ();
7427  if (rt==0)
7428  {
7429  L->Clean();
7430  Werror("`%s` is undefined",h->Fullname());
7431  return TRUE;
7432  }
7433  if ((rt==RING_CMD)||(rt==QRING_CMD))
7434  {
7435  L->m[i].rtyp=rt; L->m[i].data=h->Data();
7436  ((ring)L->m[i].data)->ref++;
7437  }
7438  else
7439  L->m[i].Copy(h);
7440  }
7441  }
7442  res->data=(char *)L;
7443  return FALSE;
7444 }
7446 {
7447  res->data=(void *)ipNameList(IDROOT);
7448  return FALSE;
7449 }
7451 {
7452  if(v==NULL)
7453  {
7454  res->data=(char *)showOption();
7455  return FALSE;
7456  }
7457  res->rtyp=NONE;
7458  return setOption(res,v);
7459 }
7461 {
7462  leftv u1=u;
7463  leftv u2=u1->next;
7464  leftv u3=u2->next;
7465  leftv u4=u3->next;
7466  if((u3->Typ()==INT_CMD)&&(u4->Typ()==INTVEC_CMD))
7467  {
7468  int save_d=Kstd1_deg;
7469  Kstd1_deg=(int)(long)u3->Data();
7470  kModW=(intvec *)u4->Data();
7471  BITSET save2;
7472  SI_SAVE_OPT2(save2);
7474  u2->next=NULL;
7475  BOOLEAN r=jjCALL2ARG(res,u);
7476  kModW=NULL;
7477  Kstd1_deg=save_d;
7478  SI_RESTORE_OPT2(save2);
7479  u->next->next=u3;
7480  return r;
7481  }
7482  else
7483  if((u1->Typ()==IDEAL_CMD)&&(u2->Typ()==MATRIX_CMD)&&(u3->Typ()==IDEAL_CMD)&&
7484  (u4->Typ()==INT_CMD))
7485  {
7486  assumeStdFlag(u3);
7487  if(!mp_IsDiagUnit((matrix)u2->Data(), currRing))
7488  {
7489  WerrorS("2nd argument must be a diagonal matrix of units");
7490  return TRUE;
7491  }
7492  res->rtyp=IDEAL_CMD;
7493  res->data=(char*)redNF(
7494  idCopy((ideal)u3->Data()),
7495  idCopy((ideal)u1->Data()),
7496  mp_Copy((matrix)u2->Data(), currRing),
7497  (int)(long)u4->Data()
7498  );
7499  return FALSE;
7500  }
7501  else
7502  if((u1->Typ()==POLY_CMD)&&(u2->Typ()==POLY_CMD)&&(u3->Typ()==IDEAL_CMD)&&
7503  (u4->Typ()==INT_CMD))
7504  {
7505  assumeStdFlag(u3);
7506  if(!pIsUnit((poly)u2->Data()))
7507  {
7508  WerrorS("2nd argument must be a unit");
7509  return TRUE;
7510  }
7511  res->rtyp=POLY_CMD;
7512  res->data=(char*)redNF(idCopy((ideal)u3->Data()),pCopy((poly)u1->Data()),
7513  pCopy((poly)u2->Data()),(int)(long)u4->Data());
7514  return FALSE;
7515  }
7516  else
7517  {
7518  Werror("%s(`poly`,`ideal`,`int`,`intvec`) expected",Tok2Cmdname(iiOp));
7519  return TRUE;
7520  }
7521 }
7523 {
7524  leftv u1=u;
7525  leftv u2=u1->next;
7526  leftv u3=u2->next;
7527  leftv u4=u3->next;
7528  leftv u5=u4->next;
7529  if((u1->Typ()==IDEAL_CMD)&&(u2->Typ()==MATRIX_CMD)&&(u3->Typ()==IDEAL_CMD)&&
7530  (u4->Typ()==INT_CMD)&&(u5->Typ()==INTVEC_CMD))
7531  {
7532  assumeStdFlag(u3);
7533  if(!mp_IsDiagUnit((matrix)u2->Data(), currRing))
7534  {
7535  WerrorS("2nd argument must be a diagonal matrix of units");
7536  return TRUE;
7537  }
7538  res->rtyp=IDEAL_CMD;
7539  res->data=(char*)redNF(
7540  idCopy((ideal)u3->Data()),
7541  idCopy((ideal)u1->Data()),
7542  mp_Copy((matrix)u2->Data(),currRing),
7543  (int)(long)u4->Data(),
7544  (intvec*)u5->Data()
7545  );
7546  return FALSE;
7547  }
7548  else
7549  if((u1->Typ()==POLY_CMD)&&(u2->Typ()==POLY_CMD)&&(u3->Typ()==IDEAL_CMD)&&
7550  (u4->Typ()==INT_CMD)&&(u5->Typ()==INTVEC_CMD))
7551  {
7552  assumeStdFlag(u3);
7553  if(!pIsUnit((poly)u2->Data()))
7554  {
7555  WerrorS("2nd argument must be a unit");
7556  return TRUE;
7557  }
7558  res->rtyp=POLY_CMD;
7559  res->data=(char*)redNF(idCopy((ideal)u3->Data()),pCopy((poly)u1->Data()),
7560  pCopy((poly)u2->Data()),
7561  (int)(long)u4->Data(),(intvec*)u5->Data());
7562  return FALSE;
7563  }
7564  else
7565  {
7566  Werror("%s(`ideal`,`ideal`,`matrix`,`int`,`intvec`) exppected",
7567  Tok2Cmdname(iiOp));
7568  return TRUE;
7569  }
7570 }
7572 {
7573  int i=1;
7574  int nCount = (sArithBase.nCmdUsed-1)/3;
7575  if((3*nCount)<sArithBase.nCmdUsed) nCount++;
7576  //Print("CMDS: %d/%d\n", sArithBase.nCmdUsed,
7577  // sArithBase.nCmdAllocated);
7578  for(i=0; i<nCount; i++)
7579  {
7580  Print("%-20s",sArithBase.sCmds[i+1].name);
7581  if(i+1+nCount<sArithBase.nCmdUsed)
7582  Print("%-20s",sArithBase.sCmds[i+1+nCount].name);
7583  if(i+1+2*nCount<sArithBase.nCmdUsed)
7584  Print("%-20s",sArithBase.sCmds[i+1+2*nCount].name);
7585  //if ((i%3)==1) PrintLn();
7586  PrintLn();
7587  }
7588  PrintLn();
7590  return FALSE;
7591 }
7593 {
7594  if (v == NULL)
7595  {
7596  res->data = omStrDup("");
7597  return FALSE;
7598  }
7599  int n = v->listLength();
7600  if (n == 1)
7601  {
7602  res->data = v->String();
7603  return FALSE;
7604  }
7605 
7606  char** slist = (char**) omAlloc(n*sizeof(char*));
7607  int i, j;
7608 
7609  for (i=0, j=0; i<n; i++, v = v ->next)
7610  {
7611  slist[i] = v->String();
7612  assume(slist[i] != NULL);
7613  j+=strlen(slist[i]);
7614  }
7615  char* s = (char*) omAlloc((j+1)*sizeof(char));
7616  *s='\0';
7617  for (i=0;i<n;i++)
7618  {
7619  strcat(s, slist[i]);
7620  omFree(slist[i]);
7621  }
7622  omFreeSize(slist, n*sizeof(char*));
7623  res->data = s;
7624  return FALSE;
7625 }
7627 {
7628  do
7629  {
7630  if (v->Typ()!=INT_CMD)
7631  return TRUE;
7632  test_cmd((int)(long)v->Data());
7633  v=v->next;
7634  }
7635  while (v!=NULL);
7636  return FALSE;
7637 }
7638 
7639 #if defined(__alpha) && !defined(linux)
7640 extern "C"
7641 {
7642  void usleep(unsigned long usec);
7643 };
7644 #endif
7646 {
7647  /* compute two factors of h(x,y) modulo x^(d+1) in K[[x]][y],
7648  see a detailed documentation in /kernel/linear_algebra/linearAlgebra.h
7649 
7650  valid argument lists:
7651  - (poly h, int d),
7652  - (poly h, int d, poly f0, poly g0), optional: factors of h(0,y),
7653  - (poly h, int d, int xIndex, int yIndex), optional: indices of vars x & y
7654  in list of ring vars,
7655  - (poly h, int d, poly f0, poly g0, int xIndex, int yIndec),
7656  optional: all 4 optional args
7657  (The defaults are xIndex = 1, yIndex = 2, f0 and g0 polynomials as found
7658  by singclap_factorize and h(0, y)
7659  has exactly two distinct monic factors [possibly with exponent > 1].)
7660  result:
7661  - list with the two factors f and g such that
7662  h(x,y) = f(x,y)*g(x,y) mod x^(d+1) */
7663 
7664  poly h = NULL;
7665  int d = 1;
7666  poly f0 = NULL;
7667  poly g0 = NULL;
7668  int xIndex = 1; /* default index if none provided */
7669  int yIndex = 2; /* default index if none provided */
7670 
7671  leftv u = v; int factorsGiven = 0;
7672  if ((u == NULL) || (u->Typ() != POLY_CMD))
7673  {
7674  WerrorS("expected arguments (poly, int [, poly, poly] [, int, int])");
7675  return TRUE;
7676  }
7677  else h = (poly)u->Data();
7678  u = u->next;
7679  if ((u == NULL) || (u->Typ() != INT_CMD))
7680  {
7681  WerrorS("expected arguments (poly, int [, poly, poly] [, int, int])");
7682  return TRUE;
7683  }
7684  else d = (int)(long)u->Data();
7685  u = u->next;
7686  if ((u != NULL) && (u->Typ() == POLY_CMD))
7687  {
7688  if ((u->next == NULL) || (u->next->Typ() != POLY_CMD))
7689  {
7690  WerrorS("expected arguments (poly, int [, poly, poly] [, int, int])");
7691  return TRUE;
7692  }
7693  else
7694  {
7695  f0 = (poly)u->Data();
7696  g0 = (poly)u->next->Data();
7697  factorsGiven = 1;
7698  u = u->next->next;
7699  }
7700  }
7701  if ((u != NULL) && (u->Typ() == INT_CMD))
7702  {
7703  if ((u->next == NULL) || (u->next->Typ() != INT_CMD))
7704  {
7705  WerrorS("expected arguments (poly, int [, poly, poly] [, int, int])");
7706  return TRUE;
7707  }
7708  else
7709  {
7710  xIndex = (int)(long)u->Data();
7711  yIndex = (int)(long)u->next->Data();
7712  u = u->next->next;
7713  }
7714  }
7715  if (u != NULL)
7716  {
7717  WerrorS("expected arguments (poly, int [, poly, poly] [, int, int])");
7718  return TRUE;
7719  }
7720 
7721  /* checks for provided arguments */
7722  if (pIsConstant(h) || (factorsGiven && (pIsConstant(f0) || pIsConstant(g0))))
7723  {
7724  WerrorS("expected non-constant polynomial argument(s)");
7725  return TRUE;
7726  }
7727  int n = rVar(currRing);
7728  if ((xIndex < 1) || (n < xIndex))
7729  {
7730  Werror("index for variable x (%d) out of range [1..%d]", xIndex, n);
7731  return TRUE;
7732  }
7733  if ((yIndex < 1) || (n < yIndex))
7734  {
7735  Werror("index for variable y (%d) out of range [1..%d]", yIndex, n);
7736  return TRUE;
7737  }
7738  if (xIndex == yIndex)
7739  {
7740  WerrorS("expected distinct indices for variables x and y");
7741  return TRUE;
7742  }
7743 
7744  /* computation of f0 and g0 if missing */
7745  if (factorsGiven == 0)
7746  {
7747  poly h0 = pSubst(pCopy(h), xIndex, NULL);
7748  intvec* v = NULL;
7749  ideal i = singclap_factorize(h0, &v, 0,currRing);
7750 
7751  ivTest(v);
7752 
7753  if (i == NULL) return TRUE;
7754 
7755  idTest(i);
7756 
7757  if ((v->rows() != 3) || ((*v)[0] =! 1) || (!nIsOne(pGetCoeff(i->m[0]))))
7758  {
7759  WerrorS("expected h(0,y) to have exactly two distinct monic factors");
7760  return TRUE;
7761  }
7762  f0 = pPower(pCopy(i->m[1]), (*v)[1]);
7763  g0 = pPower(pCopy(i->m[2]), (*v)[2]);
7764  idDelete(&i);
7765  }
7766 
7767  poly f; poly g;
7768  henselFactors(xIndex, yIndex, h, f0, g0, d, f, g);
7770  L->Init(2);
7771  L->m[0].rtyp = POLY_CMD; L->m[0].data=(void*)f;
7772  L->m[1].rtyp = POLY_CMD; L->m[1].data=(void*)g;
7773  res->rtyp = LIST_CMD;
7774  res->data = (char*)L;
7775  return FALSE;
7776 }
7778 {
7779  if ((v->Typ() != LINK_CMD) ||
7780  (v->next->Typ() != STRING_CMD) ||
7781  (v->next->next->Typ() != STRING_CMD) ||
7782  (v->next->next->next->Typ() != INT_CMD))
7783  return TRUE;
7784  jjSTATUS3(res, v, v->next, v->next->next);
7785 #if defined(HAVE_USLEEP)
7786  if (((long) res->data) == 0L)
7787  {
7788  int i_s = (int)(long) v->next->next->next->Data();
7789  if (i_s > 0)
7790  {
7791  usleep((int)(long) v->next->next->next->Data());
7792  jjSTATUS3(res, v, v->next, v->next->next);
7793  }
7794  }
7795 #elif defined(HAVE_SLEEP)
7796  if (((int) res->data) == 0)
7797  {
7798  int i_s = (int) v->next->next->next->Data();
7799  if (i_s > 0)
7800  {
7801  si_sleep((is - 1)/1000000 + 1);
7802  jjSTATUS3(res, v, v->next, v->next->next);
7803  }
7804  }
7805 #endif
7806  return FALSE;
7807 }
7809 {
7810  leftv v = u->next; // number of args > 0
7811  if (v==NULL) return TRUE;
7812  leftv w = v->next;
7813  if (w==NULL) return TRUE;
7814  leftv rest = w->next;;
7815 
7816  u->next = NULL;
7817  v->next = NULL;
7818  w->next = NULL;
7819  BOOLEAN b = iiExprArith3(res, iiOp, u, v, w);
7820  if ((rest!=NULL) && (!b))
7821  {
7822  sleftv tmp_res;
7823  leftv tmp_next=res->next;
7824  res->next=rest;
7825  memset(&tmp_res,0,sizeof(tmp_res));
7826  b = iiExprArithM(&tmp_res,res,iiOp);
7827  memcpy(res,&tmp_res,sizeof(tmp_res));
7828  res->next=tmp_next;
7829  }
7830  u->next = v;
7831  v->next = w;
7832  // rest was w->next, but is already cleaned
7833  return b;
7834 }
7835 static BOOLEAN jjQRDS(leftv res, leftv INPUT)
7836 {
7837  if ((INPUT->Typ() != MATRIX_CMD) ||
7838  (INPUT->next->Typ() != NUMBER_CMD) ||
7839  (INPUT->next->next->Typ() != NUMBER_CMD) ||
7840  (INPUT->next->next->next->Typ() != NUMBER_CMD))
7841  {
7842  WerrorS("expected (matrix, number, number, number) as arguments");
7843  return TRUE;
7844  }
7845  leftv u = INPUT; leftv v = u->next; leftv w = v->next; leftv x = w->next;
7846  res->data = (char *)qrDoubleShift((matrix)(u->Data()),
7847  (number)(v->Data()),
7848  (number)(w->Data()),
7849  (number)(x->Data()));
7850  return FALSE;
7851 }
7852 static BOOLEAN jjSTD_HILB_WP(leftv res, leftv INPUT)
7853 { ideal result;
7854  leftv u = INPUT; /* an ideal, weighted homogeneous and standard */
7855  leftv v = u->next; /* one additional polynomial or ideal */
7856  leftv h = v->next; /* Hilbert vector */
7857  leftv w = h->next; /* weight vector */
7858  assumeStdFlag(u);
7859  ideal i1=(ideal)(u->Data());
7860  ideal i0;
7861  if (((u->Typ()!=IDEAL_CMD)&&(u->Typ()!=MODUL_CMD))
7862  || (h->Typ()!=INTVEC_CMD)
7863  || (w->Typ()!=INTVEC_CMD))
7864  {
7865  WerrorS("expected `std(`ideal/module`,`poly/vector`,`intvec`,`intvec`)");
7866  return TRUE;
7867  }
7868  intvec *vw=(intvec *)w->Data(); // weights of vars
7869  /* merging std_hilb_w and std_1 */
7870  if (vw->length()!=currRing->N)
7871  {
7872  Werror("%d weights for %d variables",vw->length(),currRing->N);
7873  return TRUE;
7874  }
7875  int r=v->Typ();
7876  BOOLEAN cleanup_i0=FALSE;
7877  if ((r==POLY_CMD) ||(r==VECTOR_CMD))
7878  {
7879  i0=idInit(1,i1->rank);
7880  i0->m[0]=(poly)v->Data();
7881  cleanup_i0=TRUE;
7882  }
7883  else if (r==IDEAL_CMD)/* IDEAL */
7884  {
7885  i0=(ideal)v->Data();
7886  }
7887  else
7888  {
7889  WerrorS("expected `std(`ideal/module`,`poly/vector`,`intvec`,`intvec`)");
7890  return TRUE;
7891  }
7892  int ii0=idElem(i0);
7893  i1 = idSimpleAdd(i1,i0);
7894  if (cleanup_i0)
7895  {
7896  memset(i0->m,0,sizeof(poly)*IDELEMS(i0));
7897  idDelete(&i0);
7898  }
7899  intvec *ww=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
7900  tHomog hom=testHomog;
7901  /* u_id from jjSTD_W is now i1 as in jjSTD_1 */
7902  if (ww!=NULL)
7903  {
7904  if (!idTestHomModule(i1,currRing->qideal,ww))
7905  {
7906  WarnS("wrong weights");
7907  ww=NULL;
7908  }
7909  else
7910  {
7911  ww=ivCopy(ww);
7912  hom=isHomog;
7913  }
7914  }
7915  BITSET save1;
7916  SI_SAVE_OPT1(save1);
7918  result=kStd(i1,
7919  currRing->qideal,
7920  hom,
7921  &ww, // module weights
7922  (intvec *)h->Data(), // hilbert series
7923  0, // syzComp, whatever it is...
7924  IDELEMS(i1)-ii0, // new ideal
7925  vw); // weights of vars
7926  SI_RESTORE_OPT1(save1);
7927  idDelete(&i1);
7928  idSkipZeroes(result);
7929  res->data = (char *)result;
7930  if (!TEST_OPT_DEGBOUND) setFlag(res,FLAG_STD);
7931  if (ww!=NULL) atSet(res,omStrDup("isHomog"),ww,INTVEC_CMD);
7932  return FALSE;
7933 }
7934 
7935 
7936 static Subexpr jjMakeSub(leftv e)
7937 {
7938  assume( e->Typ()==INT_CMD );
7939  Subexpr r=(Subexpr)omAlloc0Bin(sSubexpr_bin);
7940  r->start =(int)(long)e->Data();
7941  return r;
7942 }
7943 #define D(A) (A)
7944 #define NULL_VAL NULL
7945 #define IPARITH
7946 #include "table.h"
7947 
7948 #include "iparith.inc"
7949 
7950 /*=================== operations with 2 args. ============================*/
7951 /* must be ordered: first operations for chars (infix ops),
7952  * then alphabetically */
7953 
7955  BOOLEAN proccall,
7956  struct sValCmd2* dA2,
7957  int at, int bt,
7958  struct sConvertTypes *dConvertTypes)
7959 {
7960  memset(res,0,sizeof(sleftv));
7961  BOOLEAN call_failed=FALSE;
7962 
7963  if (!errorreported)
7964  {
7965  int i=0;
7966  iiOp=op;
7967  while (dA2[i].cmd==op)
7968  {
7969  if ((at==dA2[i].arg1)
7970  && (bt==dA2[i].arg2))
7971  {
7972  res->rtyp=dA2[i].res;
7973  if (currRing!=NULL)
7974  {
7975  if (check_valid(dA2[i].valid_for,op)) break;
7976  }
7977  else
7978  {
7979  if (RingDependend(dA2[i].res))
7980  {
7981  WerrorS("no ring active");
7982  break;
7983  }
7984  }
7985  if (traceit&TRACE_CALL)
7986  Print("call %s(%s,%s)\n",iiTwoOps(op),Tok2Cmdname(at),Tok2Cmdname(bt));
7987  if ((call_failed=dA2[i].p(res,a,b)))
7988  {
7989  break;// leave loop, goto error handling
7990  }
7991  a->CleanUp();
7992  b->CleanUp();
7993  //Print("op: %d,result typ:%d\n",op,res->rtyp);
7994  return FALSE;
7995  }
7996  i++;
7997  }
7998  // implicite type conversion ----------------------------------------------
7999  if (dA2[i].cmd!=op)
8000  {
8001  int ai,bi;
8004  BOOLEAN failed=FALSE;
8005  i=0; /*iiTabIndex(dArithTab2,JJTAB2LEN,op);*/
8006  //Print("op: %c, type: %s %s\n",op,Tok2Cmdname(at),Tok2Cmdname(bt));
8007  while (dA2[i].cmd==op)
8008  {
8009  //Print("test %s %s\n",Tok2Cmdname(dA2[i].arg1),Tok2Cmdname(dA2[i].arg2));
8010  if ((ai=iiTestConvert(at,dA2[i].arg1,dConvertTypes))!=0)
8011  {
8012  if ((bi=iiTestConvert(bt,dA2[i].arg2,dConvertTypes))!=0)
8013  {
8014  res->rtyp=dA2[i].res;
8015  if (currRing!=NULL)
8016  {
8017  if (check_valid(dA2[i].valid_for,op)) break;
8018  }
8019  else
8020  {
8021  if (RingDependend(dA2[i].res))
8022  {
8023  WerrorS("no ring active");
8024  break;
8025  }
8026  }
8027  if (traceit&TRACE_CALL)
8028  Print("call %s(%s,%s)\n",iiTwoOps(op),
8029  Tok2Cmdname(dA2[i].arg1),Tok2Cmdname(dA2[i].arg2));
8030  failed= ((iiConvert(at,dA2[i].arg1,ai,a,an))
8031  || (iiConvert(bt,dA2[i].arg2,bi,b,bn))
8032  || (call_failed=dA2[i].p(res,an,bn)));
8033  // everything done, clean up temp. variables
8034  if (failed)
8035  {
8036  // leave loop, goto error handling
8037  break;
8038  }
8039  else
8040  {
8041  // everything ok, clean up and return
8042  an->CleanUp();
8043  bn->CleanUp();
8046  a->CleanUp();
8047  b->CleanUp();
8048  return FALSE;
8049  }
8050  }
8051  }
8052  i++;
8053  }
8054  an->CleanUp();
8055  bn->CleanUp();
8058  }
8059  // error handling ---------------------------------------------------
8060  const char *s=NULL;
8061  if (!errorreported)
8062  {
8063  if ((at==0) && (a->Fullname()!=sNoName))
8064  {
8065  s=a->Fullname();
8066  }
8067  else if ((bt==0) && (b->Fullname()!=sNoName))
8068  {
8069  s=b->Fullname();
8070  }
8071  if (s!=NULL)
8072  Werror("`%s` is not defined",s);
8073  else
8074  {
8075  i=0; /*iiTabIndex(dArithTab2,JJTAB2LEN,op);*/
8076  s = iiTwoOps(op);
8077  if (proccall)
8078  {
8079  Werror("%s(`%s`,`%s`) failed"
8080  ,s,Tok2Cmdname(at),Tok2Cmdname(bt));
8081  }
8082  else
8083  {
8084  Werror("`%s` %s `%s` failed"
8085  ,Tok2Cmdname(at),s,Tok2Cmdname(bt));
8086  }
8087  if ((!call_failed) && BVERBOSE(V_SHOW_USE))
8088  {
8089  while (dA2[i].cmd==op)
8090  {
8091  if(((at==dA2[i].arg1)||(bt==dA2[i].arg2))
8092  && (dA2[i].res!=0)
8093  && (dA2[i].p!=jjWRONG2))
8094  {
8095  if (proccall)
8096  Werror("expected %s(`%s`,`%s`)"
8097  ,s,Tok2Cmdname(dA2[i].arg1),Tok2Cmdname(dA2[i].arg2));
8098  else
8099  Werror("expected `%s` %s `%s`"
8100  ,Tok2Cmdname(dA2[i].arg1),s,Tok2Cmdname(dA2[i].arg2));
8101  }
8102  i++;
8103  }
8104  }
8105  }
8106  }
8107  res->rtyp = UNKNOWN;
8108  }
8109  a->CleanUp();
8110  b->CleanUp();
8111  return TRUE;
8112 }
8114  struct sValCmd2* dA2,
8115  int at,
8116  struct sConvertTypes *dConvertTypes)
8117 {
8118  leftv b=a->next;
8119  a->next=NULL;
8120  int bt=b->Typ();
8121  BOOLEAN bo=iiExprArith2TabIntern(res,a,op,b,TRUE,dA2,at,bt,dConvertTypes);
8122  a->next=b;
8123  a->CleanUp();
8124  return bo;
8125 }
8126 BOOLEAN iiExprArith2(leftv res, leftv a, int op, leftv b, BOOLEAN proccall)
8127 {
8128  memset(res,0,sizeof(sleftv));
8129 
8130  if (!errorreported)
8131  {
8132 #ifdef SIQ
8133  if (siq>0)
8134  {
8135  //Print("siq:%d\n",siq);
8137  memcpy(&d->arg1,a,sizeof(sleftv));
8138  //a->Init();
8139  memcpy(&d->arg2,b,sizeof(sleftv));
8140  //b->Init();
8141  d->argc=2;
8142  d->op=op;
8143  res->data=(char *)d;
8144  res->rtyp=COMMAND;
8145  return FALSE;
8146  }
8147 #endif
8148  int at=a->Typ();
8149  int bt=b->Typ();
8150  // handling bb-objects ----------------------------------------------------
8151  if (at>MAX_TOK)
8152  {
8153  blackbox *bb=getBlackboxStuff(at);
8154  if (bb!=NULL)
8155  {
8156  if (!bb->blackbox_Op2(op,res,a,b)) return FALSE;
8157  if (errorreported) return TRUE;
8158  // else: no op defined
8159  }
8160  else return TRUE;
8161  }
8162  else if ((bt>MAX_TOK)&&(op!='('))
8163  {
8164  blackbox *bb=getBlackboxStuff(bt);
8165  if (bb!=NULL)
8166  {
8167  if(!bb->blackbox_Op2(op,res,a,b)) return FALSE;
8168  if (errorreported) return TRUE;
8169  // else: no op defined
8170  }
8171  else return TRUE;
8172  }
8173  int i=iiTabIndex(dArithTab2,JJTAB2LEN,op);
8174  return iiExprArith2TabIntern(res,a,op,b,proccall,dArith2+i,at,bt,dConvertTypes);
8175  }
8176  a->CleanUp();
8177  b->CleanUp();
8178  return TRUE;
8179 }
8180 
8181 /*==================== operations with 1 arg. ===============================*/
8182 /* must be ordered: first operations for chars (infix ops),
8183  * then alphabetically */
8184 
8185 BOOLEAN iiExprArith1Tab(leftv res, leftv a, int op, struct sValCmd1* dA1, int at, struct sConvertTypes *dConvertTypes)
8186 {
8187  memset(res,0,sizeof(sleftv));
8188  BOOLEAN call_failed=FALSE;
8189 
8190  if (!errorreported)
8191  {
8192  BOOLEAN failed=FALSE;
8193  iiOp=op;
8194  int i = 0;
8195  while (dA1[i].cmd==op)
8196  {
8197  if (at==dA1[i].arg)
8198  {
8199  if (currRing!=NULL)
8200  {
8201  if (check_valid(dA1[i].valid_for,op)) break;
8202  }
8203  else
8204  {
8205  if (RingDependend(dA1[i].res))
8206  {
8207  WerrorS("no ring active");
8208  break;
8209  }
8210  }
8211  if (traceit&TRACE_CALL)
8212  Print("call %s(%s)\n",iiTwoOps(op),Tok2Cmdname(at));
8213  res->rtyp=dA1[i].res;
8214  if ((call_failed=dA1[i].p(res,a)))
8215  {
8216  break;// leave loop, goto error handling
8217  }
8218  if (a->Next()!=NULL)
8219  {
8221  failed=iiExprArith1(res->next,a->next,op);
8222  }
8223  a->CleanUp();
8224  return failed;
8225  }
8226  i++;
8227  }
8228  // implicite type conversion --------------------------------------------
8229  if (dA1[i].cmd!=op)
8230  {
8232  i=0;
8233  //Print("fuer %c , typ: %s\n",op,Tok2Cmdname(at));
8234  while (dA1[i].cmd==op)
8235  {
8236  int ai;
8237  //Print("test %s\n",Tok2Cmdname(dA1[i].arg));
8238  if ((ai=iiTestConvert(at,dA1[i].arg,dConvertTypes))!=0)
8239  {
8240  if (currRing!=NULL)
8241  {
8242  if (check_valid(dA1[i].valid_for,op)) break;
8243  }
8244  else
8245  {
8246  if (RingDependend(dA1[i].res))
8247  {
8248  WerrorS("no ring active");
8249  break;
8250  }
8251  }
8252  if (traceit&TRACE_CALL)
8253  Print("call %s(%s)\n",iiTwoOps(op),Tok2Cmdname(dA1[i].arg));
8254  res->rtyp=dA1[i].res;
8255  failed= ((iiConvert(at,dA1[i].arg,ai,a,an,dConvertTypes))
8256  || (call_failed=dA1[i].p(res,an)));
8257  // everything done, clean up temp. variables
8258  if (failed)
8259  {
8260  // leave loop, goto error handling
8261  break;
8262  }
8263  else
8264  {
8265  if (an->Next() != NULL)
8266  {
8267  res->next = (leftv)omAllocBin(sleftv_bin);
8268  failed=iiExprArith1(res->next,an->next,op);
8269  }
8270  // everything ok, clean up and return
8271  an->CleanUp();
8273  a->CleanUp();
8274  return failed;
8275  }
8276  }
8277  i++;
8278  }
8279  an->CleanUp();
8281  }
8282  // error handling
8283  if (!errorreported)
8284  {
8285  if ((at==0) && (a->Fullname()!=sNoName))
8286  {
8287  Werror("`%s` is not defined",a->Fullname());
8288  }
8289  else
8290  {
8291  i=0;
8292  const char *s = iiTwoOps(op);
8293  Werror("%s(`%s`) failed"
8294  ,s,Tok2Cmdname(at));
8295  if ((!call_failed) && BVERBOSE(V_SHOW_USE))
8296  {
8297  while (dA1[i].cmd==op)
8298  {
8299  if ((dA1[i].res!=0)
8300  && (dA1[i].p!=jjWRONG))
8301  Werror("expected %s(`%s`)"
8302  ,s,Tok2Cmdname(dA1[i].arg));
8303  i++;
8304  }
8305  }
8306  }
8307  }
8308  res->rtyp = UNKNOWN;
8309  }
8310  a->CleanUp();
8311  return TRUE;
8312 }
8314 {
8315  memset(res,0,sizeof(sleftv));
8316 
8317  if (!errorreported)
8318  {
8319 #ifdef SIQ
8320  if (siq>0)
8321  {
8322  //Print("siq:%d\n",siq);
8324  memcpy(&d->arg1,a,sizeof(sleftv));
8325  //a->Init();
8326  d->op=op;
8327  d->argc=1;
8328  res->data=(char *)d;
8329  res->rtyp=COMMAND;
8330  return FALSE;
8331  }
8332 #endif
8333  int at=a->Typ();
8334  // handling bb-objects ----------------------------------------------------
8335  if(op>MAX_TOK) // explicit type conversion to bb
8336  {
8337  blackbox *bb=getBlackboxStuff(op);
8338  if (bb!=NULL)
8339  {
8340  res->rtyp=op;
8341  res->data=bb->blackbox_Init(bb);
8342  if(!bb->blackbox_Assign(res,a)) return FALSE;
8343  if (errorreported) return TRUE;
8344  }
8345  else return TRUE;
8346  }
8347  else if (at>MAX_TOK) // argument is of bb-type
8348  {
8349  blackbox *bb=getBlackboxStuff(at);
8350  if (bb!=NULL)
8351  {
8352  if(!bb->blackbox_Op1(op,res,a)) return FALSE;
8353  if (errorreported) return TRUE;
8354  // else: no op defined
8355  }
8356  else return TRUE;
8357  }
8358 
8359  iiOp=op;
8360  int i=iiTabIndex(dArithTab1,JJTAB1LEN,op);
8361  return iiExprArith1Tab(res,a,op, dArith1+i,at,dConvertTypes);
8362  }
8363  a->CleanUp();
8364  return TRUE;
8365 }
8366 
8367 /*=================== operations with 3 args. ============================*/
8368 /* must be ordered: first operations for chars (infix ops),
8369  * then alphabetically */
8370 
8372  struct sValCmd3* dA3, int at, int bt, int ct,
8373  struct sConvertTypes *dConvertTypes)
8374 {
8375  memset(res,0,sizeof(sleftv));
8376  BOOLEAN call_failed=FALSE;
8377 
8378  assume(dA3[0].cmd==op);
8379 
8380  if (!errorreported)
8381  {
8382  int i=0;
8383  iiOp=op;
8384  while (dA3[i].cmd==op)
8385  {
8386  if ((at==dA3[i].arg1)
8387  && (bt==dA3[i].arg2)
8388  && (ct==dA3[i].arg3))
8389  {
8390  res->rtyp=dA3[i].res;
8391  if (currRing!=NULL)
8392  {
8393  if (check_valid(dA3[i].valid_for,op)) break;
8394  }
8395  if (traceit&TRACE_CALL)
8396  Print("call %s(%s,%s,%s)\n",
8397  iiTwoOps(op),Tok2Cmdname(at),Tok2Cmdname(bt),Tok2Cmdname(ct));
8398  if ((call_failed=dA3[i].p(res,a,b,c)))
8399  {
8400  break;// leave loop, goto error handling
8401  }
8402  a->CleanUp();
8403  b->CleanUp();
8404  c->CleanUp();
8405  return FALSE;
8406  }
8407  i++;
8408  }
8409  // implicite type conversion ----------------------------------------------
8410  if (dA3[i].cmd!=op)
8411  {
8412  int ai,bi,ci;
8416  BOOLEAN failed=FALSE;
8417  i=0;
8418  //while ((dA3[i].cmd!=op)&&(dA3[i].cmd!=0)) i++;
8419  while (dA3[i].cmd==op)
8420  {
8421  if ((ai=iiTestConvert(at,dA3[i].arg1,dConvertTypes))!=0)
8422  {
8423  if ((bi=iiTestConvert(bt,dA3[i].arg2,dConvertTypes))!=0)
8424  {
8425  if ((ci=iiTestConvert(ct,dA3[i].arg3,dConvertTypes))!=0)
8426  {
8427  res->rtyp=dA3[i].res;
8428  if (currRing!=NULL)
8429  {
8430  if (check_valid(dA3[i].valid_for,op)) break;
8431  }
8432  if (traceit&TRACE_CALL)
8433  Print("call %s(%s,%s,%s)\n",
8434  iiTwoOps(op),Tok2Cmdname(dA3[i].arg1),
8435  Tok2Cmdname(dA3[i].arg2),Tok2Cmdname(dA3[i].arg3));
8436  failed= ((iiConvert(at,dA3[i].arg1,ai,a,an,dConvertTypes))
8437  || (iiConvert(bt,dA3[i].arg2,bi,b,bn,dConvertTypes))
8438  || (iiConvert(ct,dA3[i].arg3,ci,c,cn,dConvertTypes))
8439  || (call_failed=dA3[i].p(res,an,bn,cn)));
8440  // everything done, clean up temp. variables
8441  if (failed)
8442  {
8443  // leave loop, goto error handling
8444  break;
8445  }
8446  else
8447  {
8448  // everything ok, clean up and return
8449  an->CleanUp();
8450  bn->CleanUp();
8451  cn->CleanUp();
8455  a->CleanUp();
8456  b->CleanUp();
8457  c->CleanUp();
8458  //Print("op: %d,result typ:%d\n",op,res->rtyp);
8459  return FALSE;
8460  }
8461  }
8462  }
8463  }
8464  i++;
8465  }
8466  an->CleanUp();
8467  bn->CleanUp();
8468  cn->CleanUp();
8472  }
8473  // error handling ---------------------------------------------------
8474  if (!errorreported)
8475  {
8476  const char *s=NULL;
8477  if ((at==0) && (a->Fullname()!=sNoName))
8478  {
8479  s=a->Fullname();
8480  }
8481  else if ((bt==0) && (b->Fullname()!=sNoName))
8482  {
8483  s=b->Fullname();
8484  }
8485  else if ((ct==0) && (c->Fullname()!=sNoName))
8486  {
8487  s=c->Fullname();
8488  }
8489  if (s!=NULL)
8490  Werror("`%s` is not defined",s);
8491  else
8492  {
8493  i=0;
8494  //while ((dA3[i].cmd!=op)&&(dA3[i].cmd!=0)) i++;
8495  const char *s = iiTwoOps(op);
8496  Werror("%s(`%s`,`%s`,`%s`) failed"
8497  ,s,Tok2Cmdname(at),Tok2Cmdname(bt),Tok2Cmdname(ct));
8498  if ((!call_failed) && BVERBOSE(V_SHOW_USE))
8499  {
8500  while (dA3[i].cmd==op)
8501  {
8502  if(((at==dA3[i].arg1)
8503  ||(bt==dA3[i].arg2)
8504  ||(ct==dA3[i].arg3))
8505  && (dA3[i].res!=0))
8506  {
8507  Werror("expected %s(`%s`,`%s`,`%s`)"
8508  ,s,Tok2Cmdname(dA3[i].arg1)
8509  ,Tok2Cmdname(dA3[i].arg2)
8510  ,Tok2Cmdname(dA3[i].arg3));
8511  }
8512  i++;
8513  }
8514  }
8515  }
8516  }
8517  res->rtyp = UNKNOWN;
8518  }
8519  a->CleanUp();
8520  b->CleanUp();
8521  c->CleanUp();
8522  //Print("op: %d,result typ:%d\n",op,res->rtyp);
8523  return TRUE;
8524 }
8526 {
8527  memset(res,0,sizeof(sleftv));
8528 
8529  if (!errorreported)
8530  {
8531 #ifdef SIQ
8532  if (siq>0)
8533  {
8534  //Print("siq:%d\n",siq);
8536  memcpy(&d->arg1,a,sizeof(sleftv));
8537  //a->Init();
8538  memcpy(&d->arg2,b,sizeof(sleftv));
8539  //b->Init();
8540  memcpy(&d->arg3,c,sizeof(sleftv));
8541  //c->Init();
8542  d->op=op;
8543  d->argc=3;
8544  res->data=(char *)d;
8545  res->rtyp=COMMAND;
8546  return FALSE;
8547  }
8548 #endif
8549  int at=a->Typ();
8550  // handling bb-objects ----------------------------------------------
8551  if (at>MAX_TOK)
8552  {
8553  blackbox *bb=getBlackboxStuff(at);
8554  if (bb!=NULL)
8555  {
8556  if(!bb->blackbox_Op3(op,res,a,b,c)) return FALSE;
8557  if (errorreported) return TRUE;
8558  // else: no op defined
8559  }
8560  else return TRUE;
8561  if (errorreported) return TRUE;
8562  }
8563  int bt=b->Typ();
8564  int ct=c->Typ();
8565 
8566  iiOp=op;
8567  int i=0;
8568  while ((dArith3[i].cmd!=op)&&(dArith3[i].cmd!=0)) i++;
8569  return iiExprArith3TabIntern(res,op,a,b,c,dArith3+i,at,bt,ct,dConvertTypes);
8570  }
8571  a->CleanUp();
8572  b->CleanUp();
8573  c->CleanUp();
8574  //Print("op: %d,result typ:%d\n",op,res->rtyp);
8575  return TRUE;
8576 }
8578  struct sValCmd3* dA3,
8579  int at,
8580  struct sConvertTypes *dConvertTypes)
8581 {
8582  leftv b=a->next;
8583  a->next=NULL;
8584  int bt=b->Typ();
8585  leftv c=b->next;
8586  b->next=NULL;
8587  int ct=c->Typ();
8588  BOOLEAN bo=iiExprArith3TabIntern(res,op,a,b,c,dA3,at,bt,ct,dConvertTypes);
8589  b->next=c;
8590  a->next=b;
8591  a->CleanUp();
8592  return bo;
8593 }
8594 /*==================== operations with many arg. ===============================*/
8595 /* must be ordered: first operations for chars (infix ops),
8596  * then alphabetically */
8597 
8598 BOOLEAN jjANY2LIST(leftv res, leftv v, int cnt)
8599 {
8600  // cnt = 0: all
8601  // cnt = 1: only first one
8602  leftv next;
8603  BOOLEAN failed = TRUE;
8604  if(v==NULL) return failed;
8605  res->rtyp = LIST_CMD;
8606  if(cnt) v->next = NULL;
8607  next = v->next; // saving next-pointer
8608  failed = jjLIST_PL(res, v);
8609  v->next = next; // writeback next-pointer
8610  return failed;
8611 }
8612 
8614 {
8615  memset(res,0,sizeof(sleftv));
8616 
8617  if (!errorreported)
8618  {
8619 #ifdef SIQ
8620  if (siq>0)
8621  {
8622  //Print("siq:%d\n",siq);
8624  d->op=op;
8625  res->data=(char *)d;
8626  if (a!=NULL)
8627  {
8628  d->argc=a->listLength();
8629  // else : d->argc=0;
8630  memcpy(&d->arg1,a,sizeof(sleftv));
8631  switch(d->argc)
8632  {
8633  case 3:
8634  memcpy(&d->arg3,a->next->next,sizeof(sleftv));
8635  a->next->next->Init();
8636  /* no break */
8637  case 2:
8638  memcpy(&d->arg2,a->next,sizeof(sleftv));
8639  a->next->Init();
8640  a->next->next=d->arg2.next;
8641  d->arg2.next=NULL;
8642  /* no break */
8643  case 1:
8644  a->Init();
8645  a->next=d->arg1.next;
8646  d->arg1.next=NULL;
8647  }
8648  if (d->argc>3) a->next=NULL;
8649  a->name=NULL;
8650  a->rtyp=0;
8651  a->data=NULL;
8652  a->e=NULL;
8653  a->attribute=NULL;
8654  a->CleanUp();
8655  }
8656  res->rtyp=COMMAND;
8657  return FALSE;
8658  }
8659 #endif
8660  if ((a!=NULL) && (a->Typ()>MAX_TOK))
8661  {
8662  blackbox *bb=getBlackboxStuff(a->Typ());
8663  if (bb!=NULL)
8664  {
8665  if(!bb->blackbox_OpM(op,res,a)) return FALSE;
8666  if (errorreported) return TRUE;
8667  // else: no op defined
8668  }
8669  else return TRUE;
8670  }
8671  BOOLEAN failed=FALSE;
8672  int args=0;
8673  if (a!=NULL) args=a->listLength();
8674 
8675  iiOp=op;
8676  int i=0;
8677  while ((dArithM[i].cmd!=op)&&(dArithM[i].cmd!=0)) i++;
8678  while (dArithM[i].cmd==op)
8679  {
8680  if ((args==dArithM[i].number_of_args)
8681  || (dArithM[i].number_of_args==-1)
8682  || ((dArithM[i].number_of_args==-2)&&(args>0)))
8683  {
8684  res->rtyp=dArithM[i].res;
8685  if (currRing!=NULL)
8686  {
8687  if (check_valid(dArithM[i].valid_for,op)) break;
8688  }
8689  if (traceit&TRACE_CALL)
8690  Print("call %s(... (%d args))\n", iiTwoOps(op),args);
8691  if ((failed=dArithM[i].p(res,a))==TRUE)
8692  {
8693  break;// leave loop, goto error handling
8694  }
8695  if (a!=NULL) a->CleanUp();
8696  //Print("op: %d,result typ:%d\n",op,res->rtyp);
8697  return failed;
8698  }
8699  i++;
8700  }
8701  // error handling
8702  if (!errorreported)
8703  {
8704  if ((args>0) && (a->rtyp==0) && (a->Name()!=sNoName))
8705  {
8706  Werror("`%s` is not defined",a->Fullname());
8707  }
8708  else
8709  {
8710  const char *s = iiTwoOps(op);
8711  Werror("%s(...) failed",s);
8712  }
8713  }
8714  res->rtyp = UNKNOWN;
8715  }
8716  if (a!=NULL) a->CleanUp();
8717  //Print("op: %d,result typ:%d\n",op,res->rtyp);
8718  return TRUE;
8719 }
8720 
8721 /*=================== general utilities ============================*/
8722 int IsCmd(const char *n, int & tok)
8723 {
8724  int i;
8725  int an=1;
8726  int en=sArithBase.nLastIdentifier;
8727 
8728  loop
8729  //for(an=0; an<sArithBase.nCmdUsed; )
8730  {
8731  if(an>=en-1)
8732  {
8733  if (strcmp(n, sArithBase.sCmds[an].name) == 0)
8734  {
8735  i=an;
8736  break;
8737  }
8738  else if ((an!=en) && (strcmp(n, sArithBase.sCmds[en].name) == 0))
8739  {
8740  i=en;
8741  break;
8742  }
8743  else
8744  {
8745  // -- blackbox extensions:
8746  // return 0;
8747  return blackboxIsCmd(n,tok);
8748  }
8749  }
8750  i=(an+en)/2;
8751  if (*n < *(sArithBase.sCmds[i].name))
8752  {
8753  en=i-1;
8754  }
8755  else if (*n > *(sArithBase.sCmds[i].name))
8756  {
8757  an=i+1;
8758  }
8759  else
8760  {
8761  int v=strcmp(n,sArithBase.sCmds[i].name);
8762  if(v<0)
8763  {
8764  en=i-1;
8765  }
8766  else if(v>0)
8767  {
8768  an=i+1;
8769  }
8770  else /*v==0*/
8771  {
8772  break;
8773  }
8774  }
8775  }
8776  lastreserved=sArithBase.sCmds[i].name;
8777  tok=sArithBase.sCmds[i].tokval;
8778  if(sArithBase.sCmds[i].alias==2)
8779  {
8780  Warn("outdated identifier `%s` used - please change your code",
8781  sArithBase.sCmds[i].name);
8782  sArithBase.sCmds[i].alias=1;
8783  }
8784  #if 0
8785  if (currRingHdl==NULL)
8786  {
8787  #ifdef SIQ
8788  if (siq<=0)
8789  {
8790  #endif
8791  if ((tok>=BEGIN_RING) && (tok<=END_RING))
8792  {
8793  WerrorS("no ring active");
8794  return 0;
8795  }
8796  #ifdef SIQ
8797  }
8798  #endif
8799  }
8800  #endif
8801  if (!expected_parms)
8802  {
8803  switch (tok)
8804  {
8805  case IDEAL_CMD:
8806  case INT_CMD:
8807  case INTVEC_CMD:
8808  case MAP_CMD:
8809  case MATRIX_CMD:
8810  case MODUL_CMD:
8811  case POLY_CMD:
8812  case PROC_CMD:
8813  case RING_CMD:
8814  case STRING_CMD:
8815  cmdtok = tok;
8816  break;
8817  }
8818  }
8819  return sArithBase.sCmds[i].toktype;
8820 }
8821 static int iiTabIndex(const jjValCmdTab dArithTab, const int len, const int op)
8822 {
8823  // user defined types are not in the pre-computed table:
8824  if (op>MAX_TOK) return 0;
8825 
8826  int a=0;
8827  int e=len;
8828  int p=len/2;
8829  do
8830  {
8831  if (op==dArithTab[p].cmd) return dArithTab[p].start;
8832  if (op<dArithTab[p].cmd) e=p-1;
8833  else a = p+1;
8834  p=a+(e-a)/2;
8835  }
8836  while ( a <= e);
8837 
8838  // catch missing a cmd:
8839  // may be missing as a op for blackbox, if the first operand is "undef" instead of bb
8840  // Print("op %d (%c) unknown",op,op);
8841  return 0;
8842 }
8843 
8844 const char * Tok2Cmdname(int tok)
8845 {
8846  if (tok <= 0)
8847  {
8848  return sArithBase.sCmds[0].name;
8849  }
8850  if (tok==ANY_TYPE) return "any_type";
8851  if (tok==COMMAND) return "command";
8852  if (tok==NONE) return "nothing";
8853  //if (tok==IFBREAK) return "if_break";
8854  //if (tok==VECTOR_FROM_POLYS) return "vector_from_polys";
8855  //if (tok==ORDER_VECTOR) return "ordering";
8856  //if (tok==REF_VAR) return "ref";
8857  //if (tok==OBJECT) return "object";
8858  //if (tok==PRINT_EXPR) return "print_expr";
8859  if (tok==IDHDL) return "identifier";
8860  if (tok==CRING_CMD) return "(c)ring";
8861  if (tok==QRING_CMD) return "ring";
8862  if (tok>MAX_TOK) return getBlackboxName(tok);
8863  int i;
8864  for(i=0; i<sArithBase.nCmdUsed; i++)
8865  //while (sArithBase.sCmds[i].tokval!=0)
8866  {
8867  if ((sArithBase.sCmds[i].tokval == tok)&&
8868  (sArithBase.sCmds[i].alias==0))
8869  {
8870  return sArithBase.sCmds[i].name;
8871  }
8872  }
8873  // try gain for alias/old names:
8874  for(i=0; i<sArithBase.nCmdUsed; i++)
8875  {
8876  if (sArithBase.sCmds[i].tokval == tok)
8877  {
8878  return sArithBase.sCmds[i].name;
8879  }
8880  }
8881  return sArithBase.sCmds[0].name;
8882 }
8883 
8884 
8885 /*---------------------------------------------------------------------*/
8886 /**
8887  * @brief compares to entry of cmdsname-list
8888 
8889  @param[in] a
8890  @param[in] b
8891 
8892  @return <ReturnValue>
8893 **/
8894 /*---------------------------------------------------------------------*/
8895 static int _gentable_sort_cmds( const void *a, const void *b )
8896 {
8897  cmdnames *pCmdL = (cmdnames*)a;
8898  cmdnames *pCmdR = (cmdnames*)b;
8899 
8900  if(a==NULL || b==NULL) return 0;
8901 
8902  /* empty entries goes to the end of the list for later reuse */
8903  if(pCmdL->name==NULL) return 1;
8904  if(pCmdR->name==NULL) return -1;
8905 
8906  /* $INVALID$ must come first */
8907  if(strcmp(pCmdL->name, "$INVALID$")==0) return -1;
8908  if(strcmp(pCmdR->name, "$INVALID$")==0) return 1;
8909 
8910  /* tokval=-1 are reserved names at the end */
8911  if (pCmdL->tokval==-1)
8912  {
8913  if (pCmdR->tokval==-1)
8914  return strcmp(pCmdL->name, pCmdR->name);
8915  /* pCmdL->tokval==-1, pCmdL goes at the end */
8916  return 1;
8917  }
8918  /* pCmdR->tokval==-1, pCmdR goes at the end */
8919  if(pCmdR->tokval==-1) return -1;
8920 
8921  return strcmp(pCmdL->name, pCmdR->name);
8922 }
8923 
8924 /*---------------------------------------------------------------------*/
8925 /**
8926  * @brief initialisation of arithmetic structured data
8927 
8928  @retval 0 on success
8929 
8930 **/
8931 /*---------------------------------------------------------------------*/
8933 {
8934  //printf("iiInitArithmetic()\n");
8935  memset(&sArithBase, 0, sizeof(sArithBase));
8936  iiInitCmdName();
8937  /* fix last-identifier */
8938 #if 0
8939  /* we expect that gentable allready did every thing */
8940  for(sArithBase.nLastIdentifier=sArithBase.nCmdUsed-1;
8941  sArithBase.nLastIdentifier>0; sArithBase.nLastIdentifier--) {
8942  if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
8943  }
8944 #endif
8945  //Print("L=%d\n", sArithBase.nLastIdentifier);
8946 
8947  //iiArithAddCmd(szName, nAlias, nTokval, nToktype);
8948  //iiArithAddCmd("mygcd", 1, GCD_CMD, CMD_2);
8949 
8950  //iiArithAddCmd("Top", 0,-1,0);
8951 
8952 
8953  //for(i=0; i<sArithBase.nCmdUsed; i++) {
8954  // printf("CMD[%03d] %s, %d, %d, %d\n", i,
8955  // sArithBase.sCmds[i].name,
8956  // sArithBase.sCmds[i].alias,
8957  // sArithBase.sCmds[i].tokval,
8958  // sArithBase.sCmds[i].toktype);
8959  //}
8960  //iiArithRemoveCmd("Top");
8961  //iiArithAddCmd("mygcd", 2, GCD_CMD, CMD_2);
8962  //iiArithRemoveCmd("mygcd");
8963  //iiArithAddCmd("kkk", 1, 1234, CMD_1);
8964  return 0;
8965 }
8966 
8967 int iiArithFindCmd(const char *szName)
8968 {
8969  int an=0;
8970  int i = 0,v = 0;
8971  int en=sArithBase.nLastIdentifier;
8972 
8973  loop
8974  //for(an=0; an<sArithBase.nCmdUsed; )
8975  {
8976  if(an>=en-1)
8977  {
8978  if (strcmp(szName, sArithBase.sCmds[an].name) == 0)
8979  {
8980  //Print("RET-an=%d %s\n", an, sArithBase.sCmds[an].name);
8981  return an;
8982  }
8983  else if (strcmp(szName, sArithBase.sCmds[en].name) == 0)
8984  {
8985  //Print("RET-en=%d %s\n", en, sArithBase.sCmds[en].name);
8986  return en;
8987  }
8988  else
8989  {
8990  //Print("RET- 1\n");
8991  return -1;
8992  }
8993  }
8994  i=(an+en)/2;
8995  if (*szName < *(sArithBase.sCmds[i].name))
8996  {
8997  en=i-1;
8998  }
8999  else if (*szName > *(sArithBase.sCmds[i].name))
9000  {
9001  an=i+1;
9002  }
9003  else
9004  {
9005  v=strcmp(szName,sArithBase.sCmds[i].name);
9006  if(v<0)
9007  {
9008  en=i-1;
9009  }
9010  else if(v>0)
9011  {
9012  an=i+1;
9013  }
9014  else /*v==0*/
9015  {
9016  //Print("RET-i=%d %s\n", i, sArithBase.sCmds[i].name);
9017  return i;
9018  }
9019  }
9020  }
9021  //if(i>=0 && i<sArithBase.nCmdUsed)
9022  // return i;
9023  //Print("RET-2\n");
9024  return -2;
9025 }
9026 
9027 char *iiArithGetCmd( int nPos )
9028 {
9029  if(nPos<0) return NULL;
9030  if(nPos<sArithBase.nCmdUsed)
9031  return sArithBase.sCmds[nPos].name;
9032  return NULL;
9033 }
9034 
9035 int iiArithRemoveCmd(const char *szName)
9036 {
9037  int nIndex;
9038  if(szName==NULL) return -1;
9039 
9040  nIndex = iiArithFindCmd(szName);
9041  if(nIndex<0 || nIndex>=sArithBase.nCmdUsed)
9042  {
9043  Print("'%s' not found (%d)\n", szName, nIndex);
9044  return -1;
9045  }
9046  omFree(sArithBase.sCmds[nIndex].name);
9047  sArithBase.sCmds[nIndex].name=NULL;
9048  qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames),
9049  (&_gentable_sort_cmds));
9050  sArithBase.nCmdUsed--;
9051 
9052  /* fix last-identifier */
9053  for(sArithBase.nLastIdentifier=sArithBase.nCmdUsed-1;
9054  sArithBase.nLastIdentifier>0; sArithBase.nLastIdentifier--)
9055  {
9056  if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
9057  }
9058  //Print("L=%d\n", sArithBase.nLastIdentifier);
9059  return 0;
9060 }
9061 
9063  const char *szName,
9064  short nAlias,
9065  short nTokval,
9066  short nToktype,
9067  short nPos
9068  )
9069 {
9070  //printf("AddCmd(%s, %d, %d, %d, %d)\n", szName, nAlias,
9071  // nTokval, nToktype, nPos);
9072  if(nPos>=0)
9073  {
9074  // no checks: we rely on a correct generated code in iparith.inc
9075  assume(nPos < sArithBase.nCmdAllocated);
9076  assume(szName!=NULL);
9077  sArithBase.sCmds[nPos].name = omStrDup(szName);
9078  sArithBase.sCmds[nPos].alias = nAlias;
9079  sArithBase.sCmds[nPos].tokval = nTokval;
9080  sArithBase.sCmds[nPos].toktype = nToktype;
9081  sArithBase.nCmdUsed++;
9082  //if(nTokval>0) sArithBase.nLastIdentifier++;
9083  }
9084  else
9085  {
9086  if(szName==NULL) return -1;
9087  int nIndex = iiArithFindCmd(szName);
9088  if(nIndex>=0)
9089  {
9090  Print("'%s' already exists at %d\n", szName, nIndex);
9091  return -1;
9092  }
9093 
9094  if(sArithBase.nCmdUsed>=sArithBase.nCmdAllocated)
9095  {
9096  /* needs to create new slots */
9097  unsigned long nSize = (sArithBase.nCmdAllocated+1)*sizeof(cmdnames);
9098  sArithBase.sCmds = (cmdnames *)omRealloc(sArithBase.sCmds, nSize);
9099  if(sArithBase.sCmds==NULL) return -1;
9100  sArithBase.nCmdAllocated++;
9101  }
9102  /* still free slots available */
9103  sArithBase.sCmds[sArithBase.nCmdUsed].name = omStrDup(szName);
9104  sArithBase.sCmds[sArithBase.nCmdUsed].alias = nAlias;
9105  sArithBase.sCmds[sArithBase.nCmdUsed].tokval = nTokval;
9106  sArithBase.sCmds[sArithBase.nCmdUsed].toktype = nToktype;
9107  sArithBase.nCmdUsed++;
9108 
9109  qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames),
9110  (&_gentable_sort_cmds));
9111  for(sArithBase.nLastIdentifier=sArithBase.nCmdUsed-1;
9112  sArithBase.nLastIdentifier>0; sArithBase.nLastIdentifier--)
9113  {
9114  if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
9115  }
9116  //Print("L=%d\n", sArithBase.nLastIdentifier);
9117  }
9118  return 0;
9119 }
9120 
9121 static BOOLEAN check_valid(const int p, const int op)
9122 {
9123  #ifdef HAVE_PLURAL
9124  if (rIsPluralRing(currRing))
9125  {
9126  if ((p & PLURAL_MASK)==0 /*NO_PLURAL*/)
9127  {
9128  WerrorS("not implemented for non-commutative rings");
9129  return TRUE;
9130  }
9131  else if ((p & PLURAL_MASK)==2 /*, COMM_PLURAL */)
9132  {
9133  Warn("assume commutative subalgebra for cmd `%s`",Tok2Cmdname(op));
9134  return FALSE;
9135  }
9136  /* else, ALLOW_PLURAL */
9137  }
9138  #endif
9139  #ifdef HAVE_RINGS
9140  if (rField_is_Ring(currRing))
9141  {
9142  if ((p & RING_MASK)==0 /*NO_RING*/)
9143  {
9144  WerrorS("not implemented for rings with rings as coeffients");
9145  return TRUE;
9146  }
9147  /* else ALLOW_RING */
9148  else if (((p & ZERODIVISOR_MASK)==NO_ZERODIVISOR)
9149  &&(!rField_is_Domain(currRing)))
9150  {
9151  WerrorS("domain required as coeffients");
9152  return TRUE;
9153  }
9154  /* else ALLOW_ZERODIVISOR */
9155  else if(((p & WARN_RING)==WARN_RING)&&(myynest==0))
9156  {
9157  WarnS("considering the image in Q[...]");
9158  }
9159  }
9160  #endif
9161  return FALSE;
9162 }
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:753
static BOOLEAN jjINTMAT3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5957
#define idPosConstant(I)
index of generator with leading term in ground ring (if any); otherwise -1
Definition: ideals.h:42
short cmd
Definition: gentable.cc:77
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of 'a' and 'b', i.e., a-b
Definition: coeffs.h:668
int iiInitArithmetic()
initialisation of arithmetic structured data
Definition: iparith.cc:8932
int & rows()
Definition: matpol.h:24
matrix idDiff(matrix i, int k)
Definition: ideals.cc:1953
static BOOLEAN jjBREAK0(leftv, leftv)
Definition: iparith.cc:6674
static BOOLEAN jjPLUS_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:774
static BOOLEAN jjE(leftv res, leftv v)
Definition: iparith.cc:4078
static BOOLEAN jjPAR1(leftv res, leftv v)
Definition: iparith.cc:4679
#define pSubst(p, n, e)
Definition: polys.h:337
static BOOLEAN jjRANK2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3034
static BOOLEAN jjIDEAL_PL(leftv res, leftv v)
Definition: iparith.cc:6837
intvec ** weights
Definition: syz.h:45
poly pOppose(ring Rop_src, poly p, const ring Rop_dst)
opposes a vector p from Rop to currRing (dst!)
Definition: old.gring.cc:3427
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
ideal singclap_sqrfree(poly f, intvec **v, int with_exps, const ring r)
Definition: clapsing.cc:1155
static void jjEQUAL_REST(leftv res, leftv u, leftv v)
Definition: iparith.cc:1353
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
static BOOLEAN jjDET_S(leftv res, leftv v)
Definition: iparith.cc:4012
BOOLEAN yyInRingConstruction
Definition: grammar.cc:173
ideal scKBase(int deg, ideal s, ideal Q, intvec *mv)
Definition: hdegree.cc:1352
#define SIMPL_LMDIV
Definition: iparith.cc:3347
static BOOLEAN jjPLUSMINUS_Gen(leftv res, leftv u, leftv v)
Definition: iparith.cc:652
ideal getMinorIdeal(const matrix mat, const int minorSize, const int k, const char *algorithm, const ideal iSB, const bool allDifferent)
Returns the specified set of minors (= subdeterminantes) of the given matrix.
static BOOLEAN jjTIMES_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:1003
static FORCE_INLINE number n_IntMod(number a, number b, const coeffs r)
for r a field, return n_Init(0,r) otherwise: n_Div(a,b,r)*b+n_IntMod(a,b,r)==a
Definition: coeffs.h:627
matrix mp_CoeffProc(poly f, poly vars, const ring R)
Definition: matpol.cc:414
static FORCE_INLINE number n_GetNumerator(number &n, const coeffs r)
return the numerator of n (if elements of r are by nature not fractional, result is n) ...
Definition: coeffs.h:609
static BOOLEAN jjBI2IM(leftv res, leftv u)
Definition: iparith.cc:3790
int compare(const bigintmat *op) const
Definition: bigintmat.cc:362
static BOOLEAN jjOP_BI_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:300
void id_Normalize(ideal I, const ring r)
normialize all polys in id
static FORCE_INLINE number n_Gcd(number a, number b, const coeffs r)
in Z: return the gcd of 'a' and 'b' in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ...
Definition: coeffs.h:685
#define WARN_RING
Definition: iparith.cc:127
static BOOLEAN jjFAC_P(leftv res, leftv u)
Definition: iparith.cc:4139
#define idMaxIdeal(D)
initialise the maximal ideal (at 0)
Definition: ideals.h:38
const CanonicalForm int s
Definition: facAbsFact.cc:55
void id_DelDiv(ideal id, const ring r)
delete id[j], if LT(j) == coeff*mon*LT(i) and vice versa, i.e., delete id[i], if LT(i) == coeff*mon*L...
unsigned si_opt_1
Definition: options.c:5
#define pVar(m)
Definition: polys.h:353
This file provides miscellaneous functionality.
ring rEnvelope(ring R)
Definition: ring.cc:5517
static BOOLEAN jjCALL2ARG(leftv res, leftv u)
Definition: iparith.cc:6702
resolvente syResolvente(ideal arg, int maxlength, int *length, intvec ***weights, BOOLEAN minim)
Definition: syz.cc:394
syStrategy syKosz(ideal arg, int *length)
Definition: syz3.cc:1765
int iiTestConvert(int inputType, int outputType)
Definition: gentable.cc:290
static BOOLEAN jjREPART(leftv res, leftv v)
Definition: iparith.cc:4835
ideal id_FreeModule(int i, const ring r)
the free module of rank i
sleftv * m
Definition: lists.h:45
static BOOLEAN jjRING3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6618
static BOOLEAN jjRSUM(leftv res, leftv u, leftv v)
Definition: iparith.cc:3340
static BOOLEAN jjVAR1(leftv res, leftv v)
Definition: iparith.cc:5188
bool luSolveViaLUDecomp(const matrix pMat, const matrix lMat, const matrix uMat, const matrix bVec, matrix &xVec, matrix &H)
Solves the linear system A * x = b, where A is an (m x n)-matrix which is given by its LU-decompositi...
poly nc_p_Bracket_qq(poly p, const poly q, const ring r)
returns [p,q], destroys p
Definition: old.gring.cc:2308
poly pSubstPoly(poly p, int var, poly image)
Definition: maps_ip.cc:365
void atSet(idhdl root, const char *name, void *data, int typ)
Definition: attrib.cc:156
Definition: tok.h:115
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
static BOOLEAN jjTEST(leftv, leftv v)
Definition: iparith.cc:7626
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition: kstd1.cc:2815
short valid_for
Definition: gentable.cc:82
ideal id_Homogen(ideal h, int varnum, const ring r)
#define pSetm(p)
Definition: polys.h:241
char * rVarStr(ring r)
Definition: ring.cc:594
static int _gentable_sort_cmds(const void *a, const void *b)
compares to entry of cmdsname-list
Definition: iparith.cc:8895
ip_command * command
Definition: ipid.h:24
static FORCE_INLINE BOOLEAN n_IsUnit(number n, const coeffs r)
TRUE iff n has a multiplicative inverse in the given coeff field/ring r.
Definition: coeffs.h:516
static BOOLEAN jjPARDEG(leftv res, leftv v)
Definition: iparith.cc:4695
number ntDiff(number a, number d, const coeffs cf)
Definition: transext.cc:813
static BOOLEAN jjTIMES_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:927
const poly a
Definition: syzextra.cc:212
Definition: tok.h:93
void syMake(leftv v, const char *id, idhdl packhdl)
Definition: subexpr.cc:1460
static BOOLEAN jjLOAD_E(leftv, leftv v, leftv u)
Definition: iparith.cc:2665
void PrintLn()
Definition: reporter.cc:322
static BOOLEAN jjJET_ID_M(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5994
#define ANY_TYPE
Definition: tok.h:34
BOOLEAN rIsLikeOpposite(ring rBase, ring rCandidate)
checks whether rings rBase and rCandidate could be opposite to each other returns TRUE if it is so ...
Definition: old.gring.cc:3400
static BOOLEAN jjCOMPARE_S(leftv res, leftv u, leftv v)
Definition: iparith.cc:501
#define Print
Definition: emacs.cc:83
CanonicalForm fp
Definition: cfModGcd.cc:4043
static BOOLEAN jjnInt(leftv res, leftv u)
Definition: iparith.cc:5459
static BOOLEAN jjLIFT(leftv res, leftv u, leftv v)
Definition: iparith.cc:2641
void omPrintInfo(FILE *fd)
Definition: omStats.c:127
bigintmat * bimSub(bigintmat *a, bigintmat *b)
Definition: bigintmat.cc:216
static BOOLEAN jjPLUS_MA(leftv res, leftv u, leftv v)
Definition: iparith.cc:821
Definition: tok.h:85
#define TEST_OPT_DEGBOUND
Definition: options.h:108
static BOOLEAN jjKERNEL(leftv res, leftv u, leftv v)
Definition: iparith.cc:2625
static BOOLEAN jjCOMPARE_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:363
#define pAdd(p, q)
Definition: polys.h:174
static BOOLEAN jjPLUS_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:811
static BOOLEAN jjSQR_FREE(leftv res, leftv u)
Definition: iparith.cc:5021
short arg3
Definition: gentable.cc:81
static BOOLEAN jjPFAC1(leftv res, leftv v)
Definition: iparith.cc:4525
static BOOLEAN jjTIMES_MA_BI2(leftv res, leftv u, leftv v)
Definition: iparith.cc:1045
static BOOLEAN jjKBASE2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2612
static BOOLEAN jjHILBERT2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2445
static BOOLEAN jjJET_P_IV(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5971
ideal id_Subst(ideal id, int n, poly e, const ring r)
#define SIMPL_MULT
Definition: iparith.cc:3349
ideal idSubstPar(ideal id, int n, poly e)
Definition: maps_ip.cc:348
static BOOLEAN jjMULT(leftv res, leftv v)
Definition: iparith.cc:4608
static BOOLEAN jjSUBST_Id_I(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6436
static BOOLEAN jjPlural_mat_mat(leftv res, leftv a, leftv b)
Definition: iparith.cc:2905
#define pNSet(n)
Definition: polys.h:284
static BOOLEAN jjPOWER_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:646
Subexpr e
Definition: subexpr.h:106
static BOOLEAN rField_is_Zp_a(const ring r)
Definition: ring.h:478
BITSET flag
Definition: subexpr.h:91
static BOOLEAN jjFACSTD(leftv res, leftv v)
Definition: iparith.cc:4099
static BOOLEAN jjTRANSP_IV(leftv res, leftv v)
Definition: iparith.cc:5086
int nCmdAllocated
number of commands-slots allocated
Definition: iparith.cc:209
static BOOLEAN jjCALL3ARG(leftv res, leftv u)
Definition: iparith.cc:6710
static BOOLEAN jjN2BI(leftv res, leftv v)
Definition: iparith.cc:4628
Definition: lists.h:22
static BOOLEAN jjCOUNT_N(leftv res, leftv v)
Definition: iparith.cc:3848
#define nNormalize(n)
Definition: numbers.h:30
static BOOLEAN jjGETDUMP(leftv, leftv v)
Definition: iparith.cc:4155
static BOOLEAN jjINTVEC_PL(leftv res, leftv v)
Definition: iparith.cc:7294
static BOOLEAN jjP2BI(leftv res, leftv v)
Definition: iparith.cc:4719
ideal_list kStdfac(ideal F, ideal Q, tHomog h, intvec **w, ideal D)
Definition: kstdfac.cc:808
static BOOLEAN jjTIMES_MA_P2(leftv res, leftv u, leftv v)
Definition: iparith.cc:1059
void idLiftW(ideal P, ideal Q, int n, matrix &T, ideal &R, short *w)
Definition: ideals.cc:1133
ideal interpolation(const std::vector< ideal > &L, intvec *v)
#define TEST_OPT_PROT
Definition: options.h:98
intvec * scIndIntvec(ideal S, ideal Q)
Definition: hdegree.cc:212
void henselFactors(const int xIndex, const int yIndex, const poly h, const poly f0, const poly g0, const int d, poly &f, poly &g)
Computes a factorization of a polynomial h(x, y) in K[[x]][y] up to a certain degree in x...
int ncols
Definition: matpol.h:22
#define pMaxComp(p)
Definition: polys.h:270
BOOLEAN mpKoszul(leftv res, leftv c, leftv b, leftv id)
Definition: ipshell.cc:2670
loop
Definition: myNF.cc:98
#define IDID(a)
Definition: ipid.h:121
static BOOLEAN jjCOUNT_M(leftv res, leftv v)
Definition: iparith.cc:3859
BOOLEAN iiExprArith1(leftv res, leftv a, int op)
Definition: iparith.cc:8313
static BOOLEAN rField_is_Ring_PtoM(const ring r)
Definition: ring.h:431
static int WerrorS_dummy_cnt
Definition: iparith.cc:5333
#define pSetExp(p, i, v)
Definition: polys.h:42
static int si_min(const int a, const int b)
Definition: auxiliary.h:167
int getRTimer()
Definition: timer.cc:172
static BOOLEAN jjRANDOM(leftv res, leftv u, leftv v)
Definition: iparith.cc:3026
static BOOLEAN jjOP_REST(leftv res, leftv u, leftv v)
Definition: iparith.cc:528
#define FALSE
Definition: auxiliary.h:140
static BOOLEAN jjFAREY_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:2254
poly pHeadProc(poly p)
Definition: iparith.cc:249
matrix mp_InitP(int r, int c, poly p, const ring R)
make it a p * unit matrix
Definition: matpol.cc:124
ideal t_rep_gb(ring r, ideal arg_I, int syz_comp, BOOLEAN F4_mode)
Definition: tgb.cc:3558
Compatiblity layer for legacy polynomial operations (over currRing)
static BOOLEAN jjDIVMOD_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1167
static BOOLEAN jjBRACK_Ma_I_IV(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5575
ideal kSba(ideal F, ideal Q, tHomog h, intvec **w, int sbaOrder, int arri, intvec *hilb, int syzComp, int newIdeal, intvec *vw)
Definition: kstd1.cc:2418
poly p_Homogen(poly p, int varnum, const ring r)
Definition: p_polys.cc:3138
static BOOLEAN jjL2R(leftv res, leftv v)
Definition: iparith.cc:4459
static BOOLEAN jjOpenClose(leftv, leftv v)
Definition: iparith.cc:4667
Definition: tok.h:42
short res
Definition: gentable.cc:61
static BOOLEAN jjMEMORY(leftv res, leftv v)
Definition: iparith.cc:4564
return P p
Definition: myNF.cc:203
BOOLEAN jjWAIT1ST1(leftv res, leftv u)
Definition: iparith.cc:5228
int exprlist_length(leftv v)
Definition: ipshell.cc:552
ideal id_Copy(ideal h1, const ring r)
copy an ideal
short * iv2array(intvec *iv, const ring R)
Definition: weight.cc:208
Definition: mod_raw.h:16
Matrices of numbers.
Definition: bigintmat.h:32
static int rPar(const ring r)
(r->cf->P)
Definition: ring.h:547
static BOOLEAN jjCOEFFS_Id(leftv res, leftv u, leftv v)
Definition: iparith.cc:1925
BOOLEAN iiExprArith3(leftv res, int op, leftv a, leftv b, leftv c)
Definition: iparith.cc:8525
short tokval
Definition: gentable.cc:51
static BOOLEAN jjCOLS(leftv res, leftv v)
Definition: iparith.cc:3820
static BOOLEAN rField_is_Ring_ModN(const ring r)
Definition: ring.h:428
matrix mp_Coeffs(ideal I, int var, const ring R)
corresponds to Maple's coeffs: var has to be the number of a variable
Definition: matpol.cc:327
#define nPower(a, b, res)
Definition: numbers.h:38
#define pLmCmp(p, q)
returns 0|1|-1 if p=q|p>q|p
Definition: polys.h:105
static BOOLEAN jjKLAMMER_rest(leftv res, leftv u, leftv v)
Definition: iparith.cc:1587
lists syConvRes(syStrategy syzstr, BOOLEAN toDel, int add_row_shift)
Definition: ipshell.cc:2760
static BOOLEAN jjALIGN_M(leftv res, leftv u, leftv v)
Definition: iparith.cc:1757
static BOOLEAN jjHOMOG1(leftv res, leftv v)
Definition: iparith.cc:4271
static BOOLEAN jjCHINREM_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1660
void omPrintBinStats(FILE *fd)
Definition: omBin.c:692
static BOOLEAN jjPLUS_MA_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:833
char * rParStr(ring r)
Definition: ring.cc:620
poly sm_CallDet(ideal I, const ring R)
Definition: sparsmat.cc:359
BOOLEAN idTestHomModule(ideal m, ideal Q, intvec *w)
Definition: ideals.cc:1884
static BOOLEAN jjGCD_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:2422
static BOOLEAN jjrVarStr(leftv res, leftv v)
Definition: iparith.cc:5428
static BOOLEAN jjPRIME(leftv res, leftv v)
Definition: iparith.cc:4757
static BOOLEAN jjMODULO(leftv res, leftv u, leftv v)
Definition: iparith.cc:2676
static BOOLEAN jjROWS(leftv res, leftv v)
Definition: iparith.cc:4847
ideal id_ChineseRemainder(ideal *xx, number *q, int rl, const ring r)
static BOOLEAN jjDET_BI(leftv res, leftv v)
Definition: iparith.cc:3984
static BOOLEAN jjDUMP(leftv, leftv v)
Definition: iparith.cc:4064
static BOOLEAN jjPLUS_S(leftv res, leftv u, leftv v)
Definition: iparith.cc:848
BOOLEAN iiTryLoadLib(leftv v, const char *id)
Definition: iplib.cc:751
static BOOLEAN jjBRACK_Bim(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5518
poly mp_Trace(matrix a, const ring R)
Definition: matpol.cc:289
static BOOLEAN jjCOEF(leftv res, leftv u, leftv v)
Definition: iparith.cc:1918
Definition: tok.h:167
static BOOLEAN jjREDUCE3_ID(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6572
static BOOLEAN jjTIMES_MA_I2(leftv res, leftv u, leftv v)
Definition: iparith.cc:1087
static BOOLEAN jjJACOB_M(leftv res, leftv a)
Definition: iparith.cc:4431
static BOOLEAN jjnlInt(leftv res, leftv u)
Definition: iparith.cc:5466
static BOOLEAN jjIS_RINGVAR0(leftv res, leftv)
Definition: iparith.cc:4395
sleftv iiRETURNEXPR
Definition: iplib.cc:527
static BOOLEAN jjINTERRED(leftv res, leftv v)
Definition: iparith.cc:4373
rational (GMP) numbers
Definition: coeffs.h:31
static BOOLEAN jjMINUS_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:879
static BOOLEAN jjSTD_1(leftv res, leftv u, leftv v)
Definition: iparith.cc:3482
static BOOLEAN jjDOTDOT(leftv res, leftv u, leftv v)
Definition: iparith.cc:357
void id_Norm(ideal id, const ring r)
ideal id = (id[i]), result is leadcoeff(id[i]) = 1
static BOOLEAN jjNULL(leftv, leftv)
Definition: iparith.cc:3678
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:539
short arg1
Definition: gentable.cc:62
#define pIsUnit(p)
return true if the Lm is a constant <>0
Definition: polys.h:211
static BOOLEAN jjCONTENT(leftv res, leftv v)
Definition: iparith.cc:3835
static BOOLEAN jjFAC_P2(leftv res, leftv u, leftv dummy)
Definition: iparith.cc:2185
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
static BOOLEAN jjREAD2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3043
static BOOLEAN jjKLAMMER_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1559
#define idSimpleAdd(A, B)
Definition: ideals.h:58
matrix idDiffOp(ideal I, ideal J, BOOLEAN multiply)
Definition: ideals.cc:1966
int singclap_det_i(intvec *m, const ring)
Definition: clapsing.cc:1602
static BOOLEAN jjpHead(leftv res, leftv v)
Definition: iparith.cc:5384
Definition: grammar.cc:271
static BOOLEAN jjCOLON(leftv res, leftv u, leftv v)
Definition: iparith.cc:344
static BOOLEAN jjPARSTR2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2825
int rChar(ring r)
Definition: ring.cc:684
BOOLEAN iiExprArith1Tab(leftv res, leftv a, int op, struct sValCmd1 *dA1, int at, struct sConvertTypes *dConvertTypes)
apply an operation 'op' to an argument a return TRUE on failure
Definition: iparith.cc:8185
static BOOLEAN jjBI2N(leftv res, leftv u)
Definition: iparith.cc:3775
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
static BOOLEAN jjUMINUS_MA(leftv res, leftv u)
Definition: iparith.cc:3728
static BOOLEAN jjSUBST_Id_N(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6440
#define IDROOT
Definition: ipid.h:20
static BOOLEAN jjDIV_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:1216
ring rOpposite(ring src)
Definition: ring.cc:5189
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:540
BOOLEAN jjPROC(leftv res, leftv u, leftv v)
Definition: iparith.cc:1606
poly singclap_gcd(poly f, poly g, const ring r)
destroys f and g
Definition: clapsing.cc:287
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
short arg
Definition: gentable.cc:71
void sdb_show_bp()
Definition: sdb.cc:58
#define pNeg(p)
Definition: polys.h:169
intvec * ivCopy(const intvec *o)
Definition: intvec.h:137
struct sValCmd1 * psValCmd1
Definition: iparith.cc:204
static BOOLEAN jjDEGREE(leftv res, leftv v)
Definition: iparith.cc:3902
bigintmat * bimAdd(bigintmat *a, bigintmat *b)
Matrix-Add/-Sub/-Mult so oder mit operator+/-/* ? : NULL as a result means an error (non-compatible m...
Definition: bigintmat.cc:180
BOOLEAN siq
Definition: subexpr.cc:58
static BOOLEAN jjINTERSECT_PL(leftv res, leftv v)
Definition: iparith.cc:7058
static BOOLEAN jjBREAK1(leftv, leftv v)
Definition: iparith.cc:6681
static BOOLEAN jjEXTGCD_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:2139
#define SIMPL_EQU
Definition: iparith.cc:3350
const char sNoName[]
Definition: subexpr.cc:56
int listLength()
Definition: subexpr.cc:61
ideal getMinorIdealCache(const matrix mat, const int minorSize, const int k, const ideal iSB, const int cacheStrategy, const int cacheN, const int cacheW, const bool allDifferent)
Returns the specified set of minors (= subdeterminantes) of the given matrix.
long int64
Definition: auxiliary.h:112
static BOOLEAN jjPlural_mat_poly(leftv res, leftv a, leftv b)
Definition: iparith.cc:2884
static BOOLEAN jjNEWSTRUCT3(leftv, leftv u, leftv v, leftv w)
Definition: iparith.cc:6212
static BOOLEAN jjTRACE_IV(leftv res, leftv v)
Definition: iparith.cc:5076
#define pLmDelete(p)
assume p != NULL, deletes Lm(p)->coef and Lm(p)
Definition: polys.h:76
short number_of_args
Definition: gentable.cc:89
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
static BOOLEAN jjGT_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1131
static BOOLEAN jjidFreeModule(leftv res, leftv v)
Definition: iparith.cc:5366
static BOOLEAN rField_is_Q_a(const ring r)
Definition: ring.h:488
static BOOLEAN jjINTERPOLATION(leftv res, leftv l, leftv v)
Definition: iparith.cc:2579
#define TRUE
Definition: auxiliary.h:144
struct sValCmd1 dArith1[]
Definition: table.h:19
#define nIsOne(n)
Definition: numbers.h:25
lists qrDoubleShift(const matrix A, const number tol1, const number tol2, const number tol3, const ring r=currRing)
Computes all eigenvalues of a given real quadratic matrix with multiplicites.
lib_types type_of_LIB(const char *newlib, char *libnamebuf)
Definition: mod_lib.cc:24
static BOOLEAN jjMINUS_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:863
static BOOLEAN jjDUMMY(leftv res, leftv u)
Definition: iparith.cc:3673
ideal kStd(ideal F, ideal Q, tHomog h, intvec **w, intvec *hilb, int syzComp, int newIdeal, intvec *vw, s_poly_proc_t sp)
Definition: kstd1.cc:2221
int length() const
Definition: intvec.h:86
syStrategy syResolution(ideal arg, int maxlength, intvec *w, BOOLEAN minim)
Definition: syz.cc:623
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:54
#define IDIDEAL(a)
Definition: ipid.h:132
ideal idMultSect(resolvente arg, int length)
Definition: ideals.cc:350
static BOOLEAN jjHILBERT_IV(leftv res, leftv v)
Definition: iparith.cc:4259
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1435
intvec * ivSub(intvec *a, intvec *b)
Definition: intvec.cc:306
int syDim(syStrategy syzstr)
Definition: syz1.cc:1860
#define pSplit(p, r)
Definition: polys.h:235
void Init()
Definition: subexpr.h:108
static BOOLEAN rField_is_Domain(const ring r)
Definition: ring.h:440
#define UNKNOWN
Definition: tok.h:171
int cmdtok
Definition: grammar.cc:175
static BOOLEAN jjEQUAL_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1321
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
Definition: coeffs.h:579
poly iiHighCorner(ideal I, int ak)
Definition: ipshell.cc:1480
void * ADDRESS
Definition: auxiliary.h:161
static BOOLEAN jjTIMES_MA_BI1(leftv res, leftv u, leftv v)
Definition: iparith.cc:1035
sleftv * leftv
Definition: structs.h:60
static BOOLEAN jjWEDGE(leftv res, leftv u, leftv v)
Definition: iparith.cc:3657
BOOLEAN iiExprArithM(leftv res, leftv a, int op)
Definition: iparith.cc:8613
poly singclap_det(const matrix m, const ring s)
Definition: clapsing.cc:1579
#define SI_SAVE_OPT1(A)
Definition: options.h:20
short valid_for
Definition: gentable.cc:72
sValCmdTab jjValCmdTab[]
Definition: iparith.cc:148
static BOOLEAN jjPROC1(leftv res, leftv u)
Definition: iparith.cc:3748
intvec * ivTranp(intvec *o)
Definition: intvec.cc:336
#define PLURAL_MASK
Definition: iparith.cc:106
g
Definition: cfModGcd.cc:4031
static BOOLEAN jjDEG_M(leftv res, leftv u)
Definition: iparith.cc:3891
static BOOLEAN jjDIM_R(leftv res, leftv v)
Definition: iparith.cc:5449
void WerrorS(const char *s)
Definition: feFopen.cc:23
static BOOLEAN jjPROC3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5726
void omPrintStats(FILE *fd)
Definition: omStats.c:114
int k
Definition: cfEzgcd.cc:93
static BOOLEAN jjJanetBasis2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2591
short toktype
Definition: gentable.cc:52
static BOOLEAN jjOP_BIM_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:287
static BOOLEAN jjBRACK_Im(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5491
ideal idModulo(ideal h2, ideal h1, tHomog hom, intvec **w)
Definition: ideals.cc:2038
int min_in()
Definition: intvec.h:110
static BOOLEAN jjDIV_Ma(leftv res, leftv u, leftv v)
Definition: iparith.cc:1291
static BOOLEAN jjNAMES0(leftv res, leftv)
Definition: iparith.cc:7445
static BOOLEAN rField_is_GF(const ring r)
Definition: ring.h:470
Definition: tok.h:98
static char const ** rParameter(const ring r)
(r->cf->parameter)
Definition: ring.h:573
int inerror
Definition: grammar.cc:176
static BOOLEAN jjTIMES_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:939
static BOOLEAN jjSTD(leftv res, leftv v)
Definition: iparith.cc:4990
static BOOLEAN jjJACOB_P(leftv res, leftv v)
Definition: iparith.cc:4400
static BOOLEAN jjpLength(leftv res, leftv v)
Definition: iparith.cc:5356
#define pLmFreeAndNext(p)
assumes p != NULL, deletes p, returns pNext(p)
Definition: polys.h:74
#define Q
Definition: sirandom.c:25
#define nEqual(n1, n2)
Definition: numbers.h:20
char * showOption()
Definition: misc_ip.cc:726
static BOOLEAN jjJET_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:2602
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
short cmd
Definition: gentable.cc:60
static BOOLEAN jjGE_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1106
int traceit
Definition: febase.cc:47
#define pEqualPolys(p1, p2)
Definition: polys.h:372
#define WarnS
Definition: emacs.cc:81
static FORCE_INLINE int n_ParDeg(number n, const coeffs r)
Definition: coeffs.h:788
BOOLEAN jjLOAD(const char *s, BOOLEAN autoexport)
load lib/module given in v
Definition: iparith.cc:5274
static BOOLEAN jjP2N(leftv res, leftv v)
Definition: iparith.cc:4787
ideal idMinEmbedding(ideal arg, BOOLEAN inPlace, intvec **w)
Definition: ideals.cc:2347
#define BITSET
Definition: structs.h:17
static BOOLEAN jjGCD_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:2401
poly singclap_pdivide(poly f, poly g, const ring r)
Definition: clapsing.cc:547
coeffs coeffs_BIGINT
Definition: ipid.cc:53
int Typ()
Definition: subexpr.cc:955
#define omAlloc(size)
Definition: omAllocDecl.h:210
static BOOLEAN jjOPPOSE(leftv res, leftv a, leftv b)
Definition: iparith.cc:2945
static bool rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:361
static BOOLEAN jjSUBST_Id(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6392
static BOOLEAN jjPRUNE(leftv res, leftv v)
Definition: iparith.cc:4763
static BOOLEAN jjOP_I_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:283
ideal idQuot(ideal h1, ideal h2, BOOLEAN h1IsStb, BOOLEAN resultIsIdeal)
Definition: ideals.cc:1310
#define Sy_bit(x)
Definition: options.h:30
short res
Definition: gentable.cc:70
long(* pLDegProc)(poly p, int *length, ring r)
Definition: ring.h:45
static BOOLEAN jjINDEX_P_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1451
static BOOLEAN jjsyMinBase(leftv res, leftv v)
Definition: iparith.cc:5400
const char * Name()
Definition: subexpr.h:121
intvec * idSort(ideal id, BOOLEAN nolex=TRUE)
Definition: ideals.h:184
#define pGetComp(p)
Component.
Definition: polys.h:37
static BOOLEAN jjPARSTR1(leftv res, leftv v)
Definition: iparith.cc:4701
static BOOLEAN jjHOMOG1_W(leftv res, leftv v, leftv u)
Definition: iparith.cc:2546
static BOOLEAN jjGE_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1113
static int pLength(poly a)
Definition: p_polys.h:189
int int kStrategy strat if(h==NULL) return NULL
static int iiTabIndex(const jjValCmdTab dArithTab, const int len, const int op)
Definition: iparith.cc:8821
BOOLEAN iiExport(leftv v, int toLev)
Definition: ipshell.cc:1380
Definition: idrec.h:34
Definition: tok.h:91
newstruct_desc newstructFromString(const char *s)
Definition: newstruct.cc:795
static BOOLEAN jjWAIT1ST2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3585
#define IDHDL
Definition: tok.h:35
ideal idOppose(ring Rop_src, ideal I, const ring Rop_dst)
opposes a module I from Rop to currRing(dst)
Definition: old.gring.cc:3466
poly redNF(poly h, int &max_ind, int nonorm, kStrategy strat)
Definition: kstd2.cc:1320
static BOOLEAN jjMAP(leftv res, leftv u, leftv v)
Definition: iparith.cc:1642
omBin char_ptr_bin
Definition: ring.cc:55
const char * Fullname()
Definition: subexpr.h:126
static BOOLEAN jjKoszul_Id(leftv res, leftv u, leftv v)
Definition: iparith.cc:2633
static BOOLEAN jjMINUS_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:884
#define ivTest(v)
Definition: intvec.h:161
idhdl get(const char *s, int lev)
Definition: ipid.cc:90
#define SI_PROT_I
Definition: reporter.h:50
ideal idMinBase(ideal h1)
Definition: ideals.cc:53
void monitor(void *F, int mode)
Definition: febase.cc:72
matrix idCoeffOfKBase(ideal arg, ideal kbase, poly how)
Definition: ideals.cc:2281
bool found
Definition: facFactorize.cc:56
static BOOLEAN jjTIMES_MA_I1(leftv res, leftv u, leftv v)
Definition: iparith.cc:1081
static BOOLEAN jjP2I(leftv res, leftv v)
Definition: iparith.cc:4739
ideal id_JetW(ideal i, int d, intvec *iv, const ring R)
static BOOLEAN jjMINOR_M(leftv res, leftv v)
Definition: iparith.cc:6013
static BOOLEAN jjEXPORTTO(leftv, leftv u, leftv v)
Definition: iparith.cc:2113
char * String(void *d=NULL, BOOLEAN typed=FALSE, int dim=1)
Called for conversion to string (used by string(..), write(..),..)
Definition: subexpr.cc:706
static void iiReWrite(const char *s)
Definition: iparith.cc:134
int iiRegularity(lists L)
Definition: ipshell.cc:946
static FORCE_INLINE number n_Random(siRandProc p, number p1, number p2, const coeffs cf)
Definition: coeffs.h:970
static BOOLEAN jjUMINUS_BI(leftv res, leftv u)
Definition: iparith.cc:3704
void * data
Definition: subexpr.h:89
static BOOLEAN jjTIMES_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:1023
static BOOLEAN jjCOUNT_RES(leftv res, leftv v)
Definition: iparith.cc:5444
static BOOLEAN jjJanetBasis(leftv res, leftv v)
Definition: iparith.cc:2597
void printBlackboxTypes()
list all defined type (for debugging)
Definition: blackbox.cc:210
#define mflush()
Definition: reporter.h:55
static FORCE_INLINE number n_Param(const int iParameter, const coeffs r)
return the (iParameter^th) parameter as a NEW number NOTE: parameter numbering: 1..n_NumberOfParameters(...)
Definition: coeffs.h:801
static BOOLEAN jjVARSTR2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3572
static BOOLEAN jjLE_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1150
static BOOLEAN jjROWS_IV(leftv res, leftv v)
Definition: iparith.cc:4858
#define pIter(p)
Definition: monomials.h:44
int rSum(ring r1, ring r2, ring &sum)
Definition: ring.cc:1302
static BOOLEAN jjEQUAL_Ma(leftv res, leftv u, leftv v)
Definition: iparith.cc:1333
poly res
Definition: myNF.cc:322
static BOOLEAN jjBAREISS(leftv res, leftv v)
Definition: iparith.cc:3752
intvec * kHomW
Definition: kstd1.cc:2196
matrix mp_Transp(matrix a, const ring R)
Definition: matpol.cc:268
#define IDPACKAGE(a)
Definition: ipid.h:138
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
Definition: coeffs.h:635
static BOOLEAN jjWAITALL2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3609
int myynest
Definition: febase.cc:46
int scMultInt(ideal S, ideal Q)
Definition: hdegree.cc:799
#define M
Definition: sirandom.c:24
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:12
#define pGetExp(p, i)
Exponent.
Definition: polys.h:41
static BOOLEAN jjBRACK_Ma_IV_IV(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5675
#define V_SHOW_USE
Definition: options.h:50
#define IDTYP(a)
Definition: ipid.h:118
static void WerrorS_dummy(const char *)
Definition: iparith.cc:5334
static BOOLEAN jjCOUNT_IV(leftv res, leftv v)
Definition: iparith.cc:3865
static BOOLEAN jjRES3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6580
static BOOLEAN jjTIMES_MA_N1(leftv res, leftv u, leftv v)
Definition: iparith.cc:1069
static BOOLEAN jjSTATUS2L(leftv res, leftv u, leftv v)
Definition: iparith.cc:3438
static BOOLEAN check_valid(const int p, const int op)
Definition: iparith.cc:9121
static BOOLEAN jjPLUS_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:796
char * iiArithGetCmd(int nPos)
Definition: iparith.cc:9027
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:256
static BOOLEAN jjrCharStr(leftv res, leftv v)
Definition: iparith.cc:5376
static BOOLEAN jjKoszul(leftv res, leftv u, leftv v)
Definition: iparith.cc:2629
poly * m
Definition: matpol.h:19
static BOOLEAN jjBRACKET(leftv res, leftv a, leftv b)
Definition: iparith.cc:2926
const char * Tok2Cmdname(int tok)
Definition: iparith.cc:8844
BOOLEAN iiMake_proc(idhdl pn, package pack, sleftv *sl)
Definition: iplib.cc:573
static BOOLEAN jjINDEX_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:1434
int RingDependend(int t)
Definition: gentable.cc:23
Definition: tok.h:56
void luDecomp(const matrix aMat, matrix &pMat, matrix &lMat, matrix &uMat, const ring R)
LU-decomposition of a given (m x n)-matrix.
void id_Shift(ideal M, int s, const ring r)
long p_DegW(poly p, const short *w, const ring R)
Definition: p_polys.cc:689
char my_yylinebuf[80]
Definition: febase.cc:48
static BOOLEAN jjOP_BIM_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:268
int r_IsRingVar(const char *n, char **names, int N)
Definition: ring.cc:222
ideal idSect(ideal h1, ideal h2)
Definition: ideals.cc:211
static BOOLEAN jjREDUCE3_CID(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6553
static BOOLEAN jjIDEAL_Map(leftv res, leftv v)
Definition: iparith.cc:4328
static BOOLEAN jjSUBST_Test(leftv v, leftv w, int &ringvar, poly &monomexpr)
Definition: iparith.cc:6338
const ring r
Definition: syzextra.cc:208
static BOOLEAN jjIm2Iv(leftv res, leftv v)
Definition: iparith.cc:4355
static BOOLEAN jjSUBST_M(leftv res, leftv u)
Definition: iparith.cc:7808
static BOOLEAN jjLU_INVERSE(leftv res, leftv v)
Definition: iparith.cc:7132
static BOOLEAN jjHIGHCORNER_M(leftv res, leftv v)
Definition: iparith.cc:4176
BOOLEAN expected_parms
Definition: grammar.cc:174
static BOOLEAN jjINDEPSET2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2566
intvec * bim2iv(bigintmat *b)
Definition: bigintmat.cc:341
Coefficient rings, fields and other domains suitable for Singular polynomials.
static BOOLEAN jjLT_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1154
static BOOLEAN jjIMPART(leftv res, leftv v)
Definition: iparith.cc:4362
resolvente orderedRes
Definition: syz.h:48
static BOOLEAN jjLOAD1(leftv, leftv v)
Definition: iparith.cc:4513
ideal idSeries(int n, ideal M, matrix U, intvec *w)
Definition: ideals.cc:1936
intvec * kModW
Definition: kstd1.cc:2196
ideal idElimination(ideal h1, poly delVar, intvec *hilb)
Definition: ideals.cc:1403
#define FLAG_TWOSTD
Definition: ipid.h:109
static BOOLEAN jjSUBST_Id_X(leftv res, leftv u, leftv v, leftv w, int input_type)
Definition: iparith.cc:6444
short cmd
Definition: gentable.cc:69
static BOOLEAN jjREDUCE_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:3067
#define TIMER_RESOLUTION
Definition: mod2.h:40
BOOLEAN jjWAITALL1(leftv res, leftv u)
Definition: iparith.cc:5243
void id_DelMultiples(ideal id, const ring r)
ideal id = (id[i]), c any unit if id[i] = c*id[j] then id[j] is deleted for j > i ...
Definition: intvec.h:16
#define pSub(a, b)
Definition: polys.h:258
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
void id_DelLmEquals(ideal id, const ring r)
Delete id[j], if Lm(j) == Lm(i) and both LC(j), LC(i) are units and j > i.
static FORCE_INLINE long n_Int(number &n, const coeffs r)
conversion of n to an int; 0 if not possible in Z/pZ: the representing int lying in (-p/2 ...
Definition: coeffs.h:548
const char * iiTwoOps(int t)
Definition: gentable.cc:250
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
poly p_One(const ring r)
Definition: p_polys.cc:1318
short cmd
Definition: iparith.cc:144
static BOOLEAN jjUMINUS_I(leftv res, leftv u)
Definition: iparith.cc:3711
matrix mp_Wedge(matrix a, int ar, const ring R)
Definition: matpol.cc:1656
static BOOLEAN jjWRONG(leftv, leftv)
Definition: iparith.cc:3664
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:3435
static BOOLEAN jjMATRIX_Ma(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6490
static BOOLEAN jjMSTD(leftv res, leftv v)
Definition: iparith.cc:4593
leftv Next()
Definition: subexpr.h:137
int iiArithRemoveCmd(char *szName)
int nrows
Definition: matpol.h:21
tHomog
Definition: structs.h:37
int j
Definition: myNF.cc:70
static BOOLEAN jjUMINUS_P(leftv res, leftv u)
Definition: iparith.cc:3723
static BOOLEAN jjCOEFFS2_KB(leftv res, leftv u, leftv v)
Definition: iparith.cc:1936
static BOOLEAN jjmpTrace(leftv res, leftv v)
Definition: iparith.cc:5410
lists ipNameListLev(idhdl root, int lev)
Definition: ipid.cc:547
static BOOLEAN jjALIGN_V(leftv res, leftv u, leftv v)
Definition: iparith.cc:1747
Definition: tok.h:58
bigintmat * bimMult(bigintmat *a, bigintmat *b)
Definition: bigintmat.cc:253
#define nGreaterZero(n)
Definition: numbers.h:27
const char * name
Definition: subexpr.h:88
void pSetDegProcs(ring r, pFDegProc new_FDeg, pLDegProc new_lDeg)
Definition: p_polys.cc:3481
short valid_for
Definition: gentable.cc:64
static BOOLEAN jjKLAMMER(leftv res, leftv u, leftv v)
Definition: iparith.cc:1546
#define pSetCompP(a, i)
Definition: polys.h:274
#define omFree(addr)
Definition: omAllocDecl.h:261
static long pTotaldegree(poly p)
Definition: polys.h:253
static BOOLEAN jjHOMOG_P_W(leftv res, leftv u, leftv v, leftv)
Definition: iparith.cc:5939
BOOLEAN setOption(leftv res, leftv v)
Definition: misc_ip.cc:580
omInfo_t om_Info
Definition: omStats.c:13
static BOOLEAN jjDIFF_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:1991
int scMult0Int(ideal S, ideal Q, const ring tailRing)
Definition: hdegree.cc:919
#define assume(x)
Definition: mod2.h:405
poly pSubstPar(poly p, int par, poly image)
Definition: maps_ip.cc:228
The main handler for Singular numbers which are suitable for Singular polynomials.
static FORCE_INLINE number n_Add(number a, number b, const coeffs r)
return the sum of 'a' and 'b', i.e., a+b
Definition: coeffs.h:655
static BOOLEAN jjRPAR(leftv res, leftv v)
Definition: iparith.cc:4863
static BOOLEAN jjERROR(leftv, leftv u)
Definition: iparith.cc:2118
static BOOLEAN jjVDIM(leftv res, leftv v)
Definition: iparith.cc:5222
static BOOLEAN jjEQUAL_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1339
static BOOLEAN jjJET4(leftv res, leftv u)
Definition: iparith.cc:7327
void scDegree(ideal S, intvec *modulweight, ideal Q)
Definition: hdegree.cc:822
static BOOLEAN jjOP_IM_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:325
int nLastIdentifier
valid indentifieres are slot 1..nLastIdentifier
Definition: iparith.cc:210
#define nInpNeg(n)
Definition: numbers.h:21
static BOOLEAN jjLEADEXP(leftv res, leftv v)
Definition: iparith.cc:4480
int scDimInt(ideal S, ideal Q)
Definition: hdegree.cc:72
int compare(const intvec *o) const
Definition: intvec.cc:225
static BOOLEAN jjSLIM_GB(leftv res, leftv u)
Definition: iparith.cc:4868
matrix mp_MultI(matrix a, int f, const ring R)
c = f*a
Definition: matpol.cc:146
proc2 p
Definition: iparith.cc:173
#define pLmInit(p)
like pInit, except that expvector is initialized to that of p, p must be != NULL
Definition: polys.h:64
#define pDivideM(a, b)
Definition: polys.h:265
static BOOLEAN jjDIVISION4(leftv res, leftv v)
Definition: iparith.cc:6737
static BOOLEAN jjKBASE(leftv res, leftv v)
Definition: iparith.cc:4453
#define A
Definition: sirandom.c:23
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:72
#define nMult(n1, n2)
Definition: numbers.h:17
static FORCE_INLINE number n_ChineseRemainderSym(number *a, number *b, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs r)
Definition: coeffs.h:782
static BOOLEAN jjVARSTR1(leftv res, leftv v)
Definition: iparith.cc:5205
static BOOLEAN jjREDUCE5(leftv res, leftv u)
Definition: iparith.cc:7522
pNormalize(P.p)
static BOOLEAN jjELIMIN(leftv res, leftv u, leftv v)
Definition: iparith.cc:2093
static BOOLEAN jjSTD_HILB_W(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6632
static BOOLEAN jjLIFT3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6516
BOOLEAN sm_CheckDet(ideal I, int d, BOOLEAN sw, const ring r)
Definition: sparsmat.cc:308
static BOOLEAN jjMONOM(leftv res, leftv v)
Definition: iparith.cc:2793
const char feNotImplemented[]
Definition: reporter.cc:54
void id_DelEquals(ideal id, const ring r)
ideal id = (id[i]) if id[i] = id[j] then id[j] is deleted for j > i
static BOOLEAN jjTIMES_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:946
static BOOLEAN jjMOD_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:2725
static BOOLEAN jjBRACK_Ma_IV_I(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5625
long kHomModDeg(poly p, ring r)
Definition: kstd1.cc:2208
Definition: grammar.cc:270
struct sValCmd3 dArith3[]
Definition: table.h:663
static BOOLEAN jjPREIMAGE(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6222
void makeVector()
Definition: intvec.h:95
static BOOLEAN jjKLAMMER_PL(leftv res, leftv u)
Definition: iparith.cc:7373
omBin sSubexpr_bin
Definition: subexpr.cc:49
ideal kInterRed(ideal F, ideal Q)
Definition: kstd1.cc:3277
ideal id_Power(ideal given, int exp, const ring r)
#define SIMPL_NORM
Definition: iparith.cc:3352
BOOLEAN(* proc3)(leftv, leftv, leftv, leftv)
Definition: iparith.cc:181
static BOOLEAN jjSTATUS_M(leftv res, leftv v)
Definition: iparith.cc:7777
static BOOLEAN jjDEG_M_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1955
ip_smatrix * matrix
short alias
Definition: gentable.cc:50
static BOOLEAN jjDET(leftv res, leftv v)
Definition: iparith.cc:3969
BOOLEAN jjLOAD_TRY(const char *s)
Definition: iparith.cc:5338
static BOOLEAN jjSUBST_P(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6366
static BOOLEAN jjLIFTSTD(leftv res, leftv u, leftv v)
Definition: iparith.cc:2651
int nCmdUsed
number of commands used
Definition: iparith.cc:208
static BOOLEAN jjRES(leftv res, leftv u, leftv v)
Definition: iparith.cc:3194
static BOOLEAN jjINDEX_V_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1510
static BOOLEAN jjSTRING_PL(leftv res, leftv v)
Definition: iparith.cc:7592
static BOOLEAN jjRANK1(leftv res, leftv v)
Definition: iparith.cc:4819
static BOOLEAN jjHOMOG_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:2507
idhdl currRingHdl
Definition: ipid.cc:64
static BOOLEAN jjDIV_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1203
void Copy(leftv e)
Definition: subexpr.cc:643
#define setFlag(A, F)
Definition: ipid.h:112
static BOOLEAN jjEXTGCD_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:2168
static BOOLEAN jjLEADCOEF(leftv res, leftv v)
Definition: iparith.cc:4467
#define pSetComp(p, v)
Definition: polys.h:38
static BOOLEAN jjSBA_2(leftv res, leftv v, leftv u, leftv t)
Definition: iparith.cc:4964
struct sValCmd2 * psValCmd2
Definition: iparith.cc:205
#define pJet(p, m)
Definition: polys.h:339
int m
Definition: cfEzgcd.cc:119
BOOLEAN rSamePolyRep(ring r1, ring r2)
returns TRUE, if r1 and r2 represents the monomials in the same way FALSE, otherwise this is an analo...
Definition: ring.cc:1681
static FORCE_INLINE number n_InpNeg(number n, const coeffs r)
in-place negation of n MUST BE USED: n = n_InpNeg(n) (no copy is returned)
Definition: coeffs.h:558
short ref
Definition: idrec.h:46
#define pIsConstant(p)
like above, except that Comp might be != 0
Definition: polys.h:209
static BOOLEAN jjSBA(leftv res, leftv v)
Definition: iparith.cc:4912
static BOOLEAN jjREGULARITY(leftv res, leftv v)
Definition: iparith.cc:4830
BOOLEAN jjStdJanetBasis(leftv res, leftv v, int flag)
flag: 0: JB, 1: SB
Definition: wrapper.cc:52
#define nSub(n1, n2)
Definition: numbers.h:22
matrix pMultMp(poly p, matrix a, const ring R)
Definition: matpol.cc:176
static BOOLEAN jjDEFINED(leftv res, leftv v)
Definition: iparith.cc:3940
static BOOLEAN jjidVec2Ideal(leftv res, leftv v)
Definition: iparith.cc:5371
struct sValCmdM * psValCmdM
Definition: iparith.cc:207
static int si_max(const int a, const int b)
Definition: auxiliary.h:166
static BOOLEAN jjGE_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1118
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
Definition: coeffs.h:919
static BOOLEAN jjREDUCE_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:3059
idrec * idhdl
Definition: ring.h:18
#define ZERODIVISOR_MASK
Definition: iparith.cc:113
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:46
static BOOLEAN jjMINUS_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:889
FILE * f
Definition: checklibs.c:7
BOOLEAN assumeStdFlag(leftv h)
Definition: subexpr.cc:1434
static BOOLEAN jjOP_I_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:321
static BOOLEAN jjFAREY_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:2265
static BOOLEAN jjRESERVED0(leftv, leftv)
Definition: iparith.cc:7571
omBin sleftv_bin
Definition: subexpr.cc:50
int i
Definition: cfEzgcd.cc:123
static BOOLEAN jjENVELOPE(leftv res, leftv a)
Definition: iparith.cc:5107
static BOOLEAN jjPFAC2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3314
void PrintS(const char *s)
Definition: reporter.cc:294
static BOOLEAN jjDEG_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1966
lib_types
Definition: mod_raw.h:16
static BOOLEAN jjRINGLIST(leftv res, leftv v)
Definition: iparith.cc:4840
lists ipNameList(idhdl root)
Definition: ipid.cc:524
static BOOLEAN rField_is_Q(const ring r)
Definition: ring.h:461
static BOOLEAN jjCALL1ARG(leftv res, leftv v)
Definition: iparith.cc:6698
static BOOLEAN jjLOAD2(leftv, leftv, leftv v)
Definition: iparith.cc:2661
static BOOLEAN jjidTransp(leftv res, leftv v)
Definition: iparith.cc:5454
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos=-1)
Definition: iparith.cc:9062
static long p_MinComp(poly p, ring lmRing, ring tailRing)
Definition: p_polys.h:302
BOOLEAN load_builtin(const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
Definition: iplib.cc:1145
#define SIMPL_LMEQ
Definition: iparith.cc:3348
static BOOLEAN jjSTD_HILB(leftv res, leftv u, leftv v)
Definition: iparith.cc:3456
int IsPrime(int p)
Definition: prime.cc:61
#define SIMPL_NULL
Definition: iparith.cc:3351
static BOOLEAN jjidMinBase(leftv res, leftv v)
Definition: iparith.cc:5395
#define pOne()
Definition: polys.h:286
syStrategy sySchreyer(ideal arg, int maxlength)
Definition: syz0.cc:1024
BOOLEAN sdb_set_breakpoint(const char *pp, int given_lineno)
Definition: sdb.cc:65
static BOOLEAN jjBI2P(leftv res, leftv u)
Definition: iparith.cc:3796
int yyparse(void)
Definition: grammar.cc:2168
ideal idTransp(ideal a)
transpose a module
Definition: ideals.h:193
matrix id_Module2Matrix(ideal mod, const ring R)
resolvente sySchreyerResolvente(ideal arg, int maxlength, int *length, BOOLEAN isMonomial=FALSE, BOOLEAN notReplace=FALSE)
Definition: syz0.cc:861
static BOOLEAN jjDIM2(leftv res, leftv v, leftv w)
Definition: iparith.cc:2007
Definition: tok.h:88
static BOOLEAN jjPOWER_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:590
static BOOLEAN jjUMINUS_N(leftv res, leftv u)
Definition: iparith.cc:3716
int sySize(syStrategy syzstr)
Definition: syz1.cc:1840
static BOOLEAN jjDIVISION(leftv res, leftv u, leftv v)
Definition: iparith.cc:2052
static BOOLEAN jjFWALK(leftv res, leftv u, leftv v)
Definition: iparith.cc:2395
static BOOLEAN jjREDUCE3_CP(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6541
static BOOLEAN jjINTERSECT(leftv res, leftv u, leftv v)
Definition: iparith.cc:2573
struct sValCmd2 dArith2[]
Definition: table.h:278
static BOOLEAN jjREDUCE3_P(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6565
#define pHead(p)
returns newly allocated copy of Lm(p), coef is copied, next=NULL, p might be NULL ...
Definition: polys.h:67
static BOOLEAN jjmpTransp(leftv res, leftv v)
Definition: iparith.cc:5415
static BOOLEAN jjTYPEOF(leftv res, leftv v)
Definition: iparith.cc:5140
static BOOLEAN jjINDEX_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1376
#define IDELEMS(i)
Definition: simpleideals.h:24
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:465
static BOOLEAN jjFactModD_M(leftv res, leftv v)
Definition: iparith.cc:7645
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:720
lists scIndIndset(ideal S, BOOLEAN all, ideal Q)
Definition: ipshell.cc:1012
#define atKill(H, A)
Definition: attrib.h:44
int lSize(lists L)
Definition: lists.cc:25
void(* WerrorS_callback)(const char *s)
Definition: feFopen.cc:21
#define V_DEG_STOP
Definition: options.h:67
short arg2
Definition: gentable.cc:63
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
void iiMakeResolv(resolvente r, int length, int rlen, char *name, int typ0, intvec **weights)
Definition: ipshell.cc:765
static BOOLEAN jjPLUS_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:801
#define IDLEV(a)
Definition: ipid.h:120
char * SPrintEnd()
Definition: reporter.cc:283
resolvente fullres
Definition: syz.h:57
#define TRACE_CALL
Definition: reporter.h:41
#define nDelete(n)
Definition: numbers.h:16
#define IDMAP(a)
Definition: ipid.h:134
int cols() const
Definition: bigintmat.h:128
#define FLAG_STD
Definition: ipid.h:108
static BOOLEAN jjLISTRING(leftv res, leftv v)
Definition: iparith.cc:4517
static BOOLEAN jjOPTION_PL(leftv res, leftv v)
Definition: iparith.cc:7450
poly p_Series(int n, poly p, poly u, intvec *w, const ring R)
Definition: p_polys.cc:4249
BOOLEAN iiExprArith2Tab(leftv res, leftv a, int op, struct sValCmd2 *dA2, int at, struct sConvertTypes *dConvertTypes)
apply an operation 'op' to arguments a and a->next return TRUE on failure
Definition: iparith.cc:8113
static BOOLEAN jjDENOMINATOR(leftv res, leftv v)
Return the denominator of the input number NOTE: the input number is normalized as a side effect...
Definition: iparith.cc:3953
static BOOLEAN jjRANDOM_CF(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6322
static BOOLEAN jjIS_RINGVAR_P(leftv res, leftv v)
Definition: iparith.cc:4384
ideal idCopy(ideal A)
Definition: ideals.h:76
static BOOLEAN jjrOrdStr(leftv res, leftv v)
Definition: iparith.cc:5420
static BOOLEAN jjNAMES(leftv res, leftv v)
Definition: iparith.cc:4647
bool luInverse(const matrix aMat, matrix &iMat, const ring R)
This code first computes the LU-decomposition of aMat, and then calls the method for inverting a matr...
static BOOLEAN jjGCD_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:2415
short errorreported
Definition: feFopen.cc:22
leftv next
Definition: subexpr.h:87
static BOOLEAN jjBRACK_S(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5475
struct sValCmdM dArithM[]
Definition: table.h:770
struct sConvertTypes dConvertTypes[]
Definition: table.h:1117
void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg)
Definition: p_polys.cc:3493
#define rHasLocalOrMixedOrdering_currRing()
Definition: ring.h:760
static FORCE_INLINE number n_ImPart(number i, const coeffs cf)
Definition: coeffs.h:811
void test_cmd(int i)
Definition: ipshell.cc:514
void rChangeCurrRing(ring r)
Definition: polys.cc:14
static BOOLEAN jjFIND2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2378
static BOOLEAN jjFETCH_M(leftv res, leftv u)
Definition: iparith.cc:6930
static BOOLEAN jjMOD_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:2736
short cmd
Definition: gentable.cc:87
resolvente minres
Definition: syz.h:58
static BOOLEAN rField_is_Zp(const ring r)
Definition: ring.h:455
static FORCE_INLINE number n_Farey(number a, number b, const coeffs r)
Definition: coeffs.h:785
intvec * ivMult(intvec *a, intvec *b)
Definition: intvec.cc:358
ideal idSubstPoly(ideal id, int n, poly e)
Definition: maps_ip.cc:420
static BOOLEAN jjBAREISS3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5733
static BOOLEAN jjSIMPL_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:3444
#define BVERBOSE(a)
Definition: options.h:33
short start
Definition: iparith.cc:145
void p_Shift(poly *p, int i, const ring r)
shifts components of the vector p by i
Definition: p_polys.cc:4485
#define NO_ZERODIVISOR
Definition: iparith.cc:123
static BOOLEAN jjDIM(leftv res, leftv v)
Definition: iparith.cc:4028
INLINE_THIS void Init(int l=0)
Definition: lists.h:66
static BOOLEAN jjCOEFFS3_KB(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5772
BOOLEAN(* proc2)(leftv, leftv, leftv)
Definition: iparith.cc:170
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition: matpol.cc:48
#define TEST_OPT_RETURN_SB
Definition: options.h:107
#define nInvers(a)
Definition: numbers.h:33
Definition: tok.h:38
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:850
ideal idMult(ideal h1, ideal h2)
hh := h1 * h2
Definition: ideals.h:99
matrix mp_MultP(matrix a, poly p, const ring R)
multiply a matrix 'a' by a poly 'p', destroy the args
Definition: matpol.cc:159
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
static BOOLEAN jjOP_IV_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:304
static BOOLEAN iiExprArith2TabIntern(leftv res, leftv a, int op, leftv b, BOOLEAN proccall, struct sValCmd2 *dA2, int at, int bt, struct sConvertTypes *dConvertTypes)
Definition: iparith.cc:7954
static BOOLEAN jjTIMES_MA_P1(leftv res, leftv u, leftv v)
Definition: iparith.cc:1049
static BOOLEAN jjINDEX_V(leftv res, leftv u, leftv v)
Definition: iparith.cc:1480
static FORCE_INLINE number n_ExtGcd(number a, number b, number *s, number *t, const coeffs r)
beware that ExtGCD is only relevant for a few chosen coeff. domains and may perform something unexpec...
Definition: coeffs.h:692
static BOOLEAN jjNEWSTRUCT2(leftv, leftv u, leftv v)
Definition: iparith.cc:2817
#define p_SetmComp
Definition: p_polys.h:233
#define SI_RESTORE_OPT2(A)
Definition: options.h:24
static BOOLEAN jjCOMPARE_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:446
static BOOLEAN jjSQR_FREE2(leftv res, leftv u, leftv dummy)
Definition: iparith.cc:3386
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:38
static BOOLEAN jjGCD_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:2439
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:2747
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
static BOOLEAN jjEXECUTE(leftv, leftv v)
Definition: iparith.cc:4090
short valid_for
Definition: gentable.cc:90
#define pSeries(n, p, u, w)
Definition: polys.h:343
static BOOLEAN jjidMaxIdeal(leftv res, leftv v)
Definition: iparith.cc:4304
ring rCopy(ring r)
Definition: ring.cc:1618
matrix mp_Mult(matrix a, matrix b, const ring R)
Definition: matpol.cc:224
int singclap_factorize_retry
Definition: iparith.cc:3385
static BOOLEAN jjMINRES_R(leftv res, leftv v)
Definition: iparith.cc:4614
static BOOLEAN jjPlural_num_mat(leftv res, leftv a, leftv b)
Definition: iparith.cc:2863
static BOOLEAN iiExprArith3TabIntern(leftv res, int op, leftv a, leftv b, leftv c, struct sValCmd3 *dA3, int at, int bt, int ct, struct sConvertTypes *dConvertTypes)
Definition: iparith.cc:8371
static BOOLEAN jjCOEFFS3_P(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5778
void * atGet(idhdl root, const char *name, int t, void *defaultReturnValue)
Definition: attrib.cc:135
short res
Definition: gentable.cc:88
int nr
Definition: lists.h:43
#define nDiv(a, b)
Definition: numbers.h:32
int rows() const
Definition: bigintmat.h:129
void mp_Coef2(poly v, poly mon, matrix *c, matrix *m, const ring R)
corresponds to Macauley's coef: the exponent vector of vars has to contain the variables, eg 'xy'; then the poly f is searched for monomials in x and y, these monimials are written to the first row of the matrix co. the second row of co contains the respective factors in f. Thus f = sum co[1,i]*co[2,i], i = 1..cols, rows equals 2.
Definition: matpol.cc:516
int & cols()
Definition: matpol.h:25
ideal getMinorIdealHeuristic(const matrix mat, const int minorSize, const int k, const ideal iSB, const bool allDifferent)
Returns the specified set of minors (= subdeterminantes) of the given matrix.
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
static FORCE_INLINE void n_Power(number a, int b, number *res, const coeffs r)
fill res with the power a^b
Definition: coeffs.h:631
static BOOLEAN jjPLUS_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:791
ideal id_Jet(ideal i, int d, const ring R)
CanonicalForm cf
Definition: cfModGcd.cc:4024
#define MATCOLS(i)
Definition: matpol.h:28
Definition: tok.h:95
static BOOLEAN jjJET_ID_IV(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5988
BOOLEAN jjLIST_PL(leftv res, leftv v)
Definition: iparith.cc:7394
static BOOLEAN jjTIMES_MA(leftv res, leftv u, leftv v)
Definition: iparith.cc:1091
void mp_Monomials(matrix c, int r, int var, matrix m, const ring R)
Definition: matpol.cc:377
#define nIsZero(n)
Definition: numbers.h:19
static BOOLEAN rField_is_Ring_2toM(const ring r)
Definition: ring.h:425
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:437
short res
Definition: gentable.cc:78
matrix mp_Add(matrix a, matrix b, const ring R)
Definition: matpol.cc:190
#define NULL
Definition: omList.c:10
BOOLEAN idHomIdeal(ideal id, ideal Q=NULL)
Definition: ideals.h:106
static BOOLEAN jjJET_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:2607
int ipower(int b, int m)
int ipower ( int b, int m )
Definition: cf_util.cc:25
int cols() const
Definition: intvec.h:87
matrix id_Module2formatedMatrix(ideal mod, int rows, int cols, const ring R)
slists * lists
Definition: mpr_numeric.h:146
ring rCompose(const lists L, const BOOLEAN check_comp=TRUE)
Definition: ipshell.cc:2130
static BOOLEAN jjHILBERT(leftv, leftv v)
Definition: iparith.cc:4223
ideal id_Farey(ideal x, number N, const ring r)
Definition: ideals.cc:2505
package req_packhdl
Definition: subexpr.h:107
ring syRing
Definition: syz.h:56
static BOOLEAN jjIS_RINGVAR_S(leftv res, leftv v)
Definition: iparith.cc:4389
SRes resPairs
Definition: syz.h:49
static BOOLEAN jjGT_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1136
omBin sip_command_bin
Definition: ipid.cc:48
lists primeFactorisation(const number n, const int pBound)
Factorises a given bigint number n into its prime factors less than or equal to a given bound...
Definition: misc_ip.cc:331
short arg2
Definition: gentable.cc:80
static BOOLEAN jjLT_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1158
void rDelete(ring r)
unconditionally deletes fields in r
Definition: ring.cc:448
lists rDecompose(const ring r)
Definition: ipshell.cc:1744
static BOOLEAN jjPOWER_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:624
SModulFunc_t iiGetBuiltinModInit(const char *libname)
Definition: iplib.cc:738
static BOOLEAN jjQUOT(leftv res, leftv u, leftv v)
Definition: iparith.cc:3018
#define IDINT(a)
Definition: ipid.h:124
ideal sm_CallSolv(ideal I, const ring R)
Definition: sparsmat.cc:2369
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic ...
Definition: coeffs.h:35
#define pMult(p, q)
Definition: polys.h:178
static BOOLEAN jjCOEF_M(leftv, leftv v)
Definition: iparith.cc:6722
ideal walkProc(leftv first, leftv second)
Definition: walk_ip.cc:61
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2417
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
Definition: coeffs.h:615
int rows() const
Definition: intvec.h:88
long(* pFDegProc)(poly p, ring r)
Definition: ring.h:46
intvec * hSecondSeries(intvec *hseries1)
Definition: hilb.cc:1307
#define jjWRONG2
Definition: iparith.cc:3662
ideal kMin_std(ideal F, ideal Q, tHomog h, intvec **w, ideal &M, intvec *hilb, int syzComp, int reduced)
Definition: kstd1.cc:2664
b *CanonicalForm B
Definition: facBivar.cc:51
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:6122
#define ABS(x)
Definition: auxiliary.h:157
int luRank(const matrix aMat, const bool isRowEchelon, const ring R)
Computes the rank of a given (m x n)-matrix.
static BOOLEAN jjPLUS_P_MA(leftv res, leftv u, leftv v)
Definition: iparith.cc:844
package basePack
Definition: ipid.cc:63
bool luInverseFromLUDecomp(const matrix pMat, const matrix lMat, const matrix uMat, matrix &iMat, const ring R)
This code computes the inverse by inverting lMat and uMat, and then performing two matrix multiplicat...
void omUpdateInfo()
Definition: omStats.c:24
#define R
Definition: sirandom.c:26
static BOOLEAN rField_is_Ring_Z(const ring r)
Definition: ring.h:434
static BOOLEAN jjCOUNT_RG(leftv res, leftv v)
Definition: iparith.cc:3870
static BOOLEAN jjUMINUS_IV(leftv res, leftv u)
Definition: iparith.cc:3734
void pNorm(poly p, const ring R=currRing)
Definition: polys.h:334
static BOOLEAN jjTIMES_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1011
BOOLEAN iiConvert(int inputType, int outputType, int index, leftv input, leftv output, struct sConvertTypes *dConvertTypes)
Definition: ipconv.cc:287
#define hasFlag(A, F)
Definition: ipid.h:111
ideal idLiftStd(ideal h1, matrix *ma, tHomog hi, ideal *syz)
Definition: ideals.cc:751
static BOOLEAN jjMONITOR1(leftv res, leftv v)
Definition: iparith.cc:2748
static BOOLEAN jjMINUS_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:904
static BOOLEAN jjQRDS(leftv res, leftv INPUT)
Definition: iparith.cc:7835
ideal fractalWalkProc(leftv first, leftv second)
Definition: walk_ip.cc:167
char * name
Definition: iparith.cc:152
#define pInit()
allocates a new monomial and initializes everything to 0
Definition: polys.h:61
#define IDRING(a)
Definition: ipid.h:126
static BOOLEAN jjPREIMAGE_R(leftv res, leftv v)
Definition: iparith.cc:4751
int blackboxIsCmd(const char *n, int &tok)
used by scanner: returns ROOT_DECL for known types (and the type number in tok)
Definition: blackbox.cc:193
static BOOLEAN jjPLUS_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:786
ideal id_Head(ideal h, const ring r)
returns the ideals of initial terms
static BOOLEAN jjTIMES_MA_N2(leftv res, leftv u, leftv v)
Definition: iparith.cc:1077
Definition: tok.h:86
const CanonicalForm & w
Definition: facAbsFact.cc:55
#define pWTotaldegree(p)
Definition: polys.h:254
#define pDelete(p_ptr)
Definition: polys.h:157
package currPack
Definition: ipid.cc:62
static BOOLEAN jjNAMES_I(leftv res, leftv v)
Definition: iparith.cc:4652
static BOOLEAN jjEQUAL_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:1345
proc3 p
Definition: iparith.cc:184
number singclap_det_bi(bigintmat *m, const coeffs cf)
Definition: clapsing.cc:1620
static BOOLEAN jjEXTGCD_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:2125
static BOOLEAN jjNAMEOF(leftv res, leftv v)
Definition: iparith.cc:4640
static BOOLEAN jjGT_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1124
BOOLEAN idIsZeroDim(ideal i)
Definition: ideals.h:176
static BOOLEAN jjNVARS(leftv res, leftv v)
Definition: iparith.cc:4662
static BOOLEAN jjCOLCOL(leftv res, leftv u, leftv v)
Definition: iparith.cc:714
Variable x
Definition: cfModGcd.cc:4023
int rtyp
Definition: subexpr.h:92
BOOLEAN singclap_extgcd(poly f, poly g, poly &res, poly &pa, poly &pb, const ring r)
Definition: clapsing.cc:460
BOOLEAN mp_IsDiagUnit(matrix U, const ring R)
Definition: matpol.cc:721
#define nSize(n)
Definition: numbers.h:39
#define nCopy(n)
Definition: numbers.h:15
static SArithBase sArithBase
Base entry for arithmetic.
Definition: iparith.cc:218
int iiArithFindCmd(const char *szName)
Definition: iparith.cc:8967
static FORCE_INLINE number n_GetDenom(number &n, const coeffs r)
return the denominator of n (if elements of r are by nature not fractional, result is 1) ...
Definition: coeffs.h:604
static bool rIsSCA(const ring r)
Definition: nc.h:206
static BOOLEAN jjHOMOG_ID_W(leftv res, leftv u, leftv v, leftv)
Definition: iparith.cc:5921
static BOOLEAN jjUMINUS_BIM(leftv res, leftv u)
Definition: iparith.cc:3741
void CleanUp(ring r=currRing)
Definition: subexpr.cc:307
Definition: tok.h:81
static FORCE_INLINE number n_RePart(number i, const coeffs cf)
Definition: coeffs.h:808
int(* SModulFunc_t)(SModulFunctions *)
Definition: ipid.h:84
static BOOLEAN jjMONITOR2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2752
static Subexpr jjMakeSub(leftv e)
Definition: iparith.cc:7936
void Clean(ring r=currRing)
Definition: lists.h:25
#define pNext(p)
Definition: monomials.h:43
static BOOLEAN jjLU_DECOMP(leftv res, leftv v)
Definition: iparith.cc:4534
static BOOLEAN jjFWALK3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5843
void * Data()
Definition: subexpr.cc:1097
static BOOLEAN jjCOUNT_BI(leftv res, leftv v)
Definition: iparith.cc:3843
static BOOLEAN jjrParStr(leftv res, leftv v)
Definition: iparith.cc:5436
static BOOLEAN jjCOLS_BIM(leftv res, leftv v)
Definition: iparith.cc:3825
static FORCE_INLINE BOOLEAN n_Equal(number a, number b, const coeffs r)
TRUE iff 'a' and 'b' represent the same number; they may have different representations.
Definition: coeffs.h:461
static BOOLEAN jjLE_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1145
ideal idrCopyR(ideal id, ring src_r, ring dest_r)
Definition: prCopy.cc:193
static BOOLEAN jjSYZYGY(leftv res, leftv v)
Definition: iparith.cc:5038
static BOOLEAN jjLIFTSTD3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6528
void show(int mat=0, int spaces=0) const
Definition: intvec.cc:168
int typ
Definition: idrec.h:43
ideal idLift(ideal mod, ideal submod, ideal *rest, BOOLEAN goodShape, BOOLEAN isSB, BOOLEAN divide, matrix *unit)
Definition: ideals.cc:938
short list_length
Definition: syz.h:62
static BOOLEAN jjCHINREM_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:1770
Definition: tok.h:96
BOOLEAN mp_Equal(matrix a, matrix b, const ring R)
Definition: matpol.cc:579
static BOOLEAN jjDIFF_ID_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:2002
matrix mp_Copy(matrix a, const ring r)
copies matrix a (from ring r to r)
Definition: matpol.cc:75
static BOOLEAN jjDIFF_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:1980
static BOOLEAN jjELIMIN_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:2099
ideal * resolvente
Definition: ideals.h:20
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition: fevoices.cc:171
void SPrintStart()
Definition: reporter.cc:256
syStrategy syConvList(lists li, BOOLEAN toDel)
Definition: ipshell.cc:2836
void sm_CallBareiss(ideal I, int x, int y, ideal &M, intvec **iv, const ring R)
Definition: sparsmat.cc:404
static FORCE_INLINE number n_SubringGcd(number a, number b, const coeffs r)
Definition: coeffs.h:687
static BOOLEAN jjCALL1MANY(leftv res, leftv u)
Definition: iparith.cc:3811
const char * id
Definition: idrec.h:39
static BOOLEAN jjTIMES_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:956
static BOOLEAN jjROWS_BIM(leftv res, leftv v)
Definition: iparith.cc:4853
attr attribute
Definition: subexpr.h:90
omBin slists_bin
Definition: lists.cc:23
static BOOLEAN jjLE_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1141
ideal maGetPreimage(ring theImageRing, map theMap, ideal id, const ring dst_r)
Definition: preimage.cc:63
static BOOLEAN jjINDEX_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1398
static BOOLEAN jjSBA_1(leftv res, leftv v, leftv u)
Definition: iparith.cc:4938
static BOOLEAN jjMINUS_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:894
static BOOLEAN jjPOWER_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:606
cmdnames * sCmds
array of existing commands
Definition: iparith.cc:203
#define ii_div_by_0
Definition: iparith.cc:237
int idElem(const ideal F)
count non-zero elements
char libnamebuf[128]
Definition: libparse.cc:1096
#define pPower(p, q)
Definition: polys.h:175
static FORCE_INLINE BOOLEAN nCoeff_is_Extension(const coeffs r)
Definition: coeffs.h:844
static BOOLEAN jjMATRIX_Mo(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6477
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2357
static BOOLEAN jjidHead(leftv res, leftv v)
Definition: iparith.cc:5389
Definition: tok.h:126
void newstruct_setup(const char *n, newstruct_desc d)
Definition: newstruct.cc:692
static BOOLEAN jjOP_I_IM(leftv res, leftv u, leftv v)
Definition: iparith.cc:340
static BOOLEAN jjSort_Id(leftv res, leftv v)
Definition: iparith.cc:5016
static BOOLEAN jjJET_P_P(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5978
newstruct_desc newstructChildFromString(const char *parent, const char *s)
Definition: newstruct.cc:802
leftv iiMap(map theMap, const char *what)
Definition: ipshell.cc:615
int n_IsParam(const number m, const ring r)
TODO: rewrite somehow...
Definition: ring.cc:5642
static BOOLEAN jjPOWER_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:544
static BOOLEAN jjCOMPARE_IV_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:419
static BOOLEAN jjPLUSPLUS(leftv, leftv u)
Definition: iparith.cc:3692
ring rInit(sleftv *pn, sleftv *rv, sleftv *ord)
Definition: ipshell.cc:5179
BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char *newlib, idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
Definition: iplib.cc:900
BOOLEAN iiExprArith3Tab(leftv res, leftv a, int op, struct sValCmd3 *dA3, int at, struct sConvertTypes *dConvertTypes)
apply an operation 'op' to arguments a, a->next and a->next->next return TRUE on failure ...
Definition: iparith.cc:8577
#define pDiff(a, b)
Definition: polys.h:267
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:456
#define OPT_SB_1
Definition: options.h:90
char * rCharStr(const ring r)
TODO: make it a virtual method of coeffs, together with: Decompose & Compose, rParameter & rPar...
Definition: ring.cc:618
static BOOLEAN jjFACSTD2(leftv res, leftv v, leftv w)
Definition: iparith.cc:2232
static FORCE_INLINE BOOLEAN n_GreaterZero(number n, const coeffs r)
ordered fields: TRUE iff 'n' is positive; in Z/pZ: TRUE iff 0 < m <= roundedBelow(p/2), where m is the long representing n in C: TRUE iff (Im(n) != 0 and Im(n) >= 0) or (Im(n) == 0 and Re(n) >= 0) in K(a)/: TRUE iff (n != 0 and (LC(n) > 0 or deg(n) > 0)) in K(t_1, ..., t_n): TRUE iff (LC(numerator(n) is a constant and > 0) or (LC(numerator(n) is not a constant) in Z/2^kZ: TRUE iff 0 < n <= 2^(k-1) in Z/mZ: TRUE iff the internal mpz is greater than zero in Z: TRUE iff n > 0
Definition: coeffs.h:495
#define SI_PROT_O
Definition: reporter.h:51
const char * getBlackboxName(const int t)
return the name to the type given by t (r/o)
Definition: blackbox.cc:187
ideal singclap_factorize(poly f, intvec **v, int with_exps, const ring r)
Definition: clapsing.cc:784
ideal idAdd(ideal h1, ideal h2)
h1 + h2
Definition: ideals.h:84
#define pIsUnivariate(p)
Definition: polys.h:220
static BOOLEAN jjREDUCE4(leftv res, leftv u)
Definition: iparith.cc:7460
proc1 p
Definition: iparith.cc:194
static BOOLEAN jjUNIVARIATE(leftv res, leftv v)
Definition: iparith.cc:5183
#define MATROWS(i)
Definition: matpol.h:27
static BOOLEAN jjIDEAL_Ma(leftv res, leftv v)
Definition: iparith.cc:4310
static BOOLEAN jjSTATUS3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6623
static BOOLEAN jjIDEAL_R(leftv res, leftv v)
Definition: iparith.cc:4338
intvec * hFirstSeries(ideal S, intvec *modulweight, ideal Q, intvec *wdegree, ring tailRing)
Definition: hilb.cc:1299
ideal id_Vec2Ideal(poly vec, const ring R)
matrix mp_Sub(matrix a, matrix b, const ring R)
Definition: matpol.cc:207
static BOOLEAN jjDEG(leftv res, leftv v)
Definition: iparith.cc:3883
static FORCE_INLINE char * nCoeffString(const coeffs cf)
TODO: make it a virtual method of coeffs, together with: Decompose & Compose, rParameter & rPar...
Definition: coeffs.h:963
kBucketDestroy & P
Definition: myNF.cc:191
int iiTokType(int op)
Definition: iparith.cc:254
void hLookSeries(ideal S, intvec *modulweight, ideal Q, intvec *wdegree, ring tailRing)
Definition: hilb.cc:1378
static BOOLEAN jjCOUNT_L(leftv res, leftv v)
Definition: iparith.cc:3853
static jList * T
Definition: janet.cc:37
polyrec * poly
Definition: hilb.h:10
static BOOLEAN jjMATRIX_Id(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6454
static int iin_Int(number &n, coeffs cf)
Definition: iparith.cc:242
#define IDDATA(a)
Definition: ipid.h:125
static BOOLEAN jjOR_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1371
int Kstd1_deg
Definition: kutil.cc:228
static BOOLEAN jjMINUS_MA(leftv res, leftv u, leftv v)
Definition: iparith.cc:914
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
static BOOLEAN jjLU_SOLVE(leftv res, leftv v)
Definition: iparith.cc:7213
BOOLEAN(* proc1)(leftv, leftv)
Definition: ipshell.h:123
static BOOLEAN jjpMaxComp(leftv res, leftv v)
Definition: iparith.cc:5405
#define pISet(i)
Definition: polys.h:283
#define nInit(i)
Definition: numbers.h:24
char * iiConvName(const char *libname)
Definition: iplib.cc:1277
syStrategy syHilb(ideal arg, int *length)
Definition: syz2.cc:953
int iiOp
Definition: iparith.cc:239
unsigned si_opt_2
Definition: options.c:6
static BOOLEAN currRingIsOverIntegralDomain()
Definition: iparith.cc:6005
int perm[100]
static BOOLEAN jjBRACK_Ma(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5546
static Poly * h
Definition: janet.cc:978
int BOOLEAN
Definition: auxiliary.h:131
static BOOLEAN jjPlural_num_poly(leftv res, leftv a, leftv b)
Definition: iparith.cc:2842
static BOOLEAN jjNUMERATOR(leftv res, leftv v)
Return the numerator of the input number NOTE: the input number is normalized as a side effect...
Definition: iparith.cc:3962
ideal idSyzygies(ideal h1, tHomog h, intvec **w, BOOLEAN setSyzComp, BOOLEAN setRegularity, int *deg)
Definition: ideals.cc:560
static BOOLEAN jjNOT(leftv res, leftv v)
Definition: iparith.cc:4657
#define IMATELEM(M, I, J)
Definition: intvec.h:77
const poly b
Definition: syzextra.cc:213
BOOLEAN iiExprArith2(leftv res, leftv a, int op, leftv b, BOOLEAN proccall)
Definition: iparith.cc:8126
static BOOLEAN jjHOMOG_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:2524
#define omRealloc(addr, size)
Definition: omAllocDecl.h:225
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2682
#define NONE
Definition: tok.h:170
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition: polys.h:31
static BOOLEAN jjRESERVEDNAME(leftv res, leftv v)
Definition: iparith.cc:4803
#define ppJetW(p, m, iv)
Definition: polys.h:340
#define SI_RESTORE_OPT1(A)
Definition: options.h:23
static BOOLEAN jjINDEPSET(leftv res, leftv v)
Definition: iparith.cc:4367
BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition: iplib.cc:1048
static FORCE_INLINE int n_Size(number n, const coeffs r)
return a non-negative measure for the complexity of n; return 0 only when n represents zero; (used fo...
Definition: coeffs.h:571
static BOOLEAN jjDET_I(leftv res, leftv v)
Definition: iparith.cc:3998
ideal id_Matrix2Module(matrix mat, const ring R)
static BOOLEAN jjTRANSP_BIM(leftv res, leftv v)
Definition: iparith.cc:5081
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:488
static BOOLEAN jjOPPOSITE(leftv res, leftv a)
Definition: iparith.cc:5092
static BOOLEAN jjCONTRACT(leftv res, leftv u, leftv v)
Definition: iparith.cc:1950
static BOOLEAN jjHIGHCORNER(leftv res, leftv v)
Definition: iparith.cc:4169
proc1 p
Definition: iparith.cc:163
leftv LData()
Definition: subexpr.cc:1366
struct sValCmd3 * psValCmd3
Definition: iparith.cc:206
BOOLEAN idHomModule(ideal m, ideal Q, intvec **w)
Definition: ideals.h:111
char * rOrdStr(ring r)
Definition: ring.cc:522
void Werror(const char *fmt,...)
Definition: reporter.cc:199
static BOOLEAN jjAND_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1366
void idDelete(ideal *h)
delete an ideal
Definition: ideals.h:31
#define nAdd(n1, n2)
Definition: numbers.h:18
syStrategy syLaScala3(ideal arg, int *length)
Definition: syz1.cc:2435
static BOOLEAN jjREAD(leftv res, leftv v)
Definition: iparith.cc:4826
int ivTrace(intvec *o)
Definition: intvec.cc:348
void * CopyD(int t)
Definition: subexpr.cc:662
static BOOLEAN jjCHAR(leftv res, leftv v)
Definition: iparith.cc:3815
const char * lastreserved
Definition: ipshell.cc:86
static BOOLEAN jjEQUAL_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1327
static BOOLEAN jjLEADMONOM(leftv res, leftv v)
Definition: iparith.cc:4498
int siRand()
Definition: sirandom.c:41
#define omAlloc0(size)
Definition: omAllocDecl.h:211
static BOOLEAN jjPLUS_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:858
idhdl h0
Definition: libparse.cc:1141
return result
Definition: facAbsBiFact.cc:76
int l
Definition: cfEzgcd.cc:94
static BOOLEAN jjSIMPL_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:3353
static BOOLEAN jjELIMIN_HILB(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5805
intvec * ivAdd(intvec *a, intvec *b)
Definition: intvec.cc:276
static BOOLEAN jjstrlen(leftv res, leftv v)
Definition: iparith.cc:5351
static BOOLEAN jjFETCH(leftv res, leftv u, leftv v)
Definition: iparith.cc:2273
ideal syMinBase(ideal arg)
Definition: syz.cc:1025
static BOOLEAN jjTWOSTD(leftv res, leftv a)
Definition: iparith.cc:5130
static BOOLEAN jjSTD_HILB_WP(leftv res, leftv INPUT)
Definition: iparith.cc:7852
static BOOLEAN jjDIFF_COEF(leftv res, leftv u, leftv v)
Definition: iparith.cc:4412
static BOOLEAN jjSTATUS2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3433
static BOOLEAN jjORD(leftv res, leftv v)
Definition: iparith.cc:4673
long rank
Definition: matpol.h:20
static BOOLEAN jjFIND3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5812
static BOOLEAN jjDIV_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1190
BOOLEAN jjANY2LIST(leftv res, leftv v, int cnt)
Definition: iparith.cc:8598
static BOOLEAN jjCOLS_IV(leftv res, leftv v)
Definition: iparith.cc:3830
syStrategy syMinimize(syStrategy syzstr)
Definition: syz1.cc:2403
#define IDMATRIX(a)
Definition: ipid.h:133
#define nGreater(a, b)
Definition: numbers.h:28
#define pCopy(p)
return a copy of the poly
Definition: polys.h:156
#define COMMAND
Definition: tok.h:33
#define MATELEM(mat, i, j)
Definition: matpol.h:29
#define RING_MASK
Definition: iparith.cc:112
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:20
#define V_IMAP
Definition: options.h:51
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:327
short arg1
Definition: gentable.cc:79
ssyStrategy * syStrategy
Definition: syz.h:35
#define idTest(id)
Definition: ideals.h:63
utypes data
Definition: idrec.h:40
static BOOLEAN jjCOMPARE_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:391
#define SI_SAVE_OPT2(A)
Definition: options.h:21
int IsCmd(const char *n, int &tok)
Definition: iparith.cc:8722
static BOOLEAN jjHILBERT3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5852
ListNode * next
Definition: janet.h:31
static BOOLEAN jjRANDOM_Im(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6296
static BOOLEAN jjLT_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1163
static BOOLEAN jjidElem(leftv res, leftv v)
Definition: iparith.cc:5361
static BOOLEAN jjCOEFFS3_Id(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5758
#define Warn
Definition: emacs.cc:80
ideal twostd(ideal I)
Compute two-sided GB:
Definition: nc.cc:22
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define idIsConstant(I)
Definition: ideals.h:56