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