iparith.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 
5 /*
6 * ABSTRACT: table driven kernel interface, used by interpreter
7 */
8 
9 
10 #include <kernel/mod2.h>
11 
12 #include <omalloc/omalloc.h>
13 
14 #include <factory/factory.h>
15 
16 #include <coeffs/bigintmat.h>
17 #include <coeffs/coeffs.h>
18 #include <coeffs/numbers.h>
19 
20 
21 #include <misc/options.h>
22 #include <misc/intvec.h>
23 #include <misc/sirandom.h>
24 #include <misc/prime.h>
25 
26 #include <polys/matpol.h>
27 #include <polys/monomials/maps.h>
28 #include <polys/sparsmat.h>
29 #include <polys/weight.h>
31 #include <polys/clapsing.h>
32 
35 
39 
40 #include <kernel/spectrum/GMPrat.h>
42 #include <kernel/oswrapper/timer.h>
43 #include <kernel/fglm/fglm.h>
44 
46 #include <kernel/GBEngine/syz.h>
47 #include <kernel/GBEngine/kstd1.h>
48 #include <kernel/GBEngine/units.h>
49 #include <kernel/GBEngine/tgb.h>
50 
51 #include <kernel/preimage.h>
52 #include <kernel/polys.h>
53 #include <kernel/ideals.h>
54 
55 #include <Singular/mod_lib.h>
56 #include <Singular/fevoices.h>
57 #include <Singular/tok.h>
58 #include <Singular/ipid.h>
59 #include <Singular/sdb.h>
60 #include <Singular/subexpr.h>
61 #include <Singular/lists.h>
62 #include <Singular/maps_ip.h>
63 
64 #include <Singular/ipconv.h>
65 #include <Singular/ipprint.h>
66 #include <Singular/attrib.h>
67 #include <Singular/links/silink.h>
68 #include <Singular/misc_ip.h>
70 
71 #include <Singular/number2.h>
72 
73 # include <Singular/fglm.h>
74 
75 #include <Singular/blackbox.h>
76 #include <Singular/newstruct.h>
77 #include <Singular/ipshell.h>
78 //#include <kernel/mpr_inout.h>
79 #include <reporter/si_signals.h>
80 
81 #include <stdlib.h>
82 #include <string.h>
83 #include <ctype.h>
84 #include <stdio.h>
85 #include <time.h>
86 #include <unistd.h>
87 #include <vector>
88 
89 ring rCompose(const lists L, const BOOLEAN check_comp=TRUE);
90 
91 // defaults for all commands: NO_PLURAL | NO_RING | ALLOW_ZERODIVISOR
92 
93 #ifdef HAVE_PLURAL
95  #include <kernel/GBEngine/nc.h>
96  #include <polys/nc/nc.h>
97  #include <polys/nc/sca.h>
98  #define PLURAL_MASK 3
99 #else /* HAVE_PLURAL */
100  #define PLURAL_MASK 0
101 #endif /* HAVE_PLURAL */
102 
103 #ifdef HAVE_RINGS
104  #define RING_MASK 4
105  #define ZERODIVISOR_MASK 8
106 #else
107  #define RING_MASK 0
108  #define ZERODIVISOR_MASK 0
109 #endif
110 #define ALLOW_PLURAL 1
111 #define NO_PLURAL 0
112 #define COMM_PLURAL 2
113 #define ALLOW_RING 4
114 #define NO_RING 0
115 #define NO_ZERODIVISOR 8
116 #define ALLOW_ZERODIVISOR 0
117 
118 #define ALLOW_ZZ (ALLOW_RING|NO_ZERODIVISOR)
119 
120 
121 // bit 4 for warning, if used at toplevel
122 #define WARN_RING 16
123 // bit 5: do no try automatic conversions
124 #define NO_CONVERSION 32
125 
126 static BOOLEAN check_valid(const int p, const int op);
127 
128 /*=============== types =====================*/
130 {
131  short cmd;
132  short start;
133 };
134 
136 
137 struct _scmdnames
138 {
139  char *name;
140  short alias;
141  short tokval;
142  short toktype;
143 };
144 typedef struct _scmdnames cmdnames;
145 
146 struct sValCmd1
147 {
149  short cmd;
150  short res;
151  short arg;
152  short valid_for;
153 };
154 
156 struct sValCmd2
157 {
159  short cmd;
160  short res;
161  short arg1;
162  short arg2;
163  short valid_for;
164 };
165 
167 struct sValCmd3
168 {
170  short cmd;
171  short res;
172  short arg1;
173  short arg2;
174  short arg3;
175  short valid_for;
176 };
177 struct sValCmdM
178 {
180  short cmd;
181  short res;
182  short number_of_args; /* -1: any, -2: any >0, .. */
183  short valid_for;
184 };
185 
186 typedef struct
187 {
188  cmdnames *sCmds; /**< array of existing commands */
193  unsigned nCmdUsed; /**< number of commands used */
194  unsigned nCmdAllocated; /**< number of commands-slots allocated */
195  unsigned nLastIdentifier; /**< valid indentifieres are slot 1..nLastIdentifier */
196 } SArithBase;
197 
198 /*---------------------------------------------------------------------*
199  * File scope Variables (Variables share by several functions in
200  * the same file )
201  *
202  *---------------------------------------------------------------------*/
203 static SArithBase sArithBase; /**< Base entry for arithmetic */
204 
205 /*---------------------------------------------------------------------*
206  * Extern Functions declarations
207  *
208  *---------------------------------------------------------------------*/
209 static int _gentable_sort_cmds(const void *a, const void *b);
210 extern int iiArithRemoveCmd(char *szName);
211 extern int iiArithAddCmd(const char *szName, short nAlias, short nTokval,
212  short nToktype, short nPos=-1);
213 
214 /*============= proc =======================*/
215 static int iiTabIndex(const jjValCmdTab dArithTab, const int len, const int op);
216 static Subexpr jjMakeSub(leftv e);
217 
218 /*============= vars ======================*/
219 extern int cmdtok;
220 extern BOOLEAN expected_parms;
221 
222 #define ii_div_by_0 "div. by 0"
223 
224 int iiOp; /* the current operation*/
225 
226 /*=================== simple helpers =================*/
227 static int iin_Int(number &n,coeffs cf)
228 {
229  long l=n_Int(n,cf);
230  int i=(int)l;
231  if ((long)i==l) return l;
232  return 0;
233 }
235 {
236  return pHead(p);
237 }
238 
239 int iiTokType(int op)
240 {
241  for (unsigned i=0;i<sArithBase.nCmdUsed;i++)
242  {
243  if (sArithBase.sCmds[i].tokval==op)
244  return sArithBase.sCmds[i].toktype;
245  }
246  return 0;
247 }
248 
249 /*=================== operations with 2 args.: static proc =================*/
250 /* must be ordered: first operations for chars (infix ops),
251  * then alphabetically */
252 
254 {
255  bigintmat* aa= (bigintmat *)u->Data();
256  int bb = (int)(long)(v->Data());
257  if (errorreported) return TRUE;
258  bigintmat *cc=NULL;
259  switch (iiOp)
260  {
261  case '+': cc=bimAdd(aa,bb); break;
262  case '-': cc=bimSub(aa,bb); break;
263  case '*': cc=bimMult(aa,bb); break;
264  }
265  res->data=(char *)cc;
266  return cc==NULL;
267 }
269 {
270  return jjOP_BIM_I(res, v, u);
271 }
273 {
274  bigintmat* aa= (bigintmat *)u->Data();
275  number bb = (number)(v->Data());
276  if (errorreported) return TRUE;
277  bigintmat *cc=NULL;
278  switch (iiOp)
279  {
280  case '*': cc=bimMult(aa,bb,coeffs_BIGINT); break;
281  }
282  res->data=(char *)cc;
283  return cc==NULL;
284 }
286 {
287  return jjOP_BIM_BI(res, v, u);
288 }
290 {
291  intvec* aa= (intvec *)u->CopyD(INTVEC_CMD);
292  int bb = (int)(long)(v->Data());
293  if (errorreported) return TRUE;
294  switch (iiOp)
295  {
296  case '+': (*aa) += bb; break;
297  case '-': (*aa) -= bb; break;
298  case '*': (*aa) *= bb; break;
299  case '/':
300  case INTDIV_CMD: (*aa) /= bb; break;
301  case '%': (*aa) %= bb; break;
302  }
303  res->data=(char *)aa;
304  return FALSE;
305 }
307 {
308  return jjOP_IV_I(res,v,u);
309 }
311 {
312  intvec* aa= (intvec *)u->CopyD(INTVEC_CMD);
313  int bb = (int)(long)(v->Data());
314  int i=si_min(aa->rows(),aa->cols());
315  switch (iiOp)
316  {
317  case '+': for (;i>0;i--) IMATELEM(*aa,i,i) += bb;
318  break;
319  case '-': for (;i>0;i--) IMATELEM(*aa,i,i) -= bb;
320  break;
321  }
322  res->data=(char *)aa;
323  return FALSE;
324 }
326 {
327  return jjOP_IM_I(res,v,u);
328 }
330 {
331  int l=(int)(long)v->Data();
332  if (l>=0)
333  {
334  int d=(int)(long)u->Data();
335  intvec *vv=new intvec(l);
336  int i;
337  for(i=l-1;i>=0;i--) { (*vv)[i]=d; }
338  res->data=(char *)vv;
339  }
340  return (l<0);
341 }
343 {
344  res->data=(char *)new intvec((int)(long)u->Data(),(int)(long)v->Data());
345  return FALSE;
346 }
347 static void jjEQUAL_REST(leftv res,leftv u,leftv v);
349 {
350  intvec* a = (intvec * )(u->Data());
351  intvec* b = (intvec * )(v->Data());
352  int r=a->compare(b);
353  switch (iiOp)
354  {
355  case '<':
356  res->data = (char *) (r<0);
357  break;
358  case '>':
359  res->data = (char *) (r>0);
360  break;
361  case LE:
362  res->data = (char *) (r<=0);
363  break;
364  case GE:
365  res->data = (char *) (r>=0);
366  break;
367  case EQUAL_EQUAL:
368  case NOTEQUAL: /* negation handled by jjEQUAL_REST */
369  res->data = (char *) (r==0);
370  break;
371  }
372  jjEQUAL_REST(res,u,v);
373  if(r==-2) { WerrorS("size incompatible"); return TRUE; }
374  return FALSE;
375 }
377 {
378  bigintmat* a = (bigintmat * )(u->Data());
379  bigintmat* b = (bigintmat * )(v->Data());
380  int r=a->compare(b);
381  switch (iiOp)
382  {
383  case '<':
384  res->data = (char *) (r<0);
385  break;
386  case '>':
387  res->data = (char *) (r>0);
388  break;
389  case LE:
390  res->data = (char *) (r<=0);
391  break;
392  case GE:
393  res->data = (char *) (r>=0);
394  break;
395  case EQUAL_EQUAL:
396  case NOTEQUAL: /* negation handled by jjEQUAL_REST */
397  res->data = (char *) (r==0);
398  break;
399  }
400  jjEQUAL_REST(res,u,v);
401  if(r==-2) { WerrorS("size incompatible"); return TRUE; }
402  return FALSE;
403 }
405 {
406  intvec* a = (intvec * )(u->Data());
407  int b = (int)(long)(v->Data());
408  int r=a->compare(b);
409  switch (iiOp)
410  {
411  case '<':
412  res->data = (char *) (r<0);
413  break;
414  case '>':
415  res->data = (char *) (r>0);
416  break;
417  case LE:
418  res->data = (char *) (r<=0);
419  break;
420  case GE:
421  res->data = (char *) (r>=0);
422  break;
423  case EQUAL_EQUAL:
424  case NOTEQUAL: /* negation handled by jjEQUAL_REST */
425  res->data = (char *) (r==0);
426  break;
427  }
428  jjEQUAL_REST(res,u,v);
429  return FALSE;
430 }
432 {
433  //Print("in: >>%s<<\n",my_yylinebuf);
434  matrix a=(matrix)u->Data();
435  matrix b=(matrix)v->Data();
436  int r=mp_Compare(a,b,currRing);
437  switch (iiOp)
438  {
439  case '<':
440  res->data = (char *) (long)(r < 0);
441  break;
442  case '>':
443  res->data = (char *) (long)(r > 0);
444  break;
445  case LE:
446  res->data = (char *) (long)(r <= 0);
447  break;
448  case GE:
449  res->data = (char *) (long)(r >= 0);
450  break;
451  case EQUAL_EQUAL:
452  case NOTEQUAL: /* negation handled by jjEQUAL_REST */
453  res->data = (char *)(long) (r == 0);
454  break;
455  }
456  jjEQUAL_REST(res,u,v);
457  return FALSE;
458 }
460 {
461  poly p=(poly)u->Data();
462  poly q=(poly)v->Data();
463  int r=p_Compare(p,q,currRing);
464  switch (iiOp)
465  {
466  case '<':
467  res->data = (char *) (r < 0);
468  break;
469  case '>':
470  res->data = (char *) (r > 0);
471  break;
472  case LE:
473  res->data = (char *) (r <= 0);
474  break;
475  case GE:
476  res->data = (char *) (r >= 0);
477  break;
478  //case EQUAL_EQUAL:
479  //case NOTEQUAL: /* negation handled by jjEQUAL_REST */
480  // res->data = (char *) (r == 0);
481  // break;
482  }
483  jjEQUAL_REST(res,u,v);
484  return FALSE;
485 }
487 {
488  char* a = (char * )(u->Data());
489  char* b = (char * )(v->Data());
490  int result = strcmp(a,b);
491  switch (iiOp)
492  {
493  case '<':
494  res->data = (char *) (result < 0);
495  break;
496  case '>':
497  res->data = (char *) (result > 0);
498  break;
499  case LE:
500  res->data = (char *) (result <= 0);
501  break;
502  case GE:
503  res->data = (char *) (result >= 0);
504  break;
505  case EQUAL_EQUAL:
506  case NOTEQUAL: /* negation handled by jjEQUAL_REST */
507  res->data = (char *) (result == 0);
508  break;
509  }
510  jjEQUAL_REST(res,u,v);
511  return FALSE;
512 }
513 static BOOLEAN jjOP_REST(leftv res, leftv u, leftv v)
514 {
515  if (u->Next()!=NULL)
516  {
517  u=u->next;
518  res->next = (leftv)omAllocBin(sleftv_bin);
519  return iiExprArith2(res->next,u,iiOp,v);
520  }
521  else if (v->Next()!=NULL)
522  {
523  v=v->next;
524  res->next = (leftv)omAllocBin(sleftv_bin);
525  return iiExprArith2(res->next,u,iiOp,v);
526  }
527  return FALSE;
528 }
529 static BOOLEAN jjPOWER_I(leftv res, leftv u, leftv v)
530 {
531  int b=(int)(long)u->Data();
532  int e=(int)(long)v->Data();
533  int rc = 1;
534  BOOLEAN overflow=FALSE;
535  if (e >= 0)
536  {
537  if (b==0)
538  {
539  rc=(e==0);
540  }
541  else if ((e==0)||(b==1))
542  {
543  rc= 1;
544  }
545  else if (b== -1)
546  {
547  if (e&1) rc= -1;
548  else rc= 1;
549  }
550  else
551  {
552  int oldrc;
553  while ((e--)!=0)
554  {
555  oldrc=rc;
556  rc *= b;
557  if (!overflow)
558  {
559  if(rc/b!=oldrc) overflow=TRUE;
560  }
561  }
562  if (overflow)
563  WarnS("int overflow(^), result may be wrong");
564  }
565  res->data = (char *)((long)rc);
566  if (u!=NULL) return jjOP_REST(res,u,v);
567  return FALSE;
568  }
569  else
570  {
571  WerrorS("exponent must be non-negative");
572  return TRUE;
573  }
574 }
575 static BOOLEAN jjPOWER_BI(leftv res, leftv u, leftv v)
576 {
577  int e=(int)(long)v->Data();
578  number n=(number)u->Data();
579  if (e>=0)
580  {
581  n_Power(n,e,(number*)&res->data,coeffs_BIGINT);
582  }
583  else
584  {
585  WerrorS("exponent must be non-negative");
586  return TRUE;
587  }
588  if (u!=NULL) return jjOP_REST(res,u,v);
589  return FALSE;
590 }
591 static BOOLEAN jjPOWER_N(leftv res, leftv u, leftv v)
592 {
593  int e=(int)(long)v->Data();
594  number n=(number)u->Data();
595  int d=0;
596  if (e<0)
597  {
598  n=nInvers(n);
599  e=-e;
600  d=1;
601  }
602  number r;
603  nPower(n,e,(number*)&r);
604  res->data=(char*)r;
605  if (d) nDelete(&n);
606  if (u!=NULL) return jjOP_REST(res,u,v);
607  return FALSE;
608 }
609 static BOOLEAN jjPOWER_P(leftv res, leftv u, leftv v)
610 {
611  int v_i=(int)(long)v->Data();
612  if (v_i<0)
613  {
614  WerrorS("exponent must be non-negative");
615  return TRUE;
616  }
617  poly u_p=(poly)u->CopyD(POLY_CMD);
618  if ((u_p!=NULL)
619  && ((v_i!=0) &&
620  ((long)pTotaldegree(u_p) > (signed long)currRing->bitmask / (signed long)v_i/2)))
621  {
622  Werror("OVERFLOW in power(d=%ld, e=%d, max=%ld)",
623  pTotaldegree(u_p),v_i,currRing->bitmask/2);
624  pDelete(&u_p);
625  return TRUE;
626  }
627  res->data = (char *)pPower(u_p,v_i);
628  if (u!=NULL) return jjOP_REST(res,u,v);
629  return errorreported; /* pPower may set errorreported via Werror */
630 }
631 static BOOLEAN jjPOWER_ID(leftv res, leftv u, leftv v)
632 {
633  res->data = (char *)id_Power((ideal)(u->Data()),(int)(long)(v->Data()), currRing);
634  if (u!=NULL) return jjOP_REST(res,u,v);
635  return FALSE;
636 }
638 {
639  u=u->next;
640  v=v->next;
641  if (u==NULL)
642  {
643  if (v==NULL) return FALSE; /* u==NULL, v==NULL */
644  if (iiOp=='-') /* u==NULL, v<>NULL, iiOp=='-'*/
645  {
646  do
647  {
648  if (res->next==NULL)
649  res->next = (leftv)omAlloc0Bin(sleftv_bin);
650  leftv tmp_v=v->next;
651  v->next=NULL;
652  BOOLEAN b=iiExprArith1(res->next,v,'-');
653  v->next=tmp_v;
654  if (b)
655  return TRUE;
656  v=tmp_v;
657  res=res->next;
658  } while (v!=NULL);
659  return FALSE;
660  }
661  loop /* u==NULL, v<>NULL, iiOp=='+' */
662  {
663  res->next = (leftv)omAlloc0Bin(sleftv_bin);
664  res=res->next;
665  res->data = v->CopyD();
666  res->rtyp = v->Typ();
667  v=v->next;
668  if (v==NULL) return FALSE;
669  }
670  }
671  if (v!=NULL) /* u<>NULL, v<>NULL */
672  {
673  do
674  {
675  res->next = (leftv)omAlloc0Bin(sleftv_bin);
676  leftv tmp_u=u->next; u->next=NULL;
677  leftv tmp_v=v->next; v->next=NULL;
678  BOOLEAN b=iiExprArith2(res->next,u,iiOp,v);
679  u->next=tmp_u;
680  v->next=tmp_v;
681  if (b)
682  return TRUE;
683  u=tmp_u;
684  v=tmp_v;
685  res=res->next;
686  } while ((u!=NULL) && (v!=NULL));
687  return FALSE;
688  }
689  loop /* u<>NULL, v==NULL */
690  {
691  res->next = (leftv)omAlloc0Bin(sleftv_bin);
692  res=res->next;
693  res->data = u->CopyD();
694  res->rtyp = u->Typ();
695  u=u->next;
696  if (u==NULL) return FALSE;
697  }
698 }
699 static BOOLEAN jjCOLCOL(leftv res, leftv u, leftv v)
700 {
701  switch(u->Typ())
702  {
703  case 0:
704  {
705  int name_err=0;
706  if(isupper(u->name[0]))
707  {
708  const char *c=u->name+1;
709  while((*c!='\0')&&(islower(*c)||(isdigit(*c)))) c++;
710  if (*c!='\0')
711  name_err=1;
712  else
713  {
714  Print("%s of type 'ANY'. Trying load.\n", u->name);
715  if(iiTryLoadLib(u, u->name))
716  {
717  Werror("'%s' no such package", u->name);
718  return TRUE;
719  }
720  syMake(u,u->name,NULL);
721  }
722  }
723  else name_err=1;
724  if(name_err)
725  { Werror("'%s' is an invalid package name",u->name);return TRUE;}
726  // and now, after the loading: use next case !!! no break !!!
727  }
728  case PACKAGE_CMD:
729  {
730  package pa=(package)u->Data();
731  if (u->rtyp==IDHDL) pa=IDPACKAGE((idhdl)u->data);
732  if((!pa->loaded)
733  && (pa->language > LANG_TOP))
734  {
735  Werror("'%s' not loaded", u->name);
736  return TRUE;
737  }
738  if(v->rtyp == IDHDL)
739  {
740  v->name = omStrDup(v->name);
741  }
742  else if (v->rtyp!=0)
743  {
744  WerrorS("reserved name with ::");
745  return TRUE;
746  }
747  v->req_packhdl=pa;
748  syMake(v, v->name, pa);
749  memcpy(res, v, sizeof(sleftv));
750  memset(v, 0, sizeof(sleftv));
751  }
752  break;
753  case DEF_CMD:
754  break;
755  default:
756  WerrorS("<package>::<id> expected");
757  return TRUE;
758  }
759  return FALSE;
760 }
761 static BOOLEAN jjPLUS_I(leftv res, leftv u, leftv v)
762 {
763  unsigned int a=(unsigned int)(unsigned long)u->Data();
764  unsigned int b=(unsigned int)(unsigned long)v->Data();
765  unsigned int c=a+b;
766  res->data = (char *)((long)c);
767  if (((Sy_bit(31)&a)==(Sy_bit(31)&b))&&((Sy_bit(31)&a)!=(Sy_bit(31)&c)))
768  {
769  WarnS("int overflow(+), result may be wrong");
770  }
771  return jjPLUSMINUS_Gen(res,u,v);
772 }
773 static BOOLEAN jjPLUS_BI(leftv res, leftv u, leftv v)
774 {
775  res->data = (char *)(n_Add((number)u->Data(), (number)v->Data(),coeffs_BIGINT));
776  return jjPLUSMINUS_Gen(res,u,v);
777 }
778 static BOOLEAN jjPLUS_N(leftv res, leftv u, leftv v)
779 {
780  res->data = (char *)(nAdd((number)u->Data(), (number)v->Data()));
781  return jjPLUSMINUS_Gen(res,u,v);
782 }
783 static BOOLEAN jjPLUS_P(leftv res, leftv u, leftv v)
784 {
785  res->data = (char *)(pAdd((poly)u->CopyD(POLY_CMD) , (poly)v->CopyD(POLY_CMD)));
786  return jjPLUSMINUS_Gen(res,u,v);
787 }
788 static BOOLEAN jjPLUS_IV(leftv res, leftv u, leftv v)
789 {
790  res->data = (char *)ivAdd((intvec*)(u->Data()), (intvec*)(v->Data()));
791  if (res->data==NULL)
792  {
793  WerrorS("intmat size not compatible");
794  return TRUE;
795  }
796  return jjPLUSMINUS_Gen(res,u,v);
797 }
798 static BOOLEAN jjPLUS_BIM(leftv res, leftv u, leftv v)
799 {
800  res->data = (char *)bimAdd((bigintmat*)(u->Data()), (bigintmat*)(v->Data()));
801  if (res->data==NULL)
802  {
803  WerrorS("bigintmat/cmatrix not compatible");
804  return TRUE;
805  }
806  return jjPLUSMINUS_Gen(res,u,v);
807 }
808 static BOOLEAN jjPLUS_MA(leftv res, leftv u, leftv v)
809 {
810  matrix A=(matrix)u->Data(); matrix B=(matrix)v->Data();
811  res->data = (char *)(mp_Add(A , B, currRing));
812  if (res->data==NULL)
813  {
814  Werror("matrix size not compatible(%dx%d, %dx%d)",
815  MATROWS(A),MATCOLS(A),MATROWS(B),MATCOLS(B));
816  return TRUE;
817  }
818  return jjPLUSMINUS_Gen(res,u,v);
819 }
821 {
822  matrix m=(matrix)u->Data();
824  if (iiOp=='+')
825  res->data = (char *)mp_Add(m , p,currRing);
826  else
827  res->data = (char *)mp_Sub(m , p,currRing);
828  idDelete((ideal *)&p);
829  return jjPLUSMINUS_Gen(res,u,v);
830 }
832 {
833  return jjPLUS_MA_P(res,v,u);
834 }
835 static BOOLEAN jjPLUS_S(leftv res, leftv u, leftv v)
836 {
837  char* a = (char * )(u->Data());
838  char* b = (char * )(v->Data());
839  char* r = (char * )omAlloc(strlen(a) + strlen(b) + 1);
840  strcpy(r,a);
841  strcat(r,b);
842  res->data=r;
843  return jjPLUSMINUS_Gen(res,u,v);
844 }
845 static BOOLEAN jjPLUS_ID(leftv res, leftv u, leftv v)
846 {
847  res->data = (char *)idAdd((ideal)u->Data(),(ideal)v->Data());
848  return jjPLUSMINUS_Gen(res,u,v);
849 }
850 static BOOLEAN jjMINUS_I(leftv res, leftv u, leftv v)
851 {
852  void *ap=u->Data(); void *bp=v->Data();
853  int aa=(int)(long)ap;
854  int bb=(int)(long)bp;
855  int cc=aa-bb;
856  unsigned int a=(unsigned int)(unsigned long)ap;
857  unsigned int b=(unsigned int)(unsigned long)bp;
858  unsigned int c=a-b;
859  if (((Sy_bit(31)&a)!=(Sy_bit(31)&b))&&((Sy_bit(31)&a)!=(Sy_bit(31)&c)))
860  {
861  WarnS("int overflow(-), result may be wrong");
862  }
863  res->data = (char *)((long)cc);
864  return jjPLUSMINUS_Gen(res,u,v);
865 }
866 static BOOLEAN jjMINUS_BI(leftv res, leftv u, leftv v)
867 {
868  res->data = (char *)(n_Sub((number)u->Data(), (number)v->Data(),coeffs_BIGINT));
869  return jjPLUSMINUS_Gen(res,u,v);
870 }
871 static BOOLEAN jjMINUS_N(leftv res, leftv u, leftv v)
872 {
873  res->data = (char *)(nSub((number)u->Data(), (number)v->Data()));
874  return jjPLUSMINUS_Gen(res,u,v);
875 }
876 static BOOLEAN jjMINUS_P(leftv res, leftv u, leftv v)
877 {
878  res->data = (char *)(pSub((poly)u->CopyD(POLY_CMD) , (poly)v->CopyD(POLY_CMD)));
879  return jjPLUSMINUS_Gen(res,u,v);
880 }
881 static BOOLEAN jjMINUS_IV(leftv res, leftv u, leftv v)
882 {
883  res->data = (char *)ivSub((intvec*)(u->Data()), (intvec*)(v->Data()));
884  if (res->data==NULL)
885  {
886  WerrorS("intmat size not compatible");
887  return TRUE;
888  }
889  return jjPLUSMINUS_Gen(res,u,v);
890 }
892 {
893  res->data = (char *)bimSub((bigintmat*)(u->Data()), (bigintmat*)(v->Data()));
894  if (res->data==NULL)
895  {
896  WerrorS("bigintmat/cmatrix not compatible");
897  return TRUE;
898  }
899  return jjPLUSMINUS_Gen(res,u,v);
900 }
901 static BOOLEAN jjMINUS_MA(leftv res, leftv u, leftv v)
902 {
903  matrix A=(matrix)u->Data(); matrix B=(matrix)v->Data();
904  res->data = (char *)(mp_Sub(A , B, currRing));
905  if (res->data==NULL)
906  {
907  Werror("matrix size not compatible(%dx%d, %dx%d)",
908  MATROWS(A),MATCOLS(A),MATROWS(B),MATCOLS(B));
909  return TRUE;
910  }
911  return jjPLUSMINUS_Gen(res,u,v);
912  return FALSE;
913 }
914 static BOOLEAN jjTIMES_I(leftv res, leftv u, leftv v)
915 {
916  int a=(int)(long)u->Data();
917  int b=(int)(long)v->Data();
918  int64 c=(int64)a * (int64)b;
919  if ((c>INT_MAX)||(c<INT_MIN))
920  WarnS("int overflow(*), result may be wrong");
921  res->data = (char *)((long)((int)c));
922  if ((u->Next()!=NULL) || (v->Next()!=NULL))
923  return jjOP_REST(res,u,v);
924  return FALSE;
925 }
926 static BOOLEAN jjTIMES_BI(leftv res, leftv u, leftv v)
927 {
928  res->data = (char *)(n_Mult( (number)u->Data(), (number)v->Data(),coeffs_BIGINT));
929  if ((v->next!=NULL) || (u->next!=NULL))
930  return jjOP_REST(res,u,v);
931  return FALSE;
932 }
933 static BOOLEAN jjTIMES_N(leftv res, leftv u, leftv v)
934 {
935  res->data = (char *)(nMult( (number)u->Data(), (number)v->Data()));
936  number n=(number)res->data;
937  nNormalize(n);
938  res->data=(char *)n;
939  if ((v->next!=NULL) || (u->next!=NULL))
940  return jjOP_REST(res,u,v);
941  return FALSE;
942 }
943 static BOOLEAN jjTIMES_P(leftv res, leftv u, leftv v)
944 {
945  poly a;
946  poly b;
947  if (v->next==NULL)
948  {
949  a=(poly)u->CopyD(POLY_CMD); // works also for VECTOR_CMD
950  if (u->next==NULL)
951  {
952  b=(poly)v->CopyD(POLY_CMD); // works also for VECTOR_CMD
953  if ((a!=NULL) && (b!=NULL)
954  && ((long)pTotaldegree(a)>si_max((long)rVar(currRing),(long)currRing->bitmask/2)-(long)pTotaldegree(b)))
955  {
956  Warn("possible OVERFLOW in mult(d=%ld, d=%ld, max=%ld)",
957  pTotaldegree(a),pTotaldegree(b),currRing->bitmask/2);
958  }
959  res->data = (char *)(pMult( a, b));
960  pNormalize((poly)res->data);
961  return FALSE;
962  }
963  // u->next exists: copy v
964  b=pCopy((poly)v->Data());
965  if ((a!=NULL) && (b!=NULL)
966  && (pTotaldegree(a)+pTotaldegree(b)>si_max((long)rVar(currRing),(long)currRing->bitmask/2)))
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 jjOP_REST(res,u,v);
974  }
975  // v->next exists: copy u
976  a=pCopy((poly)u->Data());
977  b=(poly)v->CopyD(POLY_CMD); // works also for VECTOR_CMD
978  if ((a!=NULL) && (b!=NULL)
979  && ((unsigned long)(pTotaldegree(a)+pTotaldegree(b))>=currRing->bitmask/2))
980  {
981  pDelete(&a);
982  pDelete(&b);
983  WerrorS("OVERFLOW");
984  return TRUE;
985  }
986  res->data = (char *)(pMult( a, b));
987  pNormalize((poly)res->data);
988  return jjOP_REST(res,u,v);
989 }
990 static BOOLEAN jjTIMES_ID(leftv res, leftv u, leftv v)
991 {
992  res->data = (char *)idMult((ideal)u->Data(),(ideal)v->Data());
993  id_Normalize((ideal)res->data,currRing);
994  if ((v->next!=NULL) || (u->next!=NULL))
995  return jjOP_REST(res,u,v);
996  return FALSE;
997 }
998 static BOOLEAN jjTIMES_IV(leftv res, leftv u, leftv v)
999 {
1000  res->data = (char *)ivMult((intvec*)(u->Data()), (intvec*)(v->Data()));
1001  if (res->data==NULL)
1002  {
1003  WerrorS("intmat size not compatible");
1004  return TRUE;
1005  }
1006  if ((v->next!=NULL) || (u->next!=NULL))
1007  return jjOP_REST(res,u,v);
1008  return FALSE;
1009 }
1011 {
1012  res->data = (char *)bimMult((bigintmat*)(u->Data()), (bigintmat*)(v->Data()));
1013  if (res->data==NULL)
1014  {
1015  WerrorS("bigintmat/cmatrix 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 {
1025  if (nMap==NULL) return TRUE;
1026  number n=nMap((number)v->Data(),coeffs_BIGINT,currRing->cf);
1027  poly p=pNSet(n);
1028  ideal I= (ideal)mp_MultP((matrix)u->CopyD(MATRIX_CMD),p,currRing);
1029  res->data = (char *)I;
1030  return FALSE;
1031 }
1033 {
1034  return jjTIMES_MA_BI1(res,v,u);
1035 }
1037 {
1038  poly p=(poly)v->CopyD(POLY_CMD);
1039  int r=pMaxComp(p);/* recompute the rank for the case ideal*vector*/
1040  ideal I= (ideal)mp_MultP((matrix)u->CopyD(MATRIX_CMD),p,currRing);
1041  if (r>0) I->rank=r;
1043  res->data = (char *)I;
1044  return FALSE;
1045 }
1047 {
1048  poly p=(poly)u->CopyD(POLY_CMD);
1049  int r=pMaxComp(p);/* recompute the rank for the case ideal*vector*/
1050  ideal I= (ideal)pMultMp(p,(matrix)v->CopyD(MATRIX_CMD),currRing);
1051  if (r>0) I->rank=r;
1053  res->data = (char *)I;
1054  return FALSE;
1055 }
1057 {
1058  number n=(number)v->CopyD(NUMBER_CMD);
1059  poly p=pNSet(n);
1060  res->data = (char *)mp_MultP((matrix)u->CopyD(MATRIX_CMD),p,currRing);
1061  id_Normalize((ideal)res->data,currRing);
1062  return FALSE;
1063 }
1065 {
1066  return jjTIMES_MA_N1(res,v,u);
1067 }
1069 {
1070  res->data = (char *)mp_MultI((matrix)u->CopyD(MATRIX_CMD),(int)(long)v->Data(),currRing);
1071  id_Normalize((ideal)res->data,currRing);
1072  return FALSE;
1073 }
1075 {
1076  return jjTIMES_MA_I1(res,v,u);
1077 }
1079 {
1080  matrix A=(matrix)u->Data(); matrix B=(matrix)v->Data();
1081  res->data = (char *)mp_Mult(A,B,currRing);
1082  if (res->data==NULL)
1083  {
1084  Werror("matrix size not compatible(%dx%d, %dx%d) in *",
1085  MATROWS(A),MATCOLS(A),MATROWS(B),MATCOLS(B));
1086  return TRUE;
1087  }
1088  id_Normalize((ideal)res->data,currRing);
1089  if ((v->next!=NULL) || (u->next!=NULL))
1090  return jjOP_REST(res,u,v);
1091  return FALSE;
1092 }
1093 static BOOLEAN jjGE_BI(leftv res, leftv u, leftv v)
1094 {
1095  number h=n_Sub((number)u->Data(),(number)v->Data(),coeffs_BIGINT);
1096  res->data = (char *) (n_GreaterZero(h,coeffs_BIGINT)||(n_IsZero(h,coeffs_BIGINT)));
1097  n_Delete(&h,coeffs_BIGINT);
1098  return FALSE;
1099 }
1100 static BOOLEAN jjGE_I(leftv res, leftv u, leftv v)
1101 {
1102  res->data = (char *)(long)((int)((long)u->Data()) >= (int)((long)v->Data()));
1103  return FALSE;
1104 }
1105 static BOOLEAN jjGE_N(leftv res, leftv u, leftv v)
1106 {
1107  res->data = (char *)(long) (nGreater((number)u->Data(),(number)v->Data())
1108  || nEqual((number)u->Data(),(number)v->Data()));
1109  return FALSE;
1110 }
1111 static BOOLEAN jjGT_BI(leftv res, leftv u, leftv v)
1112 {
1113  number h=n_Sub((number)u->Data(),(number)v->Data(),coeffs_BIGINT);
1114  res->data = (char *)(long) (n_GreaterZero(h,coeffs_BIGINT)&&(!n_IsZero(h,coeffs_BIGINT)));
1115  n_Delete(&h,coeffs_BIGINT);
1116  return FALSE;
1117 }
1118 static BOOLEAN jjGT_I(leftv res, leftv u, leftv v)
1119 {
1120  res->data = (char *)(long)((int)((long)u->Data()) > (int)((long)v->Data()));
1121  return FALSE;
1122 }
1123 static BOOLEAN jjGT_N(leftv res, leftv u, leftv v)
1124 {
1125  res->data = (char *)(long)(nGreater((number)u->Data(),(number)v->Data()));
1126  return FALSE;
1127 }
1128 static BOOLEAN jjLE_BI(leftv res, leftv u, leftv v)
1129 {
1130  return jjGE_BI(res,v,u);
1131 }
1132 static BOOLEAN jjLE_I(leftv res, leftv u, leftv v)
1133 {
1134  res->data = (char *)(long)((int)((long)u->Data()) <= (int)((long)v->Data()));
1135  return FALSE;
1136 }
1137 static BOOLEAN jjLE_N(leftv res, leftv u, leftv v)
1138 {
1139  return jjGE_N(res,v,u);
1140 }
1141 static BOOLEAN jjLT_BI(leftv res, leftv u, leftv v)
1142 {
1143  return jjGT_BI(res,v,u);
1144 }
1145 static BOOLEAN jjLT_I(leftv res, leftv u, leftv v)
1146 {
1147  res->data = (char *)(long)((int)((long)u->Data()) < (int)((long)v->Data()));
1148  return FALSE;
1149 }
1150 static BOOLEAN jjLT_N(leftv res, leftv u, leftv v)
1151 {
1152  return jjGT_N(res,v,u);
1153 }
1155 {
1156  if (iiOp=='/') Warn("int division with `/`: use `div` instead in line >>%s<<",my_yylinebuf);
1157  int a= (int)(long)u->Data();
1158  int b= (int)(long)v->Data();
1159  if (b==0)
1160  {
1162  return TRUE;
1163  }
1164  int c=a%b;
1165  int r=0;
1166  switch (iiOp)
1167  {
1168  case '%':
1169  r=c; break;
1170  case '/':
1171  case INTDIV_CMD:
1172  r=((a-c) /b); break;
1173  }
1174  res->data=(void *)((long)r);
1175  return FALSE;
1176 }
1177 static BOOLEAN jjDIV_BI(leftv res, leftv u, leftv v)
1178 {
1179  number q=(number)v->Data();
1180  if (n_IsZero(q,coeffs_BIGINT))
1181  {
1183  return TRUE;
1184  }
1185  q = n_Div((number)u->Data(),q,coeffs_BIGINT);
1187  res->data = (char *)q;
1188  return FALSE;
1189 }
1190 static BOOLEAN jjDIV_N(leftv res, leftv u, leftv v)
1191 {
1192  number q=(number)v->Data();
1193  if (nIsZero(q))
1194  {
1196  return TRUE;
1197  }
1198  q = nDiv((number)u->Data(),q);
1199  nNormalize(q);
1200  res->data = (char *)q;
1201  return FALSE;
1202 }
1203 static BOOLEAN jjDIV_P(leftv res, leftv u, leftv v)
1204 {
1205  poly q=(poly)v->Data();
1206  if (q==NULL)
1207  {
1209  return TRUE;
1210  }
1211  poly p=(poly)(u->Data());
1212  if (p==NULL)
1213  {
1214  res->data=NULL;
1215  return FALSE;
1216  }
1217  if ((pNext(q)!=NULL) && (!rField_is_Ring(currRing)))
1218  { /* This means that q != 0 consists of at least two terms.
1219  Moreover, currRing is over a field. */
1220  if(pGetComp(p)==0)
1221  {
1222  res->data=(void*)(singclap_pdivide(p /*(poly)(u->Data())*/ ,
1223  q /*(poly)(v->Data())*/ ,currRing));
1224  }
1225  else
1226  {
1227  int comps=pMaxComp(p);
1228  ideal I=idInit(comps,1);
1229  p=pCopy(p);
1230  poly h;
1231  int i;
1232  // conversion to a list of polys:
1233  while (p!=NULL)
1234  {
1235  i=pGetComp(p)-1;
1236  h=pNext(p);
1237  pNext(p)=NULL;
1238  pSetComp(p,0);
1239  I->m[i]=pAdd(I->m[i],p);
1240  p=h;
1241  }
1242  // division and conversion to vector:
1243  h=NULL;
1244  p=NULL;
1245  for(i=comps-1;i>=0;i--)
1246  {
1247  if (I->m[i]!=NULL)
1248  {
1249  h=singclap_pdivide(I->m[i],q,currRing);
1250  pSetCompP(h,i+1);
1251  p=pAdd(p,h);
1252  }
1253  }
1254  idDelete(&I);
1255  res->data=(void *)p;
1256  }
1257  }
1258  else
1259  { /* This means that q != 0 consists of just one term,
1260  or that currRing is over a coefficient ring. */
1261 #ifdef HAVE_RINGS
1262  if (!rField_is_Domain(currRing))
1263  {
1264  WerrorS("division only defined over coefficient domains");
1265  return TRUE;
1266  }
1267  if (pNext(q)!=NULL)
1268  {
1269  WerrorS("division over a coefficient domain only implemented for terms");
1270  return TRUE;
1271  }
1272 #endif
1273  res->data = (char *)pDivideM(pCopy(p),pHead(q));
1274  }
1275  pNormalize((poly)res->data);
1276  return FALSE;
1277 }
1278 static BOOLEAN jjDIV_Ma(leftv res, leftv u, leftv v)
1279 {
1280  poly q=(poly)v->Data();
1281  if (q==NULL)
1282  {
1284  return TRUE;
1285  }
1286  matrix m=(matrix)(u->Data());
1287  int r=m->rows();
1288  int c=m->cols();
1289  matrix mm=mpNew(r,c);
1290  unsigned i,j;
1291  for(i=r;i>0;i--)
1292  {
1293  for(j=c;j>0;j--)
1294  {
1295  if (pNext(q)!=NULL)
1296  {
1297  MATELEM(mm,i,j) = singclap_pdivide( MATELEM(m,i,j) ,
1298  q /*(poly)(v->Data())*/, currRing );
1299  }
1300  else
1301  MATELEM(mm,i,j) = pDivideM(pCopy(MATELEM(m,i,j)),pHead(q));
1302  }
1303  }
1304  id_Normalize((ideal)mm,currRing);
1305  res->data=(char *)mm;
1306  return FALSE;
1307 }
1309 {
1310  res->data = (char *)((long)n_Equal((number)u->Data(),(number)v->Data(),coeffs_BIGINT));
1311  jjEQUAL_REST(res,u,v);
1312  return FALSE;
1313 }
1314 static BOOLEAN jjEQUAL_I(leftv res, leftv u, leftv v)
1315 {
1316  res->data = (char *)((int)((long)u->Data()) == (int)((long)v->Data()));
1317  jjEQUAL_REST(res,u,v);
1318  return FALSE;
1319 }
1321 {
1322  res->data = (char *)((long)mp_Equal((matrix)u->Data(),(matrix)v->Data(),currRing));
1323  jjEQUAL_REST(res,u,v);
1324  return FALSE;
1325 }
1326 static BOOLEAN jjEQUAL_R(leftv res, leftv u, leftv v)
1327 {
1328  res->data = (char *)(long)(u->Data()==v->Data());
1329  jjEQUAL_REST(res,u,v);
1330  return FALSE;
1331 }
1332 static BOOLEAN jjEQUAL_N(leftv res, leftv u, leftv v)
1333 {
1334  res->data = (char *)((long)nEqual((number)u->Data(),(number)v->Data()));
1335  jjEQUAL_REST(res,u,v);
1336  return FALSE;
1337 }
1338 static BOOLEAN jjEQUAL_P(leftv res, leftv u, leftv v)
1339 {
1340  poly p=(poly)u->Data();
1341  poly q=(poly)v->Data();
1342  res->data = (char *) ((long)pEqualPolys(p,q));
1343  jjEQUAL_REST(res,u,v);
1344  return FALSE;
1345 }
1346 static void jjEQUAL_REST(leftv res,leftv u,leftv v)
1347 {
1348  if ((res->data) && (u->next!=NULL) && (v->next!=NULL))
1349  {
1350  int save_iiOp=iiOp;
1351  if (iiOp==NOTEQUAL)
1352  iiExprArith2(res,u->next,EQUAL_EQUAL,v->next);
1353  else
1354  iiExprArith2(res,u->next,iiOp,v->next);
1355  iiOp=save_iiOp;
1356  }
1357  if (iiOp==NOTEQUAL) res->data=(char *)(!(long)res->data);
1358 }
1359 static BOOLEAN jjAND_I(leftv res, leftv u, leftv v)
1360 {
1361  res->data = (char *)((long)u->Data() && (long)v->Data());
1362  return FALSE;
1363 }
1364 static BOOLEAN jjOR_I(leftv res, leftv u, leftv v)
1365 {
1366  res->data = (char *)((long)u->Data() || (long)v->Data());
1367  return FALSE;
1368 }
1369 static BOOLEAN jjINDEX_I(leftv res, leftv u, leftv v)
1370 {
1371  res->rtyp=u->rtyp; u->rtyp=0;
1372  res->data=u->data; u->data=NULL;
1373  res->name=u->name; u->name=NULL;
1374  res->e=u->e; u->e=NULL;
1375  if (res->e==NULL) res->e=jjMakeSub(v);
1376  else
1377  {
1378  Subexpr sh=res->e;
1379  while (sh->next != NULL) sh=sh->next;
1380  sh->next=jjMakeSub(v);
1381  }
1382  if (u->next!=NULL)
1383  {
1385  BOOLEAN bo=iiExprArith2(rn,u->next,iiOp,v);
1386  res->next=rn;
1387  return bo;
1388  }
1389  return FALSE;
1390 }
1392 {
1393  if ((u->rtyp!=IDHDL)||(u->e!=NULL))
1394  {
1395  WerrorS("indexed object must have a name");
1396  return TRUE;
1397  }
1398  intvec * iv=(intvec *)v->Data();
1399  leftv p=NULL;
1400  int i;
1401  sleftv t;
1402  memset(&t,0,sizeof(t));
1403  t.rtyp=INT_CMD;
1404  for (i=0;i<iv->length(); i++)
1405  {
1406  t.data=(char *)((long)(*iv)[i]);
1407  if (p==NULL)
1408  {
1409  p=res;
1410  }
1411  else
1412  {
1414  p=p->next;
1415  }
1416  p->rtyp=IDHDL;
1417  p->data=u->data;
1418  p->name=u->name;
1419  p->flag=u->flag;
1420  p->e=jjMakeSub(&t);
1421  }
1422  u->rtyp=0;
1423  u->data=NULL;
1424  u->name=NULL;
1425  return FALSE;
1426 }
1427 static BOOLEAN jjINDEX_P(leftv res, leftv u, leftv v)
1428 {
1429  poly p=(poly)u->Data();
1430  int i=(int)(long)v->Data();
1431  int j=0;
1432  while (p!=NULL)
1433  {
1434  j++;
1435  if (j==i)
1436  {
1437  res->data=(char *)pHead(p);
1438  return FALSE;
1439  }
1440  pIter(p);
1441  }
1442  return FALSE;
1443 }
1445 {
1446  poly p=(poly)u->Data();
1447  poly r=NULL;
1448  intvec *iv=(intvec *)v->CopyD(INTVEC_CMD);
1449  int i;
1450  int sum=0;
1451  for(i=iv->length()-1;i>=0;i--)
1452  sum+=(*iv)[i];
1453  int j=0;
1454  while ((p!=NULL) && (sum>0))
1455  {
1456  j++;
1457  for(i=iv->length()-1;i>=0;i--)
1458  {
1459  if (j==(*iv)[i])
1460  {
1461  r=pAdd(r,pHead(p));
1462  sum-=j;
1463  (*iv)[i]=0;
1464  break;
1465  }
1466  }
1467  pIter(p);
1468  }
1469  delete iv;
1470  res->data=(char *)r;
1471  return FALSE;
1472 }
1473 static BOOLEAN jjINDEX_V(leftv res, leftv u, leftv v)
1474 {
1475  poly p=(poly)u->CopyD(VECTOR_CMD);
1476  poly r=p; // pointer to the beginning of component i
1477  poly o=NULL;
1478  int i=(int)(long)v->Data();
1479  while (p!=NULL)
1480  {
1481  if (pGetComp(p)!=i)
1482  {
1483  if (r==p) r=pNext(p);
1484  if (o!=NULL)
1485  {
1486  if (pNext(o)!=NULL) pLmDelete(&pNext(o));
1487  p=pNext(o);
1488  }
1489  else
1490  pLmDelete(&p);
1491  }
1492  else
1493  {
1494  pSetComp(p, 0);
1495  p_SetmComp(p, currRing);
1496  o=p;
1497  p=pNext(o);
1498  }
1499  }
1500  res->data=(char *)r;
1501  return FALSE;
1502 }
1504 {
1505  poly p=(poly)u->CopyD(VECTOR_CMD);
1506  if (p!=NULL)
1507  {
1508  poly r=pOne();
1509  poly hp=r;
1510  intvec *iv=(intvec *)v->Data();
1511  int i;
1512  loop
1513  {
1514  for(i=0;i<iv->length();i++)
1515  {
1516  if (((int)pGetComp(p))==(*iv)[i])
1517  {
1518  poly h;
1519  pSplit(p,&h);
1520  pNext(hp)=p;
1521  p=h;
1522  pIter(hp);
1523  break;
1524  }
1525  }
1526  if (p==NULL) break;
1527  if (i==iv->length())
1528  {
1529  pLmDelete(&p);
1530  if (p==NULL) break;
1531  }
1532  }
1533  pLmDelete(&r);
1534  res->data=(char *)r;
1535  }
1536  return FALSE;
1537 }
1538 static BOOLEAN jjKLAMMER_rest(leftv res, leftv u, leftv v);
1539 static BOOLEAN jjKLAMMER(leftv res, leftv u, leftv v)
1540 {
1541  if(u->name==NULL) return TRUE;
1542  char * nn = (char *)omAlloc(strlen(u->name) + 14);
1543  sprintf(nn,"%s(%d)",u->name,(int)(long)v->Data());
1544  omFree((ADDRESS)u->name);
1545  u->name=NULL;
1546  char *n=omStrDup(nn);
1547  omFree((ADDRESS)nn);
1548  syMake(res,n);
1549  if (u->next!=NULL) return jjKLAMMER_rest(res,u->next,v);
1550  return FALSE;
1551 }
1553 {
1554  intvec * iv=(intvec *)v->Data();
1555  leftv p=NULL;
1556  int i;
1557  long slen = strlen(u->name) + 14;
1558  char *n = (char*) omAlloc(slen);
1559 
1560  for (i=0;i<iv->length(); i++)
1561  {
1562  if (p==NULL)
1563  {
1564  p=res;
1565  }
1566  else
1567  {
1569  p=p->next;
1570  }
1571  sprintf(n,"%s(%d)",u->name,(*iv)[i]);
1572  syMake(p,omStrDup(n));
1573  }
1574  omFree((ADDRESS)u->name);
1575  u->name = NULL;
1576  omFreeSize(n, slen);
1577  if (u->next!=NULL) return jjKLAMMER_rest(res,u->next,v);
1578  return FALSE;
1579 }
1581 {
1583  memset(tmp,0,sizeof(sleftv));
1584  BOOLEAN b;
1585  if (v->Typ()==INTVEC_CMD)
1586  b=jjKLAMMER_IV(tmp,u,v);
1587  else
1588  b=jjKLAMMER(tmp,u,v);
1589  if (b)
1590  {
1591  omFreeBin(tmp,sleftv_bin);
1592  return TRUE;
1593  }
1594  leftv h=res;
1595  while (h->next!=NULL) h=h->next;
1596  h->next=tmp;
1597  return FALSE;
1598 }
1600 {
1601  void *d;
1602  Subexpr e;
1603  int typ;
1604  BOOLEAN t=FALSE;
1605  idhdl tmp_proc=NULL;
1606  if ((u->rtyp!=IDHDL)||(u->e!=NULL))
1607  {
1608  tmp_proc=(idhdl)omAlloc0(sizeof(idrec));
1609  tmp_proc->id="_auto";
1610  tmp_proc->typ=PROC_CMD;
1611  tmp_proc->data.pinf=(procinfo *)u->Data();
1612  tmp_proc->ref=1;
1613  d=u->data; u->data=(void *)tmp_proc;
1614  e=u->e; u->e=NULL;
1615  t=TRUE;
1616  typ=u->rtyp; u->rtyp=IDHDL;
1617  }
1618  BOOLEAN sl;
1619  if (u->req_packhdl==currPack)
1620  sl = iiMake_proc((idhdl)u->data,NULL,v);
1621  else
1622  sl = iiMake_proc((idhdl)u->data,u->req_packhdl,v);
1623  if (t)
1624  {
1625  u->rtyp=typ;
1626  u->data=d;
1627  u->e=e;
1628  omFreeSize(tmp_proc,sizeof(idrec));
1629  }
1630  if (sl) return TRUE;
1631  memcpy(res,&iiRETURNEXPR,sizeof(sleftv));
1632  iiRETURNEXPR.Init();
1633  return FALSE;
1634 }
1635 static BOOLEAN jjMAP(leftv res, leftv u, leftv v)
1636 {
1637  //Print("try to map %s with %s\n",$3.Name(),$1.Name());
1638  leftv sl=NULL;
1639  if ((v->e==NULL)&&(v->name!=NULL))
1640  {
1641  map m=(map)u->Data();
1642  sl=iiMap(m,v->name);
1643  }
1644  else
1645  {
1646  Werror("%s(<name>) expected",u->Name());
1647  }
1648  if (sl==NULL) return TRUE;
1649  memcpy(res,sl,sizeof(sleftv));
1651  return FALSE;
1652 }
1653 static BOOLEAN jjRING_1(leftv res, leftv u, leftv v)
1654 {
1655  u->next=(leftv)omAlloc(sizeof(sleftv));
1656  memcpy(u->next,v,sizeof(sleftv));
1657  memset(v,0,sizeof(sleftv));
1658  BOOLEAN bo=iiExprArithM(res,u,'[');
1659  u->next=NULL;
1660  return bo;
1661 }
1663 {
1664  intvec *c=(intvec*)u->Data();
1665  intvec* p=(intvec*)v->Data();
1666  int rl=p->length();
1667  number *x=(number *)omAlloc(rl*sizeof(number));
1668  number *q=(number *)omAlloc(rl*sizeof(number));
1669  int i;
1670  for(i=rl-1;i>=0;i--)
1671  {
1672  q[i]=n_Init((*p)[i], coeffs_BIGINT);
1673  x[i]=n_Init((*c)[i], coeffs_BIGINT);
1674  }
1675  CFArray iv(rl);
1676  number n=n_ChineseRemainderSym(x,q,rl,FALSE,iv,coeffs_BIGINT);
1677  for(i=rl-1;i>=0;i--)
1678  {
1679  n_Delete(&(q[i]),coeffs_BIGINT);
1680  n_Delete(&(x[i]),coeffs_BIGINT);
1681  }
1682  omFree(x); omFree(q);
1683  res->data=(char *)n;
1684  return FALSE;
1685 }
1686 #if 0
1687 static BOOLEAN jjCHINREM_P(leftv res, leftv u, leftv v)
1688 {
1689  lists c=(lists)u->CopyD(); // list of poly
1690  intvec* p=(intvec*)v->Data();
1691  int rl=p->length();
1692  poly r=NULL,h, result=NULL;
1693  number *x=(number *)omAlloc(rl*sizeof(number));
1694  number *q=(number *)omAlloc(rl*sizeof(number));
1695  int i;
1696  for(i=rl-1;i>=0;i--)
1697  {
1698  q[i]=nlInit((*p)[i]);
1699  }
1700  loop
1701  {
1702  for(i=rl-1;i>=0;i--)
1703  {
1704  if (c->m[i].Typ()!=POLY_CMD)
1705  {
1706  Werror("poly expected at pos %d",i+1);
1707  for(i=rl-1;i>=0;i--)
1708  {
1709  nlDelete(&(q[i]),currRing);
1710  }
1711  omFree(x); omFree(q); // delete c
1712  return TRUE;
1713  }
1714  h=((poly)c->m[i].Data());
1715  if (r==NULL) r=h;
1716  else if (pLmCmp(r,h)==-1) r=h;
1717  }
1718  if (r==NULL) break;
1719  for(i=rl-1;i>=0;i--)
1720  {
1721  h=((poly)c->m[i].Data());
1722  if (pLmCmp(r,h)==0)
1723  {
1724  x[i]=pGetCoeff(h);
1725  h=pLmFreeAndNext(h);
1726  c->m[i].data=(char*)h;
1727  }
1728  else
1729  x[i]=nlInit(0);
1730  }
1731  number n=n_ChineseRemainder(x,q,rl,currRing->cf);
1732  for(i=rl-1;i>=0;i--)
1733  {
1734  nlDelete(&(x[i]),currRing);
1735  }
1736  h=pHead(r);
1737  pSetCoeff(h,n);
1738  result=pAdd(result,h);
1739  }
1740  for(i=rl-1;i>=0;i--)
1741  {
1742  nlDelete(&(q[i]),currRing);
1743  }
1744  omFree(x); omFree(q);
1745  res->data=(char *)result;
1746  return FALSE;
1747 }
1748 #endif
1749 static BOOLEAN jjALIGN_V(leftv res, leftv u, leftv v)
1750 {
1751  poly p=(poly)u->CopyD();
1752  int s=(int)(long)v->Data();
1753  if (s+p_MinComp(p,currRing)<=0)
1754  { p_Delete(&p,currRing);return TRUE;}
1755  p_Shift(&p,s,currRing);
1756  res->data=p;
1757  return FALSE;
1758 }
1759 static BOOLEAN jjALIGN_M(leftv res, leftv u, leftv v)
1760 {
1761  ideal M=(ideal)u->CopyD();
1762  int s=(int)(long)v->Data();
1763  for(int i=IDELEMS(M)-1; i>=0;i--)
1764  {
1765  if (s+p_MinComp(M->m[i],currRing)<=0)
1766  { id_Delete(&M,currRing);return TRUE;}
1767  }
1768  id_Shift(M,s,currRing);
1769  res->data=M;
1770  return FALSE;
1771 }
1772 static BOOLEAN jjCHINREM_ID(leftv res, leftv u, leftv v);
1773 static BOOLEAN jjCOEF(leftv res, leftv u, leftv v)
1774 {
1775  poly p=(poly)v->Data();
1776  if ((p==NULL)||(pNext(p)!=NULL)) return TRUE;
1777  res->data=(char *)mp_CoeffProc((poly)u->Data(),p /*(poly)v->Data()*/,currRing);
1778  return FALSE;
1779 }
1781 {
1782  int i=pVar((poly)v->Data());
1783  if (i==0)
1784  {
1785  WerrorS("ringvar expected");
1786  return TRUE;
1787  }
1788  res->data=(char *)mp_Coeffs((ideal)u->CopyD(),i,currRing);
1789  return FALSE;
1790 }
1792 {
1793  poly p = pInit();
1794  int i;
1795  for (i=1; i<=currRing->N; i++)
1796  {
1797  pSetExp(p, i, 1);
1798  }
1799  pSetm(p);
1800  res->data = (void*)idCoeffOfKBase((ideal)(u->Data()),
1801  (ideal)(v->Data()), p);
1802  pDelete(&p);
1803  return FALSE;
1804 }
1806 {
1807  res->data=(char *)idDiffOp((ideal)u->Data(),(ideal)v->Data(),FALSE);
1808  return FALSE;
1809 }
1811 {
1812  short *iv=iv2array((intvec *)v->Data(),currRing);
1813  ideal I=(ideal)u->Data();
1814  int d=-1;
1815  int i;
1816  for(i=IDELEMS(I);i>=0;i--) d=si_max(d,(int)p_DegW(I->m[i],iv,currRing));
1817  omFreeSize( (ADDRESS)iv, (rVar(currRing)+1)*sizeof(short) );
1818  res->data = (char *)((long)d);
1819  return FALSE;
1820 }
1821 static BOOLEAN jjDEG_IV(leftv res, leftv u, leftv v)
1822 {
1823  poly p=(poly)u->Data();
1824  if (p!=NULL)
1825  {
1826  short *iv=iv2array((intvec *)v->Data(),currRing);
1827  const long d = p_DegW(p,iv,currRing);
1828  omFreeSize( (ADDRESS)iv, (rVar(currRing)+1)*sizeof(short) );
1829  res->data = (char *)(d);
1830  }
1831  else
1832  res->data=(char *)(long)(-1);
1833  return FALSE;
1834 }
1835 static BOOLEAN jjDIFF_P(leftv res, leftv u, leftv v)
1836 {
1837  int i=pVar((poly)v->Data());
1838  if (i==0)
1839  {
1840  WerrorS("ringvar expected");
1841  return TRUE;
1842  }
1843  res->data=(char *)pDiff((poly)(u->Data()),i);
1844  return FALSE;
1845 }
1846 static BOOLEAN jjDIFF_ID(leftv res, leftv u, leftv v)
1847 {
1848  int i=pVar((poly)v->Data());
1849  if (i==0)
1850  {
1851  WerrorS("ringvar expected");
1852  return TRUE;
1853  }
1854  res->data=(char *)idDiff((matrix)(u->Data()),i);
1855  return FALSE;
1856 }
1858 {
1859  res->data=(char *)idDiffOp((ideal)u->Data(),(ideal)v->Data());
1860  return FALSE;
1861 }
1862 static BOOLEAN jjDIM2(leftv res, leftv v, leftv w)
1863 {
1864  assumeStdFlag(v);
1866  {
1867  Warn("dim(%s,...) may be wrong because the mixed monomial ordering",v->Name());
1868  }
1869 #ifdef HAVE_RINGS
1870  if (rField_is_Ring(currRing))
1871  {
1872  ideal vid = (ideal)v->Data();
1873  int i = idPosConstant(vid);
1874  if ((i != -1) && (n_IsUnit(pGetCoeff(vid->m[i]),currRing->cf)))
1875  { /* ideal v contains unit; dim = -1 */
1876  res->data = (char *)-1;
1877  return FALSE;
1878  }
1879  ideal vv = id_Copy(vid, currRing);
1880  ideal ww = id_Copy((ideal)w->Data(), currRing);
1881  /* drop degree zero generator from vv (if any) */
1882  if (i != -1) pDelete(&vv->m[i]);
1883  long d = (long)scDimInt(vv, ww);
1884  if (rField_is_Ring_Z(currRing) && (i == -1)) d++;
1885  res->data = (char *)d;
1886  idDelete(&vv); idDelete(&ww);
1887  return FALSE;
1888  }
1889 #endif
1890  if(currRing->qideal==NULL)
1891  res->data = (char *)((long)scDimInt((ideal)(v->Data()),(ideal)w->Data()));
1892  else
1893  {
1894  ideal q=idSimpleAdd(currRing->qideal,(ideal)w->Data());
1895  res->data = (char *)((long)scDimInt((ideal)(v->Data()),q));
1896  idDelete(&q);
1897  }
1898  return FALSE;
1899 }
1901 {
1902  ideal vi=(ideal)v->Data();
1903  int vl= IDELEMS(vi);
1904  ideal ui=(ideal)u->Data();
1905  unsigned ul= IDELEMS(ui);
1906  ideal R; matrix U;
1907  ideal m = idLift(vi,ui,&R, FALSE,hasFlag(v,FLAG_STD),TRUE,&U);
1908  if (m==NULL) return TRUE;
1909  // now make sure that all matices have the corect size:
1911  int i;
1912  if (MATCOLS(U) != (int)ul)
1913  {
1914  unsigned mul=si_min(ul,MATCOLS(U));
1915  matrix UU=mpNew(ul,ul);
1916  unsigned j;
1917  for(i=mul;i>0;i--)
1918  {
1919  for(j=mul;j>0;j--)
1920  {
1921  MATELEM(UU,i,j)=MATELEM(U,i,j);
1922  MATELEM(U,i,j)=NULL;
1923  }
1924  }
1925  idDelete((ideal *)&U);
1926  U=UU;
1927  }
1928  // make sure that U is a diagonal matrix of units
1929  for(i=ul;i>0;i--)
1930  {
1931  if(MATELEM(U,i,i)==NULL) MATELEM(U,i,i)=pOne();
1932  }
1934  L->Init(3);
1935  L->m[0].rtyp=MATRIX_CMD; L->m[0].data=(void *)T;
1936  L->m[1].rtyp=u->Typ(); L->m[1].data=(void *)R;
1937  L->m[2].rtyp=MATRIX_CMD; L->m[2].data=(void *)U;
1938  res->data=(char *)L;
1939  return FALSE;
1940 }
1941 static BOOLEAN jjELIMIN(leftv res, leftv u, leftv v)
1942 {
1943  res->data=(char *)idElimination((ideal)u->Data(),(poly)v->Data());
1944  //setFlag(res,FLAG_STD);
1945  return v->next!=NULL; //do not allow next like in eliminate(I,a(1..4))
1946 }
1948 {
1949  poly p=pOne();
1950  intvec *iv=(intvec*)v->Data();
1951  for(int i=iv->length()-1; i>=0; i--)
1952  {
1953  pSetExp(p,(*iv)[i],1);
1954  }
1955  pSetm(p);
1956  res->data=(char *)idElimination((ideal)u->Data(),p);
1957  pLmDelete(&p);
1958  //setFlag(res,FLAG_STD);
1959  return FALSE;
1960 }
1962 {
1963  //Print("exportto %s -> %s\n",v->Name(),u->Name() );
1964  return iiExport(v,0,IDPACKAGE((idhdl)u->data));
1965 }
1967 {
1968  WerrorS((char *)u->Data());
1969  extern int inerror;
1970  inerror=3;
1971  return TRUE;
1972 }
1974 {
1975  number uu=(number)u->Data();number vv=(number)v->Data();
1977  number a,b;
1978  number p0=n_ExtGcd(uu,vv,&a,&b,coeffs_BIGINT);
1979  L->Init(3);
1980  L->m[0].rtyp=BIGINT_CMD; L->m[0].data=(void *)p0;
1981  L->m[1].rtyp=BIGINT_CMD; L->m[1].data=(void *)a;
1982  L->m[2].rtyp=BIGINT_CMD; L->m[2].data=(void *)b;
1983  res->rtyp=LIST_CMD;
1984  res->data=(char *)L;
1985  return FALSE;
1986 }
1988 {
1989  int uu=(int)(long)u->Data();int vv=(int)(long)v->Data();
1990  int p0=ABS(uu),p1=ABS(vv);
1991  int f0 = 1, f1 = 0, g0 = 0, g1 = 1, q, r;
1992 
1993  while ( p1!=0 )
1994  {
1995  q=p0 / p1;
1996  r=p0 % p1;
1997  p0 = p1; p1 = r;
1998  r = g0 - g1 * q;
1999  g0 = g1; g1 = r;
2000  r = f0 - f1 * q;
2001  f0 = f1; f1 = r;
2002  }
2003  int a = f0;
2004  int b = g0;
2005  if ( uu /*(int)(long)u->Data()*/ < 0 ) a=-a;
2006  if ( vv /*(int)(long)v->Data()*/ < 0 ) b=-b;
2008  L->Init(3);
2009  L->m[0].rtyp=INT_CMD; L->m[0].data=(void *)(long)p0;
2010  L->m[1].rtyp=INT_CMD; L->m[1].data=(void *)(long)a;
2011  L->m[2].rtyp=INT_CMD; L->m[2].data=(void *)(long)b;
2012  res->rtyp=LIST_CMD;
2013  res->data=(char *)L;
2014  return FALSE;
2015 }
2017 {
2018  poly r,pa,pb;
2019  BOOLEAN ret=singclap_extgcd((poly)u->Data(),(poly)v->Data(),r,pa,pb,currRing);
2020  if (ret) return TRUE;
2022  L->Init(3);
2023  res->data=(char *)L;
2024  L->m[0].data=(void *)r;
2025  L->m[0].rtyp=POLY_CMD;
2026  L->m[1].data=(void *)pa;
2027  L->m[1].rtyp=POLY_CMD;
2028  L->m[2].data=(void *)pb;
2029  L->m[2].rtyp=POLY_CMD;
2030  return FALSE;
2031 }
2032 extern int singclap_factorize_retry;
2033 static BOOLEAN jjFAC_P2(leftv res, leftv u,leftv dummy)
2034 {
2035  intvec *v=NULL;
2036  int sw=(int)(long)dummy->Data();
2037  int fac_sw=sw;
2038  if ((sw<0)||(sw>2)) fac_sw=1;
2039  singclap_factorize_retry=0;
2040  ideal f=singclap_factorize((poly)(u->CopyD()), &v, fac_sw,currRing);
2041  if (f==NULL)
2042  return TRUE;
2043  switch(sw)
2044  {
2045  case 0:
2046  case 2:
2047  {
2049  l->Init(2);
2050  l->m[0].rtyp=IDEAL_CMD;
2051  l->m[0].data=(void *)f;
2052  l->m[1].rtyp=INTVEC_CMD;
2053  l->m[1].data=(void *)v;
2054  res->data=(void *)l;
2055  res->rtyp=LIST_CMD;
2056  return FALSE;
2057  }
2058  case 1:
2059  res->data=(void *)f;
2060  return FALSE;
2061  case 3:
2062  {
2063  poly p=f->m[0];
2064  int i=IDELEMS(f);
2065  f->m[0]=NULL;
2066  while(i>1)
2067  {
2068  i--;
2069  p=pMult(p,f->m[i]);
2070  f->m[i]=NULL;
2071  }
2072  res->data=(void *)p;
2073  res->rtyp=POLY_CMD;
2074  }
2075  return FALSE;
2076  }
2077  WerrorS("invalid switch");
2078  return TRUE;
2079 }
2081 {
2082  ideal_list p,h;
2083  h=kStdfac((ideal)v->Data(),NULL,testHomog,NULL,(ideal)w->Data());
2084  p=h;
2085  int l=0;
2086  while (p!=NULL) { p=p->next;l++; }
2088  L->Init(l);
2089  l=0;
2090  while(h!=NULL)
2091  {
2092  L->m[l].data=(char *)h->d;
2093  L->m[l].rtyp=IDEAL_CMD;
2094  p=h->next;
2095  omFreeSize(h,sizeof(*h));
2096  h=p;
2097  l++;
2098  }
2099  res->data=(void *)L;
2100  return FALSE;
2101 }
2103 {
2104  if (rField_is_Q(currRing))
2105  {
2106  number uu=(number)u->Data();
2107  number vv=(number)v->Data();
2108  res->data=(char *)n_Farey(uu,vv,currRing->cf);
2109  return FALSE;
2110  }
2111  else return TRUE;
2112 }
2114 {
2115  ideal uu=(ideal)u->Data();
2116  number vv=(number)v->Data();
2117  res->data=(void*)id_Farey(uu,vv,currRing);
2118  return FALSE;
2119 }
2120 static BOOLEAN jjFAREY_LI(leftv res, leftv u, leftv v);
2121 static BOOLEAN jjFETCH(leftv res, leftv u, leftv v)
2122 {
2123  ring r=(ring)u->Data();
2124  idhdl w;
2125  int op=iiOp;
2126  nMapFunc nMap;
2127 
2128  if ((w=r->idroot->get(v->Name(),myynest))!=NULL)
2129  {
2130  int *perm=NULL;
2131  int *par_perm=NULL;
2132  int par_perm_size=0;
2133  BOOLEAN bo;
2134  if ((nMap=n_SetMap(r->cf,currRing->cf))==NULL)
2135  {
2136  // Allow imap/fetch to be make an exception only for:
2137  if ( (rField_is_Q_a(r) && // Q(a..) -> Q(a..) || Q || Zp || Zp(a)
2140  ||
2141  (rField_is_Zp_a(r) && // Zp(a..) -> Zp(a..) || Zp
2142  (rField_is_Zp(currRing, r->cf->ch) ||
2143  rField_is_Zp_a(currRing, r->cf->ch))) )
2144  {
2145  par_perm_size=rPar(r);
2146  }
2147  else
2148  {
2149  goto err_fetch;
2150  }
2151  }
2152  if ((iiOp!=FETCH_CMD) || (r->N!=currRing->N) || (rPar(r)!=rPar(currRing)))
2153  {
2154  perm=(int *)omAlloc0((r->N+1)*sizeof(int));
2155  if (par_perm_size!=0)
2156  par_perm=(int *)omAlloc0(par_perm_size*sizeof(int));
2157  op=IMAP_CMD;
2158  if (iiOp==IMAP_CMD)
2159  {
2160  int r_par=0;
2161  char ** r_par_names=NULL;
2162  if (r->cf->extRing!=NULL)
2163  {
2164  r_par=r->cf->extRing->N;
2165  r_par_names=r->cf->extRing->names;
2166  }
2167  int c_par=0;
2168  char ** c_par_names=NULL;
2169  if (currRing->cf->extRing!=NULL)
2170  {
2171  c_par=currRing->cf->extRing->N;
2172  c_par_names=currRing->cf->extRing->names;
2173  }
2174  maFindPerm(r->names, r->N, r_par_names, r_par,
2175  currRing->names,currRing->N,c_par_names, c_par,
2176  perm,par_perm, currRing->cf->type);
2177  }
2178  else
2179  {
2180  unsigned i;
2181  if (par_perm_size!=0)
2182  for(i=si_min(rPar(r),rPar(currRing));i>0;i--) par_perm[i-1]=-i;
2183  for(i=si_min(r->N,currRing->N);i>0;i--) perm[i]=i;
2184  }
2185  }
2186  if ((iiOp==FETCH_CMD) &&(BVERBOSE(V_IMAP)))
2187  {
2188  unsigned i;
2189  for(i=0;i<(unsigned)si_min(r->N,currRing->N);i++)
2190  {
2191  Print("// var nr %d: %s -> %s\n",i,r->names[i],currRing->names[i]);
2192  }
2193  for(i=0;i<(unsigned)si_min(rPar(r),rPar(currRing));i++) // possibly empty loop
2194  {
2195  Print("// par nr %d: %s -> %s\n",
2196  i,rParameter(r)[i],rParameter(currRing)[i]);
2197  }
2198  }
2199  if (IDTYP(w)==ALIAS_CMD) w=(idhdl)IDDATA(w);
2200  sleftv tmpW;
2201  memset(&tmpW,0,sizeof(sleftv));
2202  tmpW.rtyp=IDTYP(w);
2203  tmpW.data=IDDATA(w);
2204  if ((bo=maApplyFetch(op,NULL,res,&tmpW, r,
2205  perm,par_perm,par_perm_size,nMap)))
2206  {
2207  Werror("cannot map %s of type %s(%d)",v->name, Tok2Cmdname(w->typ),w->typ);
2208  }
2209  if (perm!=NULL)
2210  omFreeSize((ADDRESS)perm,(r->N+1)*sizeof(int));
2211  if (par_perm!=NULL)
2212  omFreeSize((ADDRESS)par_perm,par_perm_size*sizeof(int));
2213  return bo;
2214  }
2215  else
2216  {
2217  Werror("identifier %s not found in %s",v->Fullname(),u->Fullname());
2218  }
2219  return TRUE;
2220 err_fetch:
2221  char *s1=nCoeffString(r->cf);
2222  char *s2=nCoeffString(currRing->cf);
2223  Werror("no identity map from %s (%s -> %s)",u->Fullname(),s1,s2);
2224  omFree(s2); omFree(s1);
2225  return TRUE;
2226 }
2227 static BOOLEAN jjFIND2(leftv res, leftv u, leftv v)
2228 {
2229  /*4
2230  * look for the substring what in the string where
2231  * return the position of the first char of what in where
2232  * or 0
2233  */
2234  char *where=(char *)u->Data();
2235  char *what=(char *)v->Data();
2236  char *found = strstr(where,what);
2237  if (found != NULL)
2238  {
2239  res->data=(char *)((found-where)+1);
2240  }
2241  /*else res->data=NULL;*/
2242  return FALSE;
2243 }
2244 static BOOLEAN jjFWALK(leftv res, leftv u, leftv v)
2245 {
2246  res->data=(char *)fractalWalkProc(u,v);
2247  setFlag( res, FLAG_STD );
2248  return FALSE;
2249 }
2250 static BOOLEAN jjGCD_I(leftv res, leftv u, leftv v)
2251 {
2252  int uu=(int)(long)u->Data();int vv=(int)(long)v->Data();
2253  int p0=ABS(uu),p1=ABS(vv);
2254  int r;
2255  while ( p1!=0 )
2256  {
2257  r=p0 % p1;
2258  p0 = p1; p1 = r;
2259  }
2260  res->rtyp=INT_CMD;
2261  res->data=(char *)(long)p0;
2262  return FALSE;
2263 }
2264 static BOOLEAN jjGCD_BI(leftv res, leftv u, leftv v)
2265 {
2266  number n1 = (number) u->Data();
2267  number n2 = (number) v->Data();
2268  res->data = n_Gcd(n1,n2,coeffs_BIGINT);
2269  return FALSE;
2270 }
2271 static BOOLEAN jjGCD_N(leftv res, leftv u, leftv v)
2272 {
2273  number a=(number) u->Data();
2274  number b=(number) v->Data();
2275  if (nIsZero(a))
2276  {
2277  if (nIsZero(b)) res->data=(char *)nInit(1);
2278  else res->data=(char *)nCopy(b);
2279  }
2280  else
2281  {
2282  if (nIsZero(b)) res->data=(char *)nCopy(a);
2283  //else res->data=(char *)n_Gcd(a, b, currRing->cf);
2284  else res->data=(char *)n_SubringGcd(a, b, currRing->cf);
2285  }
2286  return FALSE;
2287 }
2288 static BOOLEAN jjGCD_P(leftv res, leftv u, leftv v)
2289 {
2290  res->data=(void *)singclap_gcd((poly)(u->CopyD(POLY_CMD)),
2291  (poly)(v->CopyD(POLY_CMD)),currRing);
2292  return FALSE;
2293 }
2295 {
2296 #ifdef HAVE_RINGS
2298  {
2299  PrintS("// NOTE: computation of Hilbert series etc. is being\n");
2300  PrintS("// performed for generic fibre, that is, over Q\n");
2301  }
2302 #endif
2303  assumeStdFlag(u);
2304  intvec *module_w=(intvec*)atGet(u,"isHomog",INTVEC_CMD);
2305  intvec *iv=hFirstSeries((ideal)u->Data(),module_w,currRing->qideal);
2306  switch((int)(long)v->Data())
2307  {
2308  case 1:
2309  res->data=(void *)iv;
2310  return FALSE;
2311  case 2:
2312  res->data=(void *)hSecondSeries(iv);
2313  delete iv;
2314  return FALSE;
2315  }
2316  delete iv;
2318  return TRUE;
2319 }
2320 static BOOLEAN jjHOMOG_P(leftv res, leftv u, leftv v)
2321 {
2322  int i=pVar((poly)v->Data());
2323  if (i==0)
2324  {
2325  WerrorS("ringvar expected");
2326  return TRUE;
2327  }
2328  poly p=pOne(); pSetExp(p,i,1); pSetm(p);
2329  int d=pWTotaldegree(p);
2330  pLmDelete(p);
2331  if (d==1)
2332  res->data = (char *)p_Homogen((poly)u->Data(), i, currRing);
2333  else
2334  WerrorS("variable must have weight 1");
2335  return (d!=1);
2336 }
2338 {
2339  int i=pVar((poly)v->Data());
2340  if (i==0)
2341  {
2342  WerrorS("ringvar expected");
2343  return TRUE;
2344  }
2345  pFDegProc deg;
2346  if (currRing->pLexOrder && (currRing->order[0]==ringorder_lp))
2347  deg=p_Totaldegree;
2348  else
2349  deg=currRing->pFDeg;
2350  poly p=pOne(); pSetExp(p,i,1); pSetm(p);
2351  int d=deg(p,currRing);
2352  pLmDelete(p);
2353  if (d==1)
2354  res->data = (char *)id_Homogen((ideal)u->Data(), i, currRing);
2355  else
2356  WerrorS("variable must have weight 1");
2357  return (d!=1);
2358 }
2360 {
2361  intvec *w=new intvec(rVar(currRing));
2362  intvec *vw=(intvec*)u->Data();
2363  ideal v_id=(ideal)v->Data();
2364  pFDegProc save_FDeg=currRing->pFDeg;
2365  pLDegProc save_LDeg=currRing->pLDeg;
2366  BOOLEAN save_pLexOrder=currRing->pLexOrder;
2367  currRing->pLexOrder=FALSE;
2368  kHomW=vw;
2369  kModW=w;
2371  res->data=(void *)(long)idHomModule(v_id,currRing->qideal,&w);
2372  currRing->pLexOrder=save_pLexOrder;
2373  kHomW=NULL;
2374  kModW=NULL;
2375  pRestoreDegProcs(currRing,save_FDeg,save_LDeg);
2376  if (w!=NULL) delete w;
2377  return FALSE;
2378 }
2380 {
2381  assumeStdFlag(u);
2382  res->data=(void *)scIndIndset((ideal)(u->Data()),(int)(long)(v->Data()),
2383  currRing->qideal);
2384  return FALSE;
2385 }
2387 {
2388  res->data=(char *)idSect((ideal)u->Data(),(ideal)v->Data());
2390  return FALSE;
2391 }
2393 {
2394  const lists L = (lists)l->Data();
2395  const int n = L->nr; assume (n >= 0);
2396  std::vector<ideal> V(n + 1);
2397 
2398  for(int i = n; i >= 0; i--) V[i] = (ideal)(L->m[i].Data());
2399 
2400  res->data=interpolation(V, (intvec*)v->Data());
2401  setFlag(res,FLAG_STD);
2402  return errorreported;
2403 }
2405 {
2406  extern BOOLEAN jjStdJanetBasis(leftv res, leftv v,int flag);
2407  return jjStdJanetBasis(res,u,(int)(long)v->Data());
2408 }
2409 
2411 {
2412  extern BOOLEAN jjStdJanetBasis(leftv res, leftv v,int flag);
2413  return jjStdJanetBasis(res,v,0);
2414 }
2415 static BOOLEAN jjJET_P(leftv res, leftv u, leftv v)
2416 {
2417  res->data = (char *)pJet((poly)u->CopyD(), (int)(long)v->Data());
2418  return FALSE;
2419 }
2420 static BOOLEAN jjJET_ID(leftv res, leftv u, leftv v)
2421 {
2422  res->data = (char *)id_Jet((ideal)u->Data(),(int)(long)v->Data(),currRing);
2423  return FALSE;
2424 }
2425 static BOOLEAN jjKBASE2(leftv res, leftv u, leftv v)
2426 {
2427  assumeStdFlag(u);
2428  intvec *w_u=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
2429  res->data = (char *)scKBase((int)(long)v->Data(),
2430  (ideal)(u->Data()),currRing->qideal, w_u);
2431  if (w_u!=NULL)
2432  {
2433  atSet(res,omStrDup("isHomog"),ivCopy(w_u),INTVEC_CMD);
2434  }
2435  return FALSE;
2436 }
2437 static BOOLEAN jjPREIMAGE(leftv res, leftv u, leftv v, leftv w);
2438 static BOOLEAN jjKERNEL(leftv res, leftv u, leftv v)
2439 {
2440  return jjPREIMAGE(res,u,v,NULL);
2441 }
2442 static BOOLEAN jjKoszul(leftv res, leftv u, leftv v)
2443 {
2444  return mpKoszul(res, u,v,NULL);
2445 }
2447 {
2448  sleftv h;
2449  memset(&h,0,sizeof(sleftv));
2450  h.rtyp=INT_CMD;
2451  h.data=(void *)(long)IDELEMS((ideal)v->Data());
2452  return mpKoszul(res, u, &h, v);
2453 }
2454 static BOOLEAN jjLIFT(leftv res, leftv u, leftv v)
2455 {
2456  int ul= IDELEMS((ideal)u->Data());
2457  int vl= IDELEMS((ideal)v->Data());
2458  ideal m = idLift((ideal)u->Data(),(ideal)v->Data(),NULL,FALSE,
2459  hasFlag(u,FLAG_STD));
2460  if (m==NULL) return TRUE;
2461  res->data = (char *)id_Module2formatedMatrix(m,ul,vl,currRing);
2462  return FALSE;
2463 }
2464 static BOOLEAN jjLIFTSTD(leftv res, leftv u, leftv v)
2465 {
2466  if ((v->rtyp!=IDHDL)||(v->e!=NULL)) return TRUE;
2467  idhdl h=(idhdl)v->data;
2468  // CopyD for IDEAL_CMD and MODUL_CMD are identical:
2469  res->data = (char *)idLiftStd((ideal)u->Data(),
2470  &(h->data.umatrix),testHomog);
2471  setFlag(res,FLAG_STD); v->flag=0;
2472  return FALSE;
2473 }
2474 static BOOLEAN jjLOAD2(leftv /*res*/, leftv/* LIB */ , leftv v)
2475 {
2476  return jjLOAD((char*)v->Data(),TRUE);
2477 }
2478 static BOOLEAN jjLOAD_E(leftv /*res*/, leftv v, leftv u)
2479 {
2480  char * s=(char *)u->Data();
2481  if(strcmp(s, "with")==0)
2482  return jjLOAD((char*)v->Data(), TRUE);
2483  if (strcmp(s,"try")==0)
2484  return jjLOAD_TRY((char*)v->Data());
2485  WerrorS("invalid second argument");
2486  WerrorS("load(\"libname\" [,option]);");
2487  return TRUE;
2488 }
2489 static BOOLEAN jjMODULO(leftv res, leftv u, leftv v)
2490 {
2491  intvec *w_u=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
2492  tHomog hom=testHomog;
2493  if (w_u!=NULL)
2494  {
2495  w_u=ivCopy(w_u);
2496  hom=isHomog;
2497  }
2498  intvec *w_v=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
2499  if (w_v!=NULL)
2500  {
2501  w_v=ivCopy(w_v);
2502  hom=isHomog;
2503  }
2504  if ((w_u!=NULL) && (w_v==NULL))
2505  w_v=ivCopy(w_u);
2506  if ((w_v!=NULL) && (w_u==NULL))
2507  w_u=ivCopy(w_v);
2508  ideal u_id=(ideal)u->Data();
2509  ideal v_id=(ideal)v->Data();
2510  if (w_u!=NULL)
2511  {
2512  if ((*w_u).compare((w_v))!=0)
2513  {
2514  WarnS("incompatible weights");
2515  delete w_u; w_u=NULL;
2516  hom=testHomog;
2517  }
2518  else
2519  {
2520  if ((!idTestHomModule(u_id,currRing->qideal,w_v))
2521  || (!idTestHomModule(v_id,currRing->qideal,w_v)))
2522  {
2523  WarnS("wrong weights");
2524  delete w_u; w_u=NULL;
2525  hom=testHomog;
2526  }
2527  }
2528  }
2529  res->data = (char *)idModulo(u_id,v_id ,hom,&w_u);
2530  if (w_u!=NULL)
2531  {
2532  atSet(res,omStrDup("isHomog"),w_u,INTVEC_CMD);
2533  }
2534  delete w_v;
2535  //if (TEST_OPT_RETURN_SB) setFlag(res,FLAG_STD);
2536  return FALSE;
2537 }
2538 static BOOLEAN jjMOD_BI(leftv res, leftv u, leftv v)
2539 {
2540  number q=(number)v->Data();
2541  if (n_IsZero(q,coeffs_BIGINT))
2542  {
2544  return TRUE;
2545  }
2546  res->data =(char *) n_IntMod((number)u->Data(),q,coeffs_BIGINT);
2547  return FALSE;
2548 }
2549 static BOOLEAN jjMOD_N(leftv res, leftv u, leftv v)
2550 {
2551  number q=(number)v->Data();
2552  if (nIsZero(q))
2553  {
2555  return TRUE;
2556  }
2557  res->data =(char *) n_IntMod((number)u->Data(),q,currRing->cf);
2558  return FALSE;
2559 }
2560 static BOOLEAN jjMONITOR2(leftv res, leftv u,leftv v);
2562 {
2563  return jjMONITOR2(res,v,NULL);
2564 }
2566 {
2567 #if 0
2568  char *opt=(char *)v->Data();
2569  int mode=0;
2570  while(*opt!='\0')
2571  {
2572  if (*opt=='i') mode |= SI_PROT_I;
2573  else if (*opt=='o') mode |= SI_PROT_O;
2574  opt++;
2575  }
2576  monitor((char *)(u->Data()),mode);
2577 #else
2578  si_link l=(si_link)u->Data();
2579  if (slOpen(l,SI_LINK_WRITE,u)) return TRUE;
2580  if(strcmp(l->m->type,"ASCII")!=0)
2581  {
2582  Werror("ASCII link required, not `%s`",l->m->type);
2583  slClose(l);
2584  return TRUE;
2585  }
2586  SI_LINK_SET_CLOSE_P(l); // febase handles the FILE*
2587  if ( l->name[0]!='\0') // "" is the stop condition
2588  {
2589  const char *opt;
2590  int mode=0;
2591  if (v==NULL) opt=(const char*)"i";
2592  else opt=(const char *)v->Data();
2593  while(*opt!='\0')
2594  {
2595  if (*opt=='i') mode |= SI_PROT_I;
2596  else if (*opt=='o') mode |= SI_PROT_O;
2597  opt++;
2598  }
2599  monitor((FILE *)l->data,mode);
2600  }
2601  else
2602  monitor(NULL,0);
2603  return FALSE;
2604 #endif
2605 }
2606 static BOOLEAN jjMONOM(leftv res, leftv v)
2607 {
2608  intvec *iv=(intvec *)v->Data();
2609  poly p=pOne();
2610  int e;
2611  BOOLEAN err=FALSE;
2612  for(unsigned i=si_min(currRing->N,iv->length()); i>0; i--)
2613  {
2614  e=(*iv)[i-1];
2615  if (e>=0) pSetExp(p,i,e);
2616  else err=TRUE;
2617  }
2618  if (iv->length()==(currRing->N+1))
2619  {
2620  res->rtyp=VECTOR_CMD;
2621  e=(*iv)[currRing->N];
2622  if (e>=0) pSetComp(p,e);
2623  else err=TRUE;
2624  }
2625  pSetm(p);
2626  res->data=(char*)p;
2627  if(err) { pDelete(&p); WerrorS("no negative exponent allowed"); }
2628  return err;
2629 }
2631 {
2632  // u: the name of the new type
2633  // v: the elements
2634  newstruct_desc d=newstructFromString((const char *)v->Data());
2635  if (d!=NULL) newstruct_setup((const char *)u->Data(),d);
2636  return d==NULL;
2637 }
2638 static BOOLEAN jjPARSTR2(leftv res, leftv u, leftv v)
2639 {
2640  idhdl h=(idhdl)u->data;
2641  int i=(int)(long)v->Data();
2642  int p=0;
2643  if ((0<i)
2644  && (rParameter(IDRING(h))!=NULL)
2645  && (i<=(p=rPar(IDRING(h)))))
2646  res->data=omStrDup(rParameter(IDRING(h))[i-1]);
2647  else
2648  {
2649  Werror("par number %d out of range 1..%d",i,p);
2650  return TRUE;
2651  }
2652  return FALSE;
2653 }
2654 #ifdef HAVE_PLURAL
2656 {
2657  if( currRing->qideal != NULL )
2658  {
2659  WerrorS("basering must NOT be a qring!");
2660  return TRUE;
2661  }
2662 
2663  if (iiOp==NCALGEBRA_CMD)
2664  {
2665  return nc_CallPlural(NULL,NULL,(poly)a->Data(),(poly)b->Data(),currRing,false,true,false,currRing);
2666  }
2667  else
2668  {
2669  ring r=rCopy(currRing);
2670  BOOLEAN result=nc_CallPlural(NULL,NULL,(poly)a->Data(),(poly)b->Data(),r,false,true,false,currRing);
2671  res->data=r;
2672  return result;
2673  }
2674 }
2676 {
2677  if( currRing->qideal != NULL )
2678  {
2679  WerrorS("basering must NOT be a qring!");
2680  return TRUE;
2681  }
2682 
2683  if (iiOp==NCALGEBRA_CMD)
2684  {
2685  return nc_CallPlural(NULL,(matrix)b->Data(),(poly)a->Data(),NULL,currRing,false,true,false,currRing);
2686  }
2687  else
2688  {
2689  ring r=rCopy(currRing);
2690  BOOLEAN result=nc_CallPlural(NULL,(matrix)b->Data(),(poly)a->Data(),NULL,r,false,true,false,currRing);
2691  res->data=r;
2692  return result;
2693  }
2694 }
2696 {
2697  if( currRing->qideal != NULL )
2698  {
2699  WerrorS("basering must NOT be a qring!");
2700  return TRUE;
2701  }
2702 
2703  if (iiOp==NCALGEBRA_CMD)
2704  {
2705  return nc_CallPlural((matrix)a->Data(),NULL,NULL,(poly)b->Data(),currRing,false,true,false,currRing);
2706  }
2707  else
2708  {
2709  ring r=rCopy(currRing);
2710  BOOLEAN result=nc_CallPlural((matrix)a->Data(),NULL,NULL,(poly)b->Data(),r,false,true,false,currRing);
2711  res->data=r;
2712  return result;
2713  }
2714 }
2716 {
2717  if( currRing->qideal != NULL )
2718  {
2719  WerrorS("basering must NOT be a qring!");
2720  return TRUE;
2721  }
2722 
2723  if (iiOp==NCALGEBRA_CMD)
2724  {
2725  return nc_CallPlural((matrix)a->Data(),(matrix)b->Data(),NULL,NULL,currRing,false,true,false,currRing);
2726  }
2727  else
2728  {
2729  ring r=rCopy(currRing);
2730  BOOLEAN result=nc_CallPlural((matrix)a->Data(),(matrix)b->Data(),NULL,NULL,r,false,true,false,currRing);
2731  res->data=r;
2732  return result;
2733  }
2734 }
2736 {
2737  res->data=NULL;
2738 
2739  if (rIsPluralRing(currRing))
2740  {
2741  const poly q = (poly)b->Data();
2742 
2743  if( q != NULL )
2744  {
2745  if( (poly)a->Data() != NULL )
2746  {
2747  poly p = (poly)a->CopyD(POLY_CMD); // p = copy!
2748  res->data = nc_p_Bracket_qq(p,q, currRing); // p will be destroyed!
2749  }
2750  }
2751  }
2752  return FALSE;
2753 }
2755 {
2756  /* number, poly, vector, ideal, module, matrix */
2757  ring r = (ring)a->Data();
2758  if (r == currRing)
2759  {
2760  res->data = b->Data();
2761  res->rtyp = b->rtyp;
2762  return FALSE;
2763  }
2764  if (!rIsLikeOpposite(currRing, r))
2765  {
2766  Werror("%s is not an opposite ring to current ring",a->Fullname());
2767  return TRUE;
2768  }
2769  idhdl w;
2770  if( ((w=r->idroot->get(b->Name(),myynest))!=NULL) && (b->e==NULL))
2771  {
2772  int argtype = IDTYP(w);
2773  switch (argtype)
2774  {
2775  case NUMBER_CMD:
2776  {
2777  /* since basefields are equal, we can apply nCopy */
2778  res->data = nCopy((number)IDDATA(w));
2779  res->rtyp = argtype;
2780  break;
2781  }
2782  case POLY_CMD:
2783  case VECTOR_CMD:
2784  {
2785  poly q = (poly)IDDATA(w);
2786  res->data = pOppose(r,q,currRing);
2787  res->rtyp = argtype;
2788  break;
2789  }
2790  case IDEAL_CMD:
2791  case MODUL_CMD:
2792  {
2793  ideal Q = (ideal)IDDATA(w);
2794  res->data = idOppose(r,Q,currRing);
2795  res->rtyp = argtype;
2796  break;
2797  }
2798  case MATRIX_CMD:
2799  {
2800  ring save = currRing;
2801  rChangeCurrRing(r);
2802  matrix m = (matrix)IDDATA(w);
2804  rChangeCurrRing(save);
2805  ideal S = idOppose(r,Q,currRing);
2806  id_Delete(&Q, r);
2807  res->data = id_Module2Matrix(S,currRing);
2808  res->rtyp = argtype;
2809  break;
2810  }
2811  default:
2812  {
2813  WerrorS("unsupported type in oppose");
2814  return TRUE;
2815  }
2816  }
2817  }
2818  else
2819  {
2820  Werror("identifier %s not found in %s",b->Fullname(),a->Fullname());
2821  return TRUE;
2822  }
2823  return FALSE;
2824 }
2825 #endif /* HAVE_PLURAL */
2826 
2827 static BOOLEAN jjQUOT(leftv res, leftv u, leftv v)
2828 {
2829  res->data = (char *)idQuot((ideal)u->Data(),(ideal)v->Data(),
2830  hasFlag(u,FLAG_STD),u->Typ()==v->Typ());
2831  id_DelMultiples((ideal)(res->data),currRing);
2833  return FALSE;
2834 }
2835 static BOOLEAN jjRANDOM(leftv res, leftv u, leftv v)
2836 {
2837  int i=(int)(long)u->Data();
2838  int j=(int)(long)v->Data();
2839  if (j-i <0) {WerrorS("invalid range for random"); return TRUE;}
2840  res->data =(char *)(long)((i > j) ? i : (siRand() % (j-i+1)) + i);
2841  return FALSE;
2842 }
2843 static BOOLEAN jjRANK2(leftv res, leftv u, leftv v)
2844 {
2845  matrix m =(matrix)u->Data();
2846  int isRowEchelon = (int)(long)v->Data();
2847  if (isRowEchelon != 1) isRowEchelon = 0;
2848  int rank = luRank(m, isRowEchelon);
2849  res->data =(char *)(long)rank;
2850  return FALSE;
2851 }
2852 static BOOLEAN jjREAD2(leftv res, leftv u, leftv v)
2853 {
2854  si_link l=(si_link)u->Data();
2855  leftv r=slRead(l,v);
2856  if (r==NULL)
2857  {
2858  const char *s;
2859  if ((l!=NULL)&&(l->name!=NULL)) s=l->name;
2860  else s=sNoName_fe;
2861  Werror("cannot read from `%s`",s);
2862  return TRUE;
2863  }
2864  memcpy(res,r,sizeof(sleftv));
2866  return FALSE;
2867 }
2869 {
2870  ideal vi=(ideal)v->Data();
2871  if (currRing->qideal!=NULL || vi->ncols>1 || rIsPluralRing(currRing))
2872  assumeStdFlag(v);
2873  res->data = (char *)kNF(vi,currRing->qideal,(poly)u->Data());
2874  return FALSE;
2875 }
2877 {
2878  ideal ui=(ideal)u->Data();
2879  ideal vi=(ideal)v->Data();
2880  if (currRing->qideal!=NULL || vi->ncols>1 || rIsPluralRing(currRing))
2881  assumeStdFlag(v);
2882  res->data = (char *)kNF(vi,currRing->qideal,ui);
2883  return FALSE;
2884 }
2885 #if 0
2886 static BOOLEAN jjRES(leftv res, leftv u, leftv v)
2887 {
2888  int maxl=(int)(long)v->Data();
2889  if (maxl<0)
2890  {
2891  WerrorS("length for res must not be negative");
2892  return TRUE;
2893  }
2894  int l=0;
2895  //resolvente r;
2896  syStrategy r;
2897  intvec *weights=NULL;
2898  int wmaxl=maxl;
2899  ideal u_id=(ideal)u->Data();
2900 
2901  maxl--;
2902  if (/*(*/ maxl==-1 /*)*/) /*&& (iiOp!=MRES_CMD)*/
2903  {
2904  maxl = currRing->N-1+2*(iiOp==MRES_CMD);
2905  if (currRing->qideal!=NULL)
2906  {
2907  Warn(
2908  "full resolution in a qring may be infinite, setting max length to %d",
2909  maxl+1);
2910  }
2911  }
2912  weights=(intvec*)atGet(u,"isHomog",INTVEC_CMD);
2913  if (weights!=NULL)
2914  {
2915  if (!idTestHomModule(u_id,currRing->qideal,weights))
2916  {
2917  WarnS("wrong weights given:");weights->show();PrintLn();
2918  weights=NULL;
2919  }
2920  }
2921  intvec *ww=NULL;
2922  int add_row_shift=0;
2923  if (weights!=NULL)
2924  {
2925  ww=ivCopy(weights);
2926  add_row_shift = ww->min_in();
2927  (*ww) -= add_row_shift;
2928  }
2929  else
2930  idHomModule(u_id,currRing->qideal,&ww);
2931  weights=ww;
2932 
2933  if ((iiOp == RES_CMD) || (iiOp == MRES_CMD))
2934  {
2935  r=syResolution(u_id,maxl, ww, iiOp==MRES_CMD);
2936  }
2937  else if (iiOp==SRES_CMD)
2938  // r=sySchreyerResolvente(u_id,maxl+1,&l);
2939  r=sySchreyer(u_id,maxl+1);
2940  else if (iiOp == LRES_CMD)
2941  {
2942  int dummy;
2943  if((currRing->qideal!=NULL)||
2944  (!idHomIdeal (u_id,NULL)))
2945  {
2946  WerrorS
2947  ("`lres` not implemented for inhomogeneous input or qring");
2948  return TRUE;
2949  }
2950  r=syLaScala3(u_id,&dummy);
2951  }
2952  else if (iiOp == KRES_CMD)
2953  {
2954  int dummy;
2955  if((currRing->qideal!=NULL)||
2956  (!idHomIdeal (u_id,NULL)))
2957  {
2958  WerrorS
2959  ("`kres` not implemented for inhomogeneous input or qring");
2960  return TRUE;
2961  }
2962  r=syKosz(u_id,&dummy);
2963  }
2964  else
2965  {
2966  int dummy;
2967  if((currRing->qideal!=NULL)||
2968  (!idHomIdeal (u_id,NULL)))
2969  {
2970  WerrorS
2971  ("`hres` not implemented for inhomogeneous input or qring");
2972  return TRUE;
2973  }
2974  r=syHilb(u_id,&dummy);
2975  }
2976  if (r==NULL) return TRUE;
2977  //res->data=(void *)liMakeResolv(r,l,wmaxl,u->Typ(),weights);
2978  r->list_length=wmaxl;
2979  res->data=(void *)r;
2980  if ((r->weights!=NULL) && (r->weights[0]!=NULL))
2981  {
2982  intvec *w=ivCopy(r->weights[0]);
2983  if (weights!=NULL) (*w) += add_row_shift;
2984  atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
2985  w=NULL;
2986  }
2987  else
2988  {
2989 //#if 0
2990 // need to set weights for ALL components (sres)
2991  if (weights!=NULL)
2992  {
2993  atSet(res,omStrDup("isHomog"),ivCopy(weights),INTVEC_CMD);
2995  (r->weights)[0] = ivCopy(weights);
2996  }
2997 //#endif
2998  }
2999  if (ww!=NULL) { delete ww; ww=NULL; }
3000  return FALSE;
3001 }
3002 #else
3003 static BOOLEAN jjRES(leftv res, leftv u, leftv v)
3004 {
3005  int maxl=(int)(long)v->Data();
3006  if (maxl<0)
3007  {
3008  WerrorS("length for res must not be negative");
3009  return TRUE;
3010  }
3011  syStrategy r;
3012  intvec *weights=NULL;
3013  int wmaxl=maxl;
3014  ideal u_id=(ideal)u->Data();
3015 
3016  maxl--;
3017  if (/*(*/ maxl==-1 /*)*/) /*&& (iiOp!=MRES_CMD)*/
3018  {
3019  maxl = currRing->N-1+2*(iiOp==MRES_CMD);
3020  if (currRing->qideal!=NULL)
3021  {
3022  Warn(
3023  "full resolution in a qring may be infinite, setting max length to %d",
3024  maxl+1);
3025  }
3026  }
3027  weights=(intvec*)atGet(u,"isHomog",INTVEC_CMD);
3028  if (weights!=NULL)
3029  {
3030  if (!idTestHomModule(u_id,currRing->qideal,weights))
3031  {
3032  WarnS("wrong weights given:");weights->show();PrintLn();
3033  weights=NULL;
3034  }
3035  }
3036  intvec *ww=NULL;
3037  int add_row_shift=0;
3038  if (weights!=NULL)
3039  {
3040  ww=ivCopy(weights);
3041  add_row_shift = ww->min_in();
3042  (*ww) -= add_row_shift;
3043  }
3044  if ((iiOp == RES_CMD) || (iiOp == MRES_CMD))
3045  {
3046  r=syResolution(u_id,maxl, ww, iiOp==MRES_CMD);
3047  }
3048  else if (iiOp==SRES_CMD)
3049  // r=sySchreyerResolvente(u_id,maxl+1,&l);
3050  r=sySchreyer(u_id,maxl+1);
3051  else if (iiOp == LRES_CMD)
3052  {
3053  int dummy;
3054  if((currRing->qideal!=NULL)||
3055  (!idHomIdeal (u_id,NULL)))
3056  {
3057  WerrorS
3058  ("`lres` not implemented for inhomogeneous input or qring");
3059  return TRUE;
3060  }
3061  if(currRing->N == 1)
3062  WarnS("the current implementation of `lres` may not work in the case of a single variable");
3063  r=syLaScala3(u_id,&dummy);
3064  }
3065  else if (iiOp == KRES_CMD)
3066  {
3067  int dummy;
3068  if((currRing->qideal!=NULL)||
3069  (!idHomIdeal (u_id,NULL)))
3070  {
3071  WerrorS
3072  ("`kres` not implemented for inhomogeneous input or qring");
3073  return TRUE;
3074  }
3075  r=syKosz(u_id,&dummy);
3076  }
3077  else
3078  {
3079  int dummy;
3080  if((currRing->qideal!=NULL)||
3081  (!idHomIdeal (u_id,NULL)))
3082  {
3083  WerrorS
3084  ("`hres` not implemented for inhomogeneous input or qring");
3085  return TRUE;
3086  }
3087  ideal u_id_copy=idCopy(u_id);
3088  idSkipZeroes(u_id_copy);
3089  r=syHilb(u_id_copy,&dummy);
3090  idDelete(&u_id_copy);
3091  }
3092  if (r==NULL) return TRUE;
3093  //res->data=(void *)liMakeResolv(r,l,wmaxl,u->Typ(),weights);
3094  r->list_length=wmaxl;
3095  res->data=(void *)r;
3096  if ((weights!=NULL) && (ww!=NULL)) { delete ww; ww=NULL; }
3097  if ((r->weights!=NULL) && (r->weights[0]!=NULL))
3098  {
3099  ww=ivCopy(r->weights[0]);
3100  if (weights!=NULL) (*ww) += add_row_shift;
3101  atSet(res,omStrDup("isHomog"),ww,INTVEC_CMD);
3102  }
3103  else
3104  {
3105  if (weights!=NULL)
3106  {
3107  atSet(res,omStrDup("isHomog"),ivCopy(weights),INTVEC_CMD);
3108  }
3109  }
3110 
3111  // test the La Scala case' output
3112  assume( ((iiOp == LRES_CMD) || (iiOp == HRES_CMD)) == (r->syRing != NULL) );
3113  assume( (r->syRing != NULL) == (r->resPairs != NULL) );
3114 
3115  if(iiOp != HRES_CMD)
3116  assume( (r->minres != NULL) || (r->fullres != NULL) ); // is wrong for HRES_CMD...
3117  else
3118  assume( (r->orderedRes != NULL) || (r->res != NULL) ); // analog for hres...
3119 
3120  return FALSE;
3121 }
3122 #endif
3123 static BOOLEAN jjPFAC2(leftv res, leftv u, leftv v)
3124 {
3125  number n1; int i;
3126 
3127  if ((u->Typ() == BIGINT_CMD) ||
3128  ((u->Typ() == NUMBER_CMD) && rField_is_Q(currRing)))
3129  {
3130  n1 = (number)u->CopyD();
3131  }
3132  else if (u->Typ() == INT_CMD)
3133  {
3134  i = (int)(long)u->Data();
3135  n1 = n_Init(i, coeffs_BIGINT);
3136  }
3137  else
3138  {
3139  return TRUE;
3140  }
3141 
3142  i = (int)(long)v->Data();
3143 
3144  lists l = primeFactorisation(n1, i);
3145  n_Delete(&n1, coeffs_BIGINT);
3146  res->data = (char*)l;
3147  return FALSE;
3148 }
3149 static BOOLEAN jjRSUM(leftv res, leftv u, leftv v)
3150 {
3151  ring r;
3152  int i=rSum((ring)u->Data(),(ring)v->Data(),r);
3153  res->data = (char *)r;
3154  return (i==-1);
3155 }
3156 #define SIMPL_LMDIV 32
3157 #define SIMPL_LMEQ 16
3158 #define SIMPL_MULT 8
3159 #define SIMPL_EQU 4
3160 #define SIMPL_NULL 2
3161 #define SIMPL_NORM 1
3163 {
3164  int sw = (int)(long)v->Data();
3165  // CopyD for IDEAL_CMD and MODUL_CMD are identical:
3166  ideal id = (ideal)u->CopyD(IDEAL_CMD);
3167  if (sw & SIMPL_LMDIV)
3168  {
3169  id_DelDiv(id,currRing);
3170  }
3171  if (sw & SIMPL_LMEQ)
3172  {
3174  }
3175  if (sw & SIMPL_MULT)
3176  {
3178  }
3179  else if(sw & SIMPL_EQU)
3180  {
3181  id_DelEquals(id,currRing);
3182  }
3183  if (sw & SIMPL_NULL)
3184  {
3185  idSkipZeroes(id);
3186  }
3187  if (sw & SIMPL_NORM)
3188  {
3189  id_Norm(id,currRing);
3190  }
3191  res->data = (char * )id;
3192  return FALSE;
3193 }
3195 static BOOLEAN jjSQR_FREE2(leftv res, leftv u, leftv dummy)
3196 {
3197  intvec *v=NULL;
3198  int sw=(int)(long)dummy->Data();
3199  int fac_sw=sw;
3200  if (sw<0) fac_sw=1;
3201  singclap_factorize_retry=0;
3202  ideal f=singclap_sqrfree((poly)(u->CopyD()), &v, fac_sw, currRing);
3203  if (f==NULL)
3204  return TRUE;
3205  switch(sw)
3206  {
3207  case 0:
3208  case 2:
3209  {
3211  l->Init(2);
3212  l->m[0].rtyp=IDEAL_CMD;
3213  l->m[0].data=(void *)f;
3214  l->m[1].rtyp=INTVEC_CMD;
3215  l->m[1].data=(void *)v;
3216  res->data=(void *)l;
3217  res->rtyp=LIST_CMD;
3218  return FALSE;
3219  }
3220  case 1:
3221  res->data=(void *)f;
3222  return FALSE;
3223  case 3:
3224  {
3225  poly p=f->m[0];
3226  int i=IDELEMS(f);
3227  f->m[0]=NULL;
3228  while(i>1)
3229  {
3230  i--;
3231  p=pMult(p,f->m[i]);
3232  f->m[i]=NULL;
3233  }
3234  res->data=(void *)p;
3235  res->rtyp=POLY_CMD;
3236  }
3237  return FALSE;
3238  }
3239  WerrorS("invalid switch");
3240  return FALSE;
3241 }
3242 static BOOLEAN jjSTATUS2(leftv res, leftv u, leftv v)
3243 {
3244  res->data = omStrDup(slStatus((si_link) u->Data(), (char *) v->Data()));
3245  return FALSE;
3246 }
3248 {
3249  res->data = (void *)(long)slStatusSsiL((lists) u->Data(), (int)(long) v->Data());
3250  //return (res->data== (void*)(long)-2);
3251  return FALSE;
3252 }
3253 static BOOLEAN jjSIMPL_P(leftv res, leftv u, leftv v)
3254 {
3255  int sw = (int)(long)v->Data();
3256  // CopyD for POLY_CMD and VECTOR_CMD are identical:
3257  poly p = (poly)u->CopyD(POLY_CMD);
3258  if (sw & SIMPL_NORM)
3259  {
3260  pNorm(p);
3261  }
3262  res->data = (char * )p;
3263  return FALSE;
3264 }
3266 {
3267  ideal result;
3268  intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
3269  tHomog hom=testHomog;
3270  ideal u_id=(ideal)(u->Data());
3271  if (w!=NULL)
3272  {
3273  if (!idTestHomModule(u_id,currRing->qideal,w))
3274  {
3275  WarnS("wrong weights:");w->show();PrintLn();
3276  w=NULL;
3277  }
3278  else
3279  {
3280  w=ivCopy(w);
3281  hom=isHomog;
3282  }
3283  }
3284  result=kStd(u_id,currRing->qideal,hom,&w,(intvec *)v->Data());
3285  idSkipZeroes(result);
3286  res->data = (char *)result;
3287  setFlag(res,FLAG_STD);
3288  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
3289  return FALSE;
3290 }
3291 static BOOLEAN jjSTD_1(leftv res, leftv u, leftv v)
3292 {
3293  ideal result;
3294  assumeStdFlag(u);
3295  ideal i1=(ideal)(u->Data());
3296  ideal i0;
3297  int r=v->Typ();
3298  if ((/*v->Typ()*/r==POLY_CMD) ||(r==VECTOR_CMD))
3299  {
3300  i0=idInit(1,i1->rank); // TODO: rank is wrong (if v is a vector!)
3301  i0->m[0]=(poly)v->Data();
3302  int ii0=idElem(i0); /* size of i0 */
3303  i1=idSimpleAdd(i1,i0); //
3304  memset(i0->m,0,sizeof(poly)*IDELEMS(i0));
3305  idDelete(&i0);
3306  intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
3307  tHomog hom=testHomog;
3308 
3309  if (w!=NULL)
3310  {
3311  if (!idTestHomModule(i1,currRing->qideal,w))
3312  {
3313  // no warnung: this is legal, if i in std(i,p)
3314  // is homogeneous, but p not
3315  w=NULL;
3316  }
3317  else
3318  {
3319  w=ivCopy(w);
3320  hom=isHomog;
3321  }
3322  }
3323  BITSET save1;
3324  SI_SAVE_OPT1(save1);
3326  /* ii0 appears to be the position of the first element of il that
3327  does not belong to the old SB ideal */
3328  result=kStd(i1,currRing->qideal,hom,&w,NULL,0,ii0);
3329  SI_RESTORE_OPT1(save1);
3330  idDelete(&i1);
3331  idSkipZeroes(result);
3332  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
3333  res->data = (char *)result;
3334  }
3335  else /*IDEAL/MODULE*/
3336  {
3337  i0=(ideal)v->CopyD();
3338  int ii0=idElem(i0); /* size of i0 */
3339  i1=idSimpleAdd(i1,i0); //
3340  memset(i0->m,0,sizeof(poly)*IDELEMS(i0));
3341  idDelete(&i0);
3342  intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
3343  tHomog hom=testHomog;
3344 
3345  if (w!=NULL)
3346  {
3347  if (!idTestHomModule(i1,currRing->qideal,w))
3348  {
3349  // no warnung: this is legal, if i in std(i,p)
3350  // is homogeneous, but p not
3351  w=NULL;
3352  }
3353  else
3354  {
3355  w=ivCopy(w);
3356  hom=isHomog;
3357  }
3358  }
3359  if (ii0*4 >= 3*IDELEMS(i1)) // MAGIC: add few poly to large SB: 3/4
3360  {
3361  BITSET save1;
3362  SI_SAVE_OPT1(save1);
3364  /* ii0 appears to be the position of the first element of il that
3365  does not belong to the old SB ideal */
3366  result=kStd(i1,currRing->qideal,hom,&w,NULL,0,ii0);
3367  SI_RESTORE_OPT1(save1);
3368  }
3369  else
3370  {
3371  result=kStd(i1,currRing->qideal,hom,&w);
3372  }
3373  idDelete(&i1);
3374  idSkipZeroes(result);
3375  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
3376  res->data = (char *)result;
3377  }
3379  return FALSE;
3380 }
3381 static BOOLEAN jjSYZ_2(leftv res, leftv u, leftv v)
3382 {
3383  // see jjSYZYGY
3384  intvec *w=NULL;
3385  ideal I=(ideal)u->Data();
3386  GbVariant alg=syGetAlgorithm((char*)v->Data(),currRing,I);
3387  res->data = (char *)idSyzygies(I,testHomog,&w,TRUE,FALSE,NULL,alg);
3388  if (w!=NULL) delete w;
3390  return FALSE;
3391 
3392 }
3393 static BOOLEAN jjVARSTR2(leftv res, leftv u, leftv v)
3394 {
3395  idhdl h=(idhdl)u->data;
3396  int i=(int)(long)v->Data();
3397  if ((0<i) && (i<=IDRING(h)->N))
3398  res->data=omStrDup(IDRING(h)->names[i-1]);
3399  else
3400  {
3401  Werror("var number %d out of range 1..%d",i,IDRING(h)->N);
3402  return TRUE;
3403  }
3404  return FALSE;
3405 }
3407 {
3408 // input: u: a list with links of type
3409 // ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch
3410 // v: timeout for select in milliseconds
3411 // or 0 for polling
3412 // returns: ERROR (via Werror): timeout negative
3413 // -1: the read state of all links is eof
3414 // 0: timeout (or polling): none ready
3415 // i>0: (at least) L[i] is ready
3416  lists Lforks = (lists)u->Data();
3417  int t = (int)(long)v->Data();
3418  if(t < 0)
3419  {
3420  WerrorS("negative timeout"); return TRUE;
3421  }
3422  int i = slStatusSsiL(Lforks, t*1000);
3423  if(i == -2) /* error */
3424  {
3425  return TRUE;
3426  }
3427  res->data = (void*)(long)i;
3428  return FALSE;
3429 }
3431 {
3432 // input: u: a list with links of type
3433 // ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch
3434 // v: timeout for select in milliseconds
3435 // or 0 for polling
3436 // returns: ERROR (via Werror): timeout negative
3437 // -1: the read state of all links is eof
3438 // 0: timeout (or polling): none ready
3439 // 1: all links are ready
3440 // (caution: at least one is ready, but some maybe dead)
3441  lists Lforks = (lists)u->CopyD();
3442  int timeout = 1000*(int)(long)v->Data();
3443  if(timeout < 0)
3444  {
3445  WerrorS("negative timeout"); return TRUE;
3446  }
3447  int t = getRTimer()/TIMER_RESOLUTION; // in seconds
3448  int i;
3449  int ret = -1;
3450  for(unsigned nfinished = 0; nfinished < ((unsigned)Lforks->nr)+1; nfinished++)
3451  {
3452  i = slStatusSsiL(Lforks, timeout);
3453  if(i > 0) /* Lforks[i] is ready */
3454  {
3455  ret = 1;
3456  Lforks->m[i-1].CleanUp();
3457  Lforks->m[i-1].rtyp=DEF_CMD;
3458  Lforks->m[i-1].data=NULL;
3459  timeout = si_max(0,timeout - 1000*(getRTimer()/TIMER_RESOLUTION - t));
3460  }
3461  else /* terminate the for loop */
3462  {
3463  if(i == -2) /* error */
3464  {
3465  return TRUE;
3466  }
3467  if(i == 0) /* timeout */
3468  {
3469  ret = 0;
3470  }
3471  break;
3472  }
3473  }
3474  Lforks->Clean();
3475  res->data = (void*)(long)ret;
3476  return FALSE;
3477 }
3478 static BOOLEAN jjWEDGE(leftv res, leftv u, leftv v)
3479 {
3480  res->data = (char *)mp_Wedge((matrix)u->Data(),(int)(long)v->Data(),currRing);
3481  return FALSE;
3482 }
3483 #define jjWRONG2 (proc2)jjWRONG
3484 #define jjWRONG3 (proc3)jjWRONG
3486 {
3487  return TRUE;
3488 }
3489 
3490 /*=================== operations with 1 arg.: static proc =================*/
3491 /* must be ordered: first operations for chars (infix ops),
3492  * then alphabetically */
3493 
3494 static BOOLEAN jjDUMMY(leftv res, leftv u)
3495 {
3496  res->data = (char *)u->CopyD();
3497  return FALSE;
3498 }
3500 {
3501  return FALSE;
3502 }
3503 //static BOOLEAN jjPLUSPLUS(leftv res, leftv u)
3504 //{
3505 // res->data = (char *)((int)(long)u->Data()+1);
3506 // return FALSE;
3507 //}
3508 //static BOOLEAN jjMINUSMINUS(leftv res, leftv u)
3509 //{
3510 // res->data = (char *)((int)(long)u->Data()-1);
3511 // return FALSE;
3512 //}
3514 {
3515  if (IDTYP((idhdl)u->data)==INT_CMD)
3516  {
3517  int i=IDINT((idhdl)u->data);
3518  if (iiOp==PLUSPLUS) i++;
3519  else i--;
3520  IDDATA((idhdl)u->data)=(char *)(long)i;
3521  return FALSE;
3522  }
3523  return TRUE;
3524 }
3526 {
3527  number n=(number)u->CopyD(BIGINT_CMD);
3528  n=n_InpNeg(n,coeffs_BIGINT);
3529  res->data = (char *)n;
3530  return FALSE;
3531 }
3533 {
3534  res->data = (char *)(-(long)u->Data());
3535  return FALSE;
3536 }
3538 {
3539  number n=(number)u->CopyD(NUMBER_CMD);
3540  n=nInpNeg(n);
3541  res->data = (char *)n;
3542  return FALSE;
3543 }
3545 {
3546  res->data = (char *)pNeg((poly)u->CopyD(POLY_CMD));
3547  return FALSE;
3548 }
3550 {
3551  poly m1=pISet(-1);
3552  res->data = (char *)mp_MultP((matrix)u->CopyD(MATRIX_CMD),m1,currRing);
3553  return FALSE;
3554 }
3556 {
3557  intvec *iv=(intvec *)u->CopyD(INTVEC_CMD);
3558  (*iv)*=(-1);
3559  res->data = (char *)iv;
3560  return FALSE;
3561 }
3563 {
3564  bigintmat *bim=(bigintmat *)u->CopyD(BIGINTMAT_CMD);
3565  (*bim)*=(-1);
3566  res->data = (char *)bim;
3567  return FALSE;
3568 }
3569 // dummy for python_module.so and similiar
3571 {
3572  if (u->rtyp==IDHDL) rSetHdl((idhdl)u->data);
3573  else
3574  {
3575  ring r=(ring)u->Data();
3576  idhdl h=rFindHdl(r,NULL);
3577  if (h==NULL)
3578  {
3579  char name_buffer[100];
3580  static int ending=1000000;
3581  ending++;
3582  sprintf(name_buffer, "PYTHON_RING_VAR%d",ending);
3583  h=enterid(omStrDup(name_buffer),0,RING_CMD,&IDROOT);
3584  IDRING(h)=r;
3585  r->ref++;
3586  }
3587  rSetHdl(h);
3588  }
3589  return FALSE;
3590 }
3591 static BOOLEAN jjPROC1(leftv res, leftv u)
3592 {
3593  return jjPROC(res,u,NULL);
3594 }
3596 {
3597  //matrix m=(matrix)v->Data();
3598  //lists l=mpBareiss(m,FALSE);
3599  intvec *iv;
3600  ideal m;
3601  sm_CallBareiss((ideal)v->Data(),0,0,m,&iv, currRing);
3603  l->Init(2);
3604  l->m[0].rtyp=MODUL_CMD;
3605  l->m[1].rtyp=INTVEC_CMD;
3606  l->m[0].data=(void *)m;
3607  l->m[1].data=(void *)iv;
3608  res->data = (char *)l;
3609  return FALSE;
3610 }
3611 //static BOOLEAN jjBAREISS_IM(leftv res, leftv v)
3612 //{
3613 // intvec *m=(intvec *)v->CopyD(INTMAT_CMD);
3614 // ivTriangMat(m);
3615 // res->data = (char *)m;
3616 // return FALSE;
3617 //}
3619 {
3621  b->hnf();
3622  res->data=(char*)b;
3623  return FALSE;
3624 }
3625 static BOOLEAN jjBI2N(leftv res, leftv u)
3626 {
3627  BOOLEAN bo=FALSE;
3628  number n=(number)u->CopyD();
3630  if (nMap!=NULL)
3631  res->data=nMap(n,coeffs_BIGINT,currRing->cf);
3632  else
3633  {
3634  Werror("cannot convert bigint to cring %s", nCoeffName(currRing->cf));
3635  bo=TRUE;
3636  }
3637  n_Delete(&n,coeffs_BIGINT);
3638  return bo;
3639 }
3640 static BOOLEAN jjBI2IM(leftv res, leftv u)
3641 {
3642  bigintmat *b=(bigintmat*)u->Data();
3643  res->data=(void *)bim2iv(b);
3644  return FALSE;
3645 }
3646 static BOOLEAN jjBI2P(leftv res, leftv u)
3647 {
3648  sleftv tmp;
3649  BOOLEAN bo=jjBI2N(&tmp,u);
3650  if (!bo)
3651  {
3652  number n=(number) tmp.data;
3653  if (nIsZero(n)) { res->data=NULL;nDelete(&n); }
3654  else
3655  {
3656  res->data=(void *)pNSet(n);
3657  }
3658  }
3659  return bo;
3660 }
3662 {
3663  return iiExprArithM(res,u,iiOp);
3664 }
3665 static BOOLEAN jjCHAR(leftv res, leftv v)
3666 {
3667  res->data = (char *)(long)rChar((ring)v->Data());
3668  return FALSE;
3669 }
3670 static BOOLEAN jjCOLS(leftv res, leftv v)
3671 {
3672  res->data = (char *)(long)MATCOLS((matrix)(v->Data()));
3673  return FALSE;
3674 }
3676 {
3677  res->data = (char *)(long)((bigintmat*)(v->Data()))->cols();
3678  return FALSE;
3679 }
3681 {
3682  res->data = (char *)(long)((intvec*)(v->Data()))->cols();
3683  return FALSE;
3684 }
3686 {
3687  // CopyD for POLY_CMD and VECTOR_CMD are identical:
3688  poly p=(poly)v->CopyD(POLY_CMD);
3689  if (p!=NULL) p_Cleardenom(p, currRing);
3690  res->data = (char *)p;
3691  return FALSE;
3692 }
3694 {
3695  res->data = (char *)(long)n_Size((number)v->Data(),coeffs_BIGINT);
3696  return FALSE;
3697 }
3699 {
3700  res->data = (char *)(long)nSize((number)v->Data());
3701  return FALSE;
3702 }
3704 {
3705  lists l=(lists)v->Data();
3706  res->data = (char *)(long)(lSize(l)+1);
3707  return FALSE;
3708 }
3710 {
3711  matrix m=(matrix)v->Data();
3712  res->data = (char *)(long)(MATROWS(m)*MATCOLS(m));
3713  return FALSE;
3714 }
3716 {
3717  res->data = (char *)(long)((intvec*)(v->Data()))->length();
3718  return FALSE;
3719 }
3721 {
3722  ring r=(ring)v->Data();
3723  int elems=-1;
3724  if (rField_is_Zp(r)) elems=r->cf->ch;
3725  else if (rField_is_GF(r)) elems=r->cf->m_nfCharQ;
3726  else if (rField_is_Zp_a(r) && (r->cf->type==n_algExt))
3727  {
3728  extern int ipower ( int b, int n ); /* factory/cf_util */
3729  elems=ipower(r->cf->ch,r->cf->extRing->pFDeg(r->cf->extRing->qideal->m[0],r->cf->extRing));
3730  }
3731  res->data = (char *)(long)elems;
3732  return FALSE;
3733 }
3734 static BOOLEAN jjDEG(leftv res, leftv v)
3735 {
3736  int dummy;
3737  poly p=(poly)v->Data();
3738  if (p!=NULL) res->data = (char *)currRing->pLDeg(p,&dummy,currRing);
3739  else res->data=(char *)-1;
3740  return FALSE;
3741 }
3742 static BOOLEAN jjDEG_M(leftv res, leftv u)
3743 {
3744  ideal I=(ideal)u->Data();
3745  int d=-1;
3746  int dummy;
3747  int i;
3748  for(i=IDELEMS(I)-1;i>=0;i--)
3749  if (I->m[i]!=NULL) d=si_max(d,(int)currRing->pLDeg(I->m[i],&dummy,currRing));
3750  res->data = (char *)(long)d;
3751  return FALSE;
3752 }
3753 static BOOLEAN jjDEGREE(leftv res, leftv v)
3754 {
3755  SPrintStart();
3756 #ifdef HAVE_RINGS
3758  {
3759  PrintS("// NOTE: computation of degree is being performed for\n");
3760  PrintS("// generic fibre, that is, over Q\n");
3761  }
3762 #endif
3763  assumeStdFlag(v);
3764  intvec *module_w=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
3765  scDegree((ideal)v->Data(),module_w,currRing->qideal);
3766  char *s=SPrintEnd();
3767  int l=strlen(s)-1;
3768  s[l]='\0';
3769  res->data=(void*)s;
3770  return FALSE;
3771 }
3773 {
3774  if ((v->rtyp==IDHDL)
3775  && ((myynest==IDLEV((idhdl)v->data))||(0==IDLEV((idhdl)v->data))))
3776  {
3777  res->data=(void *)(long)(IDLEV((idhdl)v->data)+1);
3778  }
3779  else if (v->rtyp!=0) res->data=(void *)(-1);
3780  return FALSE;
3781 }
3782 
3783 /// Return the denominator of the input number
3784 /// NOTE: the input number is normalized as a side effect
3786 {
3787  number n = reinterpret_cast<number>(v->Data());
3788  res->data = reinterpret_cast<void*>(n_GetDenom(n, currRing->cf));
3789  return FALSE;
3790 }
3791 
3792 /// Return the numerator of the input number
3793 /// NOTE: the input number is normalized as a side effect
3795 {
3796  number n = reinterpret_cast<number>(v->Data());
3797  res->data = reinterpret_cast<void*>(n_GetNumerator(n, currRing->cf));
3798  return FALSE;
3799 }
3800 
3801 static BOOLEAN jjDET(leftv res, leftv v)
3802 {
3803  matrix m=(matrix)v->Data();
3804  poly p;
3805  if (sm_CheckDet((ideal)m,m->cols(),TRUE, currRing))
3806  {
3808  p=sm_CallDet(I, currRing);
3809  idDelete(&I);
3810  }
3811  else
3812  p=singclap_det(m,currRing);
3813  res ->data = (char *)p;
3814  return FALSE;
3815 }
3816 static BOOLEAN jjDET_BI(leftv res, leftv v)
3817 {
3818  bigintmat * m=(bigintmat*)v->Data();
3819  int i,j;
3820  i=m->rows();j=m->cols();
3821  if(i==j)
3822  res->data = (char *)(long)singclap_det_bi(m,coeffs_BIGINT);
3823  else
3824  {
3825  Werror("det of %d x %d bigintmat",i,j);
3826  return TRUE;
3827  }
3828  return FALSE;
3829 }
3830 #ifdef SINGULAR_4_2
3831 static BOOLEAN jjDET_N2(leftv res, leftv v)
3832 {
3833  bigintmat * m=(bigintmat*)v->Data();
3834  number2 r=(number2)omAlloc0(sizeof(*r));
3835  int i,j;
3836  i=m->rows();j=m->cols();
3837  if(i==j)
3838  {
3839  r->n=m->det();
3840  r->cf=m->basecoeffs();
3841  }
3842  else
3843  {
3844  omFreeSize(r,sizeof(*r));
3845  Werror("det of %d x %d cmatrix",i,j);
3846  return TRUE;
3847  }
3848  res->data=(void*)r;
3849  return FALSE;
3850 }
3851 #endif
3852 static BOOLEAN jjDET_I(leftv res, leftv v)
3853 {
3854  intvec * m=(intvec*)v->Data();
3855  int i,j;
3856  i=m->rows();j=m->cols();
3857  if(i==j)
3858  res->data = (char *)(long)singclap_det_i(m,currRing);
3859  else
3860  {
3861  Werror("det of %d x %d intmat",i,j);
3862  return TRUE;
3863  }
3864  return FALSE;
3865 }
3866 static BOOLEAN jjDET_S(leftv res, leftv v)
3867 {
3868  ideal I=(ideal)v->Data();
3869  poly p;
3870  if (IDELEMS(I)<1) return TRUE;
3871  if (sm_CheckDet(I,IDELEMS(I),FALSE, currRing))
3872  {
3874  p=singclap_det(m,currRing);
3875  idDelete((ideal *)&m);
3876  }
3877  else
3878  p=sm_CallDet(I, currRing);
3879  res->data = (char *)p;
3880  return FALSE;
3881 }
3882 static BOOLEAN jjDIM(leftv res, leftv v)
3883 {
3884  assumeStdFlag(v);
3886  {
3887  Warn("dim(%s) may be wrong because the mixed monomial ordering",v->Name());
3888  }
3889 #ifdef HAVE_RINGS
3890  if (rField_is_Ring(currRing))
3891  {
3892  ideal vid = (ideal)v->Data();
3893  int i = idPosConstant(vid);
3894  if ((i != -1) && (n_IsUnit(pGetCoeff(vid->m[i]),currRing->cf)))
3895  { /* ideal v contains unit; dim = -1 */
3896  res->data = (char *)-1L;
3897  return FALSE;
3898  }
3899  ideal vv = id_Head(vid,currRing);
3900  idSkipZeroes(vv);
3901  int j = idPosConstant(vv);
3902  long d;
3903  if(j == -1)
3904  {
3905  d = (long)scDimInt(vv, currRing->qideal);
3907  d++;
3908  }
3909  else
3910  {
3911  if(n_IsUnit(pGetCoeff(vv->m[j]),currRing->cf))
3912  d = -1;
3913  else
3914  d = (long)scDimInt(vv, currRing->qideal);
3915  }
3916  //Anne's Idea for std(4,2x) = 0 bug
3917  long dcurr = d;
3918  for(unsigned ii=0;ii<(unsigned)IDELEMS(vv);ii++)
3919  {
3920  if(vv->m[ii] != NULL && !n_IsUnit(pGetCoeff(vv->m[ii]),currRing->cf))
3921  {
3922  ideal vc = idCopy(vv);
3923  poly c = pInit();
3924  pSetCoeff0(c,nCopy(pGetCoeff(vv->m[ii])));
3925  idInsertPoly(vc,c);
3926  idSkipZeroes(vc);
3927  for(unsigned jj = 0;jj<(unsigned)IDELEMS(vc)-1;jj++)
3928  {
3929  if((vc->m[jj]!=NULL)
3930  && (n_DivBy(pGetCoeff(vc->m[jj]),pGetCoeff(c),currRing->cf)))
3931  {
3932  pDelete(&vc->m[jj]);
3933  }
3934  }
3935  idSkipZeroes(vc);
3936  j = idPosConstant(vc);
3937  if (j != -1) pDelete(&vc->m[j]);
3938  dcurr = (long)scDimInt(vc, currRing->qideal);
3939  // the following assumes the ground rings to be either zero- or one-dimensional
3940  if((j==-1) && rField_is_Ring_Z(currRing))
3941  {
3942  // should also be activated for other euclidean domains as groundfield
3943  dcurr++;
3944  }
3945  idDelete(&vc);
3946  }
3947  if(dcurr > d)
3948  d = dcurr;
3949  }
3950  res->data = (char *)d;
3951  idDelete(&vv);
3952  return FALSE;
3953  }
3954 #endif
3955  res->data = (char *)(long)scDimInt((ideal)(v->Data()),currRing->qideal);
3956  return FALSE;
3957 }
3959 {
3960  si_link l = (si_link)v->Data();
3961  if (slDump(l))
3962  {
3963  const char *s;
3964  if ((l!=NULL)&&(l->name!=NULL)) s=l->name;
3965  else s=sNoName_fe;
3966  Werror("cannot dump to `%s`",s);
3967  return TRUE;
3968  }
3969  else
3970  return FALSE;
3971 }
3972 static BOOLEAN jjE(leftv res, leftv v)
3973 {
3974  res->data = (char *)pOne();
3975  int co=(int)(long)v->Data();
3976  if (co>0)
3977  {
3978  pSetComp((poly)res->data,co);
3979  pSetm((poly)res->data);
3980  }
3981  else WerrorS("argument of gen must be positive");
3982  return (co<=0);
3983 }
3985 {
3986  char * d = (char *)v->Data();
3987  char * s = (char *)omAlloc(strlen(d) + 13);
3988  strcpy( s, (char *)d);
3989  strcat( s, "\n;RETURN();\n");
3990  newBuffer(s,BT_execute);
3991  return yyparse();
3992 }
3993 static BOOLEAN jjFACSTD(leftv res, leftv v)
3994 {
3996  if (currRing->cf->convSingNFactoryN!=NULL) /* conversion to factory*/
3997  {
3998  ideal_list p,h;
3999  h=kStdfac((ideal)v->Data(),NULL,testHomog,NULL);
4000  if (h==NULL)
4001  {
4002  L->Init(1);
4003  L->m[0].data=(char *)idInit(1);
4004  L->m[0].rtyp=IDEAL_CMD;
4005  }
4006  else
4007  {
4008  p=h;
4009  int l=0;
4010  while (p!=NULL) { p=p->next;l++; }
4011  L->Init(l);
4012  l=0;
4013  while(h!=NULL)
4014  {
4015  L->m[l].data=(char *)h->d;
4016  L->m[l].rtyp=IDEAL_CMD;
4017  p=h->next;
4018  omFreeSize(h,sizeof(*h));
4019  h=p;
4020  l++;
4021  }
4022  }
4023  }
4024  else
4025  {
4026  WarnS("no factorization implemented");
4027  L->Init(1);
4028  iiExprArith1(&(L->m[0]),v,STD_CMD);
4029  }
4030  res->data=(void *)L;
4031  return FALSE;
4032 }
4033 static BOOLEAN jjFAC_P(leftv res, leftv u)
4034 {
4035  intvec *v=NULL;
4036  singclap_factorize_retry=0;
4037  ideal f=singclap_factorize((poly)(u->CopyD()), &v, 0,currRing);
4038  if (f==NULL) return TRUE;
4039  ivTest(v);
4041  l->Init(2);
4042  l->m[0].rtyp=IDEAL_CMD;
4043  l->m[0].data=(void *)f;
4044  l->m[1].rtyp=INTVEC_CMD;
4045  l->m[1].data=(void *)v;
4046  res->data=(void *)l;
4047  return FALSE;
4048 }
4050 {
4051  si_link l = (si_link)v->Data();
4052  if (slGetDump(l))
4053  {
4054  const char *s;
4055  if ((l!=NULL)&&(l->name!=NULL)) s=l->name;
4056  else s=sNoName_fe;
4057  Werror("cannot get dump from `%s`",s);
4058  return TRUE;
4059  }
4060  else
4061  return FALSE;
4062 }
4064 {
4065  assumeStdFlag(v);
4066  ideal I=(ideal)v->Data();
4067  res->data=(void *)iiHighCorner(I,0);
4068  return FALSE;
4069 }
4071 {
4072  assumeStdFlag(v);
4073  intvec *w=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
4074  BOOLEAN delete_w=FALSE;
4075  ideal I=(ideal)v->Data();
4076  int i;
4077  poly p=NULL,po=NULL;
4078  int rk=id_RankFreeModule(I,currRing);
4079  if (w==NULL)
4080  {
4081  w = new intvec(rk);
4082  delete_w=TRUE;
4083  }
4084  for(i=rk;i>0;i--)
4085  {
4086  p=iiHighCorner(I,i);
4087  if (p==NULL)
4088  {
4089  WerrorS("module must be zero-dimensional");
4090  if (delete_w) delete w;
4091  return TRUE;
4092  }
4093  if (po==NULL)
4094  {
4095  po=p;
4096  }
4097  else
4098  {
4099  // now po!=NULL, p!=NULL
4100  int d=(currRing->pFDeg(po,currRing)-(*w)[pGetComp(po)-1] - currRing->pFDeg(p,currRing)+(*w)[i-1]);
4101  if (d==0)
4102  d=pLmCmp(po,p);
4103  if (d > 0)
4104  {
4105  pDelete(&p);
4106  }
4107  else // (d < 0)
4108  {
4109  pDelete(&po); po=p;
4110  }
4111  }
4112  }
4113  if (delete_w) delete w;
4114  res->data=(void *)po;
4115  return FALSE;
4116 }
4118 {
4119 #ifdef HAVE_RINGS
4121  {
4122  PrintS("// NOTE: computation of Hilbert series etc. is being\n");
4123  PrintS("// performed for generic fibre, that is, over Q\n");
4124  }
4125 #endif
4126  assumeStdFlag(v);
4127  intvec *module_w=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
4128  //scHilbertPoly((ideal)v->Data(),currRing->qideal);
4129  hLookSeries((ideal)v->Data(),module_w,currRing->qideal);
4130  return FALSE;
4131 }
4133 {
4134 #ifdef HAVE_RINGS
4136  {
4137  PrintS("// NOTE: computation of Hilbert series etc. is being\n");
4138  PrintS("// performed for generic fibre, that is, over Q\n");
4139  }
4140 #endif
4141  res->data=(void *)hSecondSeries((intvec *)v->Data());
4142  return FALSE;
4143 }
4144 static BOOLEAN jjHOMOG1(leftv res, leftv v)
4145 {
4146  intvec *w=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
4147  ideal v_id=(ideal)v->Data();
4148  if (w==NULL)
4149  {
4150  res->data=(void *)(long)idHomModule(v_id,currRing->qideal,&w);
4151  if (res->data!=NULL)
4152  {
4153  if (v->rtyp==IDHDL)
4154  {
4155  char *s_isHomog=omStrDup("isHomog");
4156  if (v->e==NULL)
4157  atSet((idhdl)(v->data),s_isHomog,w,INTVEC_CMD);
4158  else
4159  atSet((idhdl)(v->LData()),s_isHomog,w,INTVEC_CMD);
4160  }
4161  else if (w!=NULL) delete w;
4162  } // if res->data==NULL then w==NULL
4163  }
4164  else
4165  {
4166  res->data=(void *)(long)idTestHomModule(v_id,currRing->qideal,w);
4167  if((res->data==NULL) && (v->rtyp==IDHDL))
4168  {
4169  if (v->e==NULL)
4170  atKill((idhdl)(v->data),"isHomog");
4171  else
4172  atKill((idhdl)(v->LData()),"isHomog");
4173  }
4174  }
4175  return FALSE;
4176 }
4178 {
4179  res->data = (char *)idMaxIdeal((int)(long)v->Data());
4180  setFlag(res,FLAG_STD);
4181  return FALSE;
4182 }
4184 {
4185  matrix mat=(matrix)v->CopyD(MATRIX_CMD);
4186  IDELEMS((ideal)mat)=MATCOLS(mat)*MATROWS(mat);
4187  if (IDELEMS((ideal)mat)==0)
4188  {
4189  idDelete((ideal *)&mat);
4190  mat=(matrix)idInit(1,1);
4191  }
4192  else
4193  {
4194  MATROWS(mat)=1;
4195  mat->rank=1;
4196  idTest((ideal)mat);
4197  }
4198  res->data=(char *)mat;
4199  return FALSE;
4200 }
4202 {
4203  map m=(map)v->CopyD(MAP_CMD);
4204  omFree((ADDRESS)m->preimage);
4205  m->preimage=NULL;
4206  ideal I=(ideal)m;
4207  I->rank=1;
4208  res->data=(char *)I;
4209  return FALSE;
4210 }
4212 {
4213  if (currRing!=NULL)
4214  {
4215  ring q=(ring)v->Data();
4216  if (rSamePolyRep(currRing, q))
4217  {
4218  if (q->qideal==NULL)
4219  res->data=(char *)idInit(1,1);
4220  else
4221  res->data=(char *)idCopy(q->qideal);
4222  return FALSE;
4223  }
4224  }
4225  WerrorS("can only get ideal from identical qring");
4226  return TRUE;
4227 }
4228 static BOOLEAN jjIm2Iv(leftv res, leftv v)
4229 {
4230  intvec *iv = (intvec *)v->CopyD(INTMAT_CMD);
4231  iv->makeVector();
4232  res->data = iv;
4233  return FALSE;
4234 }
4235 static BOOLEAN jjIMPART(leftv res, leftv v)
4236 {
4237  res->data = (char *)n_ImPart((number)v->Data(),currRing->cf);
4238  return FALSE;
4239 }
4241 {
4242  assumeStdFlag(v);
4243  res->data=(void *)scIndIntvec((ideal)(v->Data()),currRing->qideal);
4244  return FALSE;
4245 }
4247 {
4248  ideal result=kInterRed((ideal)(v->Data()), currRing->qideal);
4249 #ifdef HAVE_RINGS
4251  WarnS("interred: this command is experimental over the integers");
4252 #endif
4253  if (TEST_OPT_PROT) { PrintLn(); mflush(); }
4254  res->data = result;
4255  return FALSE;
4256 }
4258 {
4259  res->data = (char *)(long)pVar((poly)v->Data());
4260  return FALSE;
4261 }
4263 {
4264  res->data = (char *)(long)(r_IsRingVar((char *)v->Data(), currRing->names,
4265  currRing->N)+1);
4266  return FALSE;
4267 }
4269 {
4270  res->data = (char *)0;
4271  return FALSE;
4272 }
4274 {
4275  ideal i=idInit(currRing->N,1);
4276  int k;
4277  poly p=(poly)(v->Data());
4278  for (k=currRing->N;k>0;k--)
4279  {
4280  i->m[k-1]=pDiff(p,k);
4281  }
4282  res->data = (char *)i;
4283  return FALSE;
4284 }
4286 {
4287  if (!nCoeff_is_transExt(currRing->cf))
4288  {
4289  WerrorS("differentiation not defined in the coefficient ring");
4290  return TRUE;
4291  }
4292  number n = (number) u->Data();
4293  number k = (number) v->Data();
4294  res->data = ntDiff(n,k,currRing->cf);
4295  return FALSE;
4296 }
4297 /*2
4298  * compute Jacobi matrix of a module/matrix
4299  * Jacobi(M) := ( diff(Mt,var(1))|, ... ,| diff(Mt,var(currRing->N)) ),
4300  * where Mt := transpose(M)
4301  * Note that this is consistent with the current conventions for jacob in Singular,
4302  * whereas M2 computes its transposed.
4303  */
4305 {
4306  ideal id = (ideal)a->Data();
4307  id = id_Transp(id,currRing);
4308  int W = IDELEMS(id);
4309 
4310  ideal result = idInit(W * currRing->N, id->rank);
4311  poly *p = result->m;
4312 
4313  for( int v = 1; v <= currRing->N; v++ )
4314  {
4315  poly* q = id->m;
4316  for( int i = 0; i < W; i++, p++, q++ )
4317  *p = pDiff( *q, v );
4318  }
4319  idDelete(&id);
4320 
4321  res->data = (char *)result;
4322  return FALSE;
4323 }
4324 
4325 
4326 static BOOLEAN jjKBASE(leftv res, leftv v)
4327 {
4328  assumeStdFlag(v);
4329  res->data = (char *)scKBase(-1,(ideal)(v->Data()),currRing->qideal);
4330  return FALSE;
4331 }
4332 static BOOLEAN jjL2R(leftv res, leftv v)
4333 {
4334  res->data=(char *)syConvList((lists)v->Data());
4335  if (res->data != NULL)
4336  return FALSE;
4337  else
4338  return TRUE;
4339 }
4341 {
4342  poly p=(poly)v->Data();
4343  if (p==NULL)
4344  {
4345  res->data=(char *)nInit(0);
4346  }
4347  else
4348  {
4349  res->data=(char *)nCopy(pGetCoeff(p));
4350  }
4351  return FALSE;
4352 }
4354 {
4355  poly p=(poly)v->Data();
4356  int s=currRing->N;
4357  if (v->Typ()==VECTOR_CMD) s++;
4358  intvec *iv=new intvec(s);
4359  if (p!=NULL)
4360  {
4361  for(int i = currRing->N;i;i--)
4362  {
4363  (*iv)[i-1]=pGetExp(p,i);
4364  }
4365  if (s!=currRing->N)
4366  (*iv)[currRing->N]=pGetComp(p);
4367  }
4368  res->data=(char *)iv;
4369  return FALSE;
4370 }
4372 {
4373  poly p=(poly)v->Data();
4374  if (p == NULL)
4375  {
4376  res->data = (char*) NULL;
4377  }
4378  else
4379  {
4380  poly lm = pLmInit(p);
4381  pSetCoeff(lm, nInit(1));
4382  res->data = (char*) lm;
4383  }
4384  return FALSE;
4385 }
4386 static BOOLEAN jjLOAD1(leftv /*res*/, leftv v)
4387 {
4388  return jjLOAD((char*)v->Data(),FALSE);
4389 }
4391 {
4392  ring r=rCompose((lists)v->Data());
4393  if (r==NULL) return TRUE;
4394  res->data=(char *)r;
4395  return FALSE;
4396 }
4397 static BOOLEAN jjPFAC1(leftv res, leftv v)
4398 {
4399  /* call method jjPFAC2 with second argument = 0 (meaning that no
4400  valid bound for the prime factors has been given) */
4401  sleftv tmp;
4402  memset(&tmp, 0, sizeof(tmp));
4403  tmp.rtyp = INT_CMD;
4404  return jjPFAC2(res, v, &tmp);
4405 }
4407 {
4408  /* computes the LU-decomposition of a matrix M;
4409  i.e., M = P * L * U, where
4410  - P is a row permutation matrix,
4411  - L is in lower triangular form,
4412  - U is in upper row echelon form
4413  Then, we also have P * M = L * U.
4414  A list [P, L, U] is returned. */
4415  matrix mat = (const matrix)v->Data();
4416  if (!idIsConstant((ideal)mat))
4417  {
4418  WerrorS("matrix must be constant");
4419  return TRUE;
4420  }
4421  matrix pMat;
4422  matrix lMat;
4423  matrix uMat;
4424 
4425  luDecomp(mat, pMat, lMat, uMat);
4426 
4428  ll->Init(3);
4429  ll->m[0].rtyp=MATRIX_CMD; ll->m[0].data=(void *)pMat;
4430  ll->m[1].rtyp=MATRIX_CMD; ll->m[1].data=(void *)lMat;
4431  ll->m[2].rtyp=MATRIX_CMD; ll->m[2].data=(void *)uMat;
4432  res->data=(char*)ll;
4433 
4434  return FALSE;
4435 }
4436 static BOOLEAN jjMEMORY(leftv res, leftv v)
4437 {
4438  // clean out "_":
4440  memset(&sLastPrinted,0,sizeof(sleftv));
4441  // collect all info:
4442  omUpdateInfo();
4443  switch(((int)(long)v->Data()))
4444  {
4445  case 0:
4446  res->data=(char *)n_Init(om_Info.UsedBytes,coeffs_BIGINT);
4447  break;
4448  case 1:
4449  res->data = (char *)n_Init(om_Info.CurrentBytesSystem,coeffs_BIGINT);
4450  break;
4451  case 2:
4452  res->data = (char *)n_Init(om_Info.MaxBytesSystem,coeffs_BIGINT);
4453  break;
4454  default:
4455  omPrintStats(stdout);
4456  omPrintInfo(stdout);
4457  omPrintBinStats(stdout);
4458  res->data = (char *)0;
4459  res->rtyp = NONE;
4460  }
4461  return FALSE;
4462  res->data = (char *)0;
4463  return FALSE;
4464 }
4465 //static BOOLEAN jjMONITOR1(leftv res, leftv v)
4466 //{
4467 // return jjMONITOR2(res,v,NULL);
4468 //}
4469 static BOOLEAN jjMSTD(leftv res, leftv v)
4470 {
4471  int t=v->Typ();
4472  ideal r,m;
4473  r=kMin_std((ideal)v->Data(),currRing->qideal,testHomog,NULL,m);
4475  l->Init(2);
4476  l->m[0].rtyp=t;
4477  l->m[0].data=(char *)r;
4478  setFlag(&(l->m[0]),FLAG_STD);
4479  l->m[1].rtyp=t;
4480  l->m[1].data=(char *)m;
4481  res->data=(char *)l;
4482  return FALSE;
4483 }
4484 static BOOLEAN jjMULT(leftv res, leftv v)
4485 {
4486  assumeStdFlag(v);
4487  res->data = (char *)(long)scMultInt((ideal)(v->Data()),currRing->qideal);
4488  return FALSE;
4489 }
4491 {
4492  intvec *weights=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
4493 
4494  syStrategy tmp=(syStrategy)v->Data();
4495  tmp = syMinimize(tmp); // enrich itself!
4496 
4497  res->data=(char *)tmp;
4498 
4499  if (weights!=NULL)
4500  atSet(res, omStrDup("isHomog"),ivCopy(weights),INTVEC_CMD);
4501 
4502  return FALSE;
4503 }
4504 static BOOLEAN jjN2BI(leftv res, leftv v)
4505 {
4506  number n,i; i=(number)v->Data();
4508  if (nMap!=NULL)
4509  n=nMap(i,currRing->cf,coeffs_BIGINT);
4510  else goto err;
4511  res->data=(void *)n;
4512  return FALSE;
4513 err:
4514  WerrorS("cannot convert to bigint"); return TRUE;
4515 }
4516 static BOOLEAN jjNAMEOF(leftv res, leftv v)
4517 {
4518  if ((v->rtyp==IDHDL)||(v->rtyp==ALIAS_CMD))
4519  res->data=omStrDup(v->name);
4520  else if (v->name==NULL)
4521  res->data=omStrDup("");
4522  else
4523  {
4524  res->data = (char *)v->name;
4525  v->name=NULL;
4526  }
4527  return FALSE;
4528 }
4529 static BOOLEAN jjNAMES(leftv res, leftv v)
4530 {
4531  res->data=ipNameList(((ring)v->Data())->idroot);
4532  return FALSE;
4533 }
4535 {
4536  res->data=ipNameListLev((IDROOT),(int)(long)v->Data());
4537  return FALSE;
4538 }
4539 static BOOLEAN jjNOT(leftv res, leftv v)
4540 {
4541  res->data=(char*)(long)((long)v->Data()==0 ? 1 : 0);
4542  return FALSE;
4543 }
4544 static BOOLEAN jjNVARS(leftv res, leftv v)
4545 {
4546  res->data = (char *)(long)(((ring)(v->Data()))->N);
4547  return FALSE;
4548 }
4550 {
4551  si_link l=(si_link)v->Data();
4552  if (iiOp==OPEN_CMD) return slOpen(l, SI_LINK_OPEN,v);
4553  else { slPrepClose(l); return slClose(l);}
4554 }
4555 static BOOLEAN jjORD(leftv res, leftv v)
4556 {
4557  poly p=(poly)v->Data();
4558  res->data=(char *)( p==NULL ? -1 : currRing->pFDeg(p,currRing) );
4559  return FALSE;
4560 }
4561 static BOOLEAN jjPAR1(leftv res, leftv v)
4562 {
4563  int i=(int)(long)v->Data();
4564  int p=0;
4565  p=rPar(currRing);
4566  if ((0<i) && (i<=p))
4567  {
4568  res->data=(char *)n_Param(i,currRing);
4569  }
4570  else
4571  {
4572  Werror("par number %d out of range 1..%d",i,p);
4573  return TRUE;
4574  }
4575  return FALSE;
4576 }
4577 static BOOLEAN jjPARDEG(leftv res, leftv v)
4578 {
4579  number nn=(number)v->Data();
4580  res->data = (char *)(long)n_ParDeg(nn, currRing->cf);
4581  return FALSE;
4582 }
4584 {
4585  if (currRing==NULL)
4586  {
4587  WerrorS("no ring active");
4588  return TRUE;
4589  }
4590  int i=(int)(long)v->Data();
4591  int p=0;
4592  if ((0<i) && (rParameter(currRing)!=NULL) && (i<=(p=rPar(currRing))))
4593  res->data=omStrDup(rParameter(currRing)[i-1]);
4594  else
4595  {
4596  Werror("par number %d out of range 1..%d",i,p);
4597  return TRUE;
4598  }
4599  return FALSE;
4600 }
4601 static BOOLEAN jjP2BI(leftv res, leftv v)
4602 {
4603  poly p=(poly)v->Data();
4604  if (p==NULL) { res->data=(char *)n_Init(0,coeffs_BIGINT); return FALSE; }
4605  if ((pNext(p)!=NULL)|| (!pIsConstant(p)))
4606  {
4607  WerrorS("poly must be constant");
4608  return TRUE;
4609  }
4610  number i=pGetCoeff(p);
4611  number n;
4613  if (nMap!=NULL)
4614  n=nMap(i,currRing->cf,coeffs_BIGINT);
4615  else goto err;
4616  res->data=(void *)n;
4617  return FALSE;
4618 err:
4619  WerrorS("cannot convert to bigint"); return TRUE;
4620 }
4621 static BOOLEAN jjP2I(leftv res, leftv v)
4622 {
4623  poly p=(poly)v->Data();
4624  if (p==NULL) { /*res->data=(char *)0;*/ return FALSE; }
4625  if ((pNext(p)!=NULL)|| (!pIsConstant(p)))
4626  {
4627  WerrorS("poly must be constant");
4628  return TRUE;
4629  }
4630  res->data = (char *)(long)iin_Int(pGetCoeff(p),currRing->cf);
4631  return FALSE;
4632 }
4634 {
4635  map mapping=(map)v->Data();
4636  syMake(res,omStrDup(mapping->preimage));
4637  return FALSE;
4638 }
4639 static BOOLEAN jjPRIME(leftv res, leftv v)
4640 {
4641  int i = IsPrime((int)(long)(v->Data()));
4642  res->data = (char *)(long)(i > 1 ? i : 2);
4643  return FALSE;
4644 }
4645 static BOOLEAN jjPRUNE(leftv res, leftv v)
4646 {
4647  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4648  ideal v_id=(ideal)v->Data();
4649  if (w!=NULL)
4650  {
4651  if (!idTestHomModule(v_id,currRing->qideal,w))
4652  {
4653  WarnS("wrong weights");
4654  w=NULL;
4655  // and continue at the non-homog case below
4656  }
4657  else
4658  {
4659  w=ivCopy(w);
4660  intvec **ww=&w;
4661  res->data = (char *)idMinEmbedding(v_id,FALSE,ww);
4662  atSet(res,omStrDup("isHomog"),*ww,INTVEC_CMD);
4663  return FALSE;
4664  }
4665  }
4666  res->data = (char *)idMinEmbedding(v_id);
4667  return FALSE;
4668 }
4669 static BOOLEAN jjP2N(leftv res, leftv v)
4670 {
4671  number n;
4672  poly p;
4673  if (((p=(poly)v->Data())!=NULL)
4674  && (pIsConstant(p)))
4675  {
4676  n=nCopy(pGetCoeff(p));
4677  }
4678  else
4679  {
4680  n=nInit(0);
4681  }
4682  res->data = (char *)n;
4683  return FALSE;
4684 }
4686 {
4687  char *s= (char *)v->Data();
4688  for(unsigned i=0; i<sArithBase.nCmdUsed; i++)
4689  {
4690  //Print("test %d, >>%s<<, tab:>>%s<<\n",i,s,sArithBase.sCmds[i].name);
4691  if (strcmp(s, sArithBase.sCmds[i].name) == 0)
4692  {
4693  res->data = (char *)1;
4694  return FALSE;
4695  }
4696  }
4697  //res->data = (char *)0;
4698  return FALSE;
4699 }
4700 static BOOLEAN jjRANK1(leftv res, leftv v)
4701 {
4702  matrix m =(matrix)v->Data();
4703  int rank = luRank(m, 0);
4704  res->data =(char *)(long)rank;
4705  return FALSE;
4706 }
4707 static BOOLEAN jjREAD(leftv res, leftv v)
4708 {
4709  return jjREAD2(res,v,NULL);
4710 }
4712 {
4713  res->data = (char *)(long)iiRegularity((lists)v->Data());
4714  return FALSE;
4715 }
4716 static BOOLEAN jjREPART(leftv res, leftv v)
4717 {
4718  res->data = (char *)n_RePart((number)v->Data(),currRing->cf);
4719  return FALSE;
4720 }
4722 {
4723  ring r=(ring)v->Data();
4724  if (r!=NULL)
4725  res->data = (char *)rDecompose((ring)v->Data());
4726  return (r==NULL)||(res->data==NULL);
4727 }
4729 {
4730  coeffs r=(coeffs)v->Data();
4731  if (r!=NULL)
4732  return rDecompose_CF(res,r);
4733  return TRUE;
4734 }
4736 {
4737  ring r=(ring)v->Data();
4738  if (r!=NULL)
4739  res->data = (char *)rDecompose_list_cf((ring)v->Data());
4740  return (r==NULL)||(res->data==NULL);
4741 }
4742 static BOOLEAN jjROWS(leftv res, leftv v)
4743 {
4744  ideal i = (ideal)v->Data();
4745  res->data = (char *)i->rank;
4746  return FALSE;
4747 }
4749 {
4750  res->data = (char *)(long)((bigintmat*)(v->Data()))->rows();
4751  return FALSE;
4752 }
4754 {
4755  res->data = (char *)(long)((intvec*)(v->Data()))->rows();
4756  return FALSE;
4757 }
4758 static BOOLEAN jjRPAR(leftv res, leftv v)
4759 {
4760  res->data = (char *)(long)rPar(((ring)v->Data()));
4761  return FALSE;
4762 }
4764 {
4765 #ifdef HAVE_PLURAL
4766  const bool bIsSCA = rIsSCA(currRing);
4767 #else
4768  const bool bIsSCA = false;
4769 #endif
4770 
4771  if ((currRing->qideal!=NULL) && !bIsSCA)
4772  {
4773  WerrorS("qring not supported by slimgb at the moment");
4774  return TRUE;
4775  }
4777  {
4778  WerrorS("ordering must be global for slimgb");
4779  return TRUE;
4780  }
4781  intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
4782  // tHomog hom=testHomog;
4783  ideal u_id=(ideal)u->Data();
4784  if (w!=NULL)
4785  {
4786  if (!idTestHomModule(u_id,currRing->qideal,w))
4787  {
4788  WarnS("wrong weights");
4789  w=NULL;
4790  }
4791  else
4792  {
4793  w=ivCopy(w);
4794  // hom=isHomog;
4795  }
4796  }
4797 
4798  assume(u_id->rank>=id_RankFreeModule(u_id, currRing));
4799  res->data=(char *)t_rep_gb(currRing,
4800  u_id,u_id->rank);
4801  //res->data=(char *)t_rep_gb(currRing, u_id);
4802 
4804  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
4805  return FALSE;
4806 }
4807 static BOOLEAN jjSBA(leftv res, leftv v)
4808 {
4809  ideal result;
4810  ideal v_id=(ideal)v->Data();
4811  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4812  tHomog hom=testHomog;
4813  if (w!=NULL)
4814  {
4815  if (!idTestHomModule(v_id,currRing->qideal,w))
4816  {
4817  WarnS("wrong weights");
4818  w=NULL;
4819  }
4820  else
4821  {
4822  hom=isHomog;
4823  w=ivCopy(w);
4824  }
4825  }
4826  result=kSba(v_id,currRing->qideal,hom,&w,1,0);
4827  idSkipZeroes(result);
4828  res->data = (char *)result;
4830  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
4831  return FALSE;
4832 }
4833 static BOOLEAN jjSBA_1(leftv res, leftv v, leftv u)
4834 {
4835  ideal result;
4836  ideal v_id=(ideal)v->Data();
4837  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4838  tHomog hom=testHomog;
4839  if (w!=NULL)
4840  {
4841  if (!idTestHomModule(v_id,currRing->qideal,w))
4842  {
4843  WarnS("wrong weights");
4844  w=NULL;
4845  }
4846  else
4847  {
4848  hom=isHomog;
4849  w=ivCopy(w);
4850  }
4851  }
4852  result=kSba(v_id,currRing->qideal,hom,&w,(int)(long)u->Data(),0);
4853  idSkipZeroes(result);
4854  res->data = (char *)result;
4856  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
4857  return FALSE;
4858 }
4859 static BOOLEAN jjSBA_2(leftv res, leftv v, leftv u, leftv t)
4860 {
4861  ideal result;
4862  ideal v_id=(ideal)v->Data();
4863  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4864  tHomog hom=testHomog;
4865  if (w!=NULL)
4866  {
4867  if (!idTestHomModule(v_id,currRing->qideal,w))
4868  {
4869  WarnS("wrong weights");
4870  w=NULL;
4871  }
4872  else
4873  {
4874  hom=isHomog;
4875  w=ivCopy(w);
4876  }
4877  }
4878  result=kSba(v_id,currRing->qideal,hom,&w,(int)(long)u->Data(),(int)(long)t->Data());
4879  idSkipZeroes(result);
4880  res->data = (char *)result;
4882  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
4883  return FALSE;
4884 }
4885 static BOOLEAN jjSTD(leftv res, leftv v)
4886 {
4887  ideal result;
4888  ideal v_id=(ideal)v->Data();
4889  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4890  tHomog hom=testHomog;
4891  if (w!=NULL)
4892  {
4893  if (!idTestHomModule(v_id,currRing->qideal,w))
4894  {
4895  WarnS("wrong weights");
4896  w=NULL;
4897  }
4898  else
4899  {
4900  hom=isHomog;
4901  w=ivCopy(w);
4902  }
4903  }
4904  result=kStd(v_id,currRing->qideal,hom,&w);
4905  idSkipZeroes(result);
4906  res->data = (char *)result;
4908  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
4909  return FALSE;
4910 }
4912 {
4913  res->data = (char *)idSort((ideal)v->Data());
4914  return FALSE;
4915 }
4917 {
4918  singclap_factorize_retry=0;
4919  intvec *v=NULL;
4920  ideal f=singclap_sqrfree((poly)(u->CopyD()), &v, 0, currRing);
4921  if (f==NULL) return TRUE;
4922  ivTest(v);
4924  l->Init(2);
4925  l->m[0].rtyp=IDEAL_CMD;
4926  l->m[0].data=(void *)f;
4927  l->m[1].rtyp=INTVEC_CMD;
4928  l->m[1].data=(void *)v;
4929  res->data=(void *)l;
4930  return FALSE;
4931 }
4932 #if 1
4933 static BOOLEAN jjSYZYGY(leftv res, leftv v)
4934 {
4935  intvec *w=NULL;
4936  res->data = (char *)idSyzygies((ideal)v->Data(),testHomog,&w);
4937  if (w!=NULL) delete w;
4939  return FALSE;
4940 }
4941 #else
4942 // activate, if idSyz handle module weights correctly !
4943 static BOOLEAN jjSYZYGY(leftv res, leftv v)
4944 {
4945  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4946  ideal v_id=(ideal)v->Data();
4947  tHomog hom=testHomog;
4948  int add_row_shift=0;
4949  if (w!=NULL)
4950  {
4951  w=ivCopy(w);
4952  add_row_shift=w->min_in();
4953  (*w)-=add_row_shift;
4954  if (idTestHomModule(v_id,currRing->qideal,w))
4955  hom=isHomog;
4956  else
4957  {
4958  //WarnS("wrong weights");
4959  delete w; w=NULL;
4960  hom=testHomog;
4961  }
4962  }
4963  res->data = (char *)idSyzygies(v_id,hom,&w);
4964  if (w!=NULL)
4965  {
4966  atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
4967  }
4968  return FALSE;
4969 }
4970 #endif
4972 {
4973  res->data = (char *)(long)ivTrace((intvec*)(v->Data()));
4974  return FALSE;
4975 }
4977 {
4978  res->data = (char *)(((bigintmat*)(v->Data()))->transpose());
4979  return FALSE;
4980 }
4982 {
4983  res->data = (char *)ivTranp((intvec*)(v->Data()));
4984  return FALSE;
4985 }
4986 #ifdef HAVE_PLURAL
4988 {
4989  ring r = (ring)a->Data();
4990  //if (rIsPluralRing(r))
4991  if (r->OrdSgn==1)
4992  {
4993  res->data = rOpposite(r);
4994  }
4995  else
4996  {
4997  WarnS("opposite only for global orderings");
4998  res->data = rCopy(r);
4999  }
5000  return FALSE;
5001 }
5003 {
5004  ring r = (ring)a->Data();
5005  if (rIsPluralRing(r))
5006  {
5007  ring s = rEnvelope(r);
5008  res->data = s;
5009  }
5010  else res->data = rCopy(r);
5011  return FALSE;
5012 }
5014 {
5015  if (rIsPluralRing(currRing)) res->data=(ideal)twostd((ideal)a->Data());
5016  else res->data=(ideal)a->CopyD();
5017  setFlag(res,FLAG_STD);
5018  setFlag(res,FLAG_TWOSTD);
5019  return FALSE;
5020 }
5021 #endif
5022 
5023 static BOOLEAN jjTYPEOF(leftv res, leftv v)
5024 {
5025  int t=(int)(long)v->data;
5026  switch (t)
5027  {
5028  case CRING_CMD:
5029  case INT_CMD:
5030  case POLY_CMD:
5031  case VECTOR_CMD:
5032  case STRING_CMD:
5033  case INTVEC_CMD:
5034  case IDEAL_CMD:
5035  case MATRIX_CMD:
5036  case MODUL_CMD:
5037  case MAP_CMD:
5038  case PROC_CMD:
5039  case RING_CMD:
5040  //case QRING_CMD:
5041  case INTMAT_CMD:
5042  case BIGINTMAT_CMD:
5043  case NUMBER_CMD:
5044  #ifdef SINGULAR_4_2
5045  case CNUMBER_CMD:
5046  #endif
5047  case BIGINT_CMD:
5048  case LIST_CMD:
5049  case PACKAGE_CMD:
5050  case LINK_CMD:
5051  case RESOLUTION_CMD:
5052  res->data=omStrDup(Tok2Cmdname(t)); break;
5053  case DEF_CMD:
5054  case NONE: res->data=omStrDup("none"); break;
5055  default:
5056  {
5057  if (t>MAX_TOK)
5058  res->data=omStrDup(getBlackboxName(t));
5059  else
5060  res->data=omStrDup("?unknown type?");
5061  break;
5062  }
5063  }
5064  return FALSE;
5065 }
5067 {
5068  res->data=(char *)(long)pIsUnivariate((poly)v->Data());
5069  return FALSE;
5070 }
5071 static BOOLEAN jjVAR1(leftv res, leftv v)
5072 {
5073  int i=(int)(long)v->Data();
5074  if ((0<i) && (i<=currRing->N))
5075  {
5076  poly p=pOne();
5077  pSetExp(p,i,1);
5078  pSetm(p);
5079  res->data=(char *)p;
5080  }
5081  else
5082  {
5083  Werror("var number %d out of range 1..%d",i,currRing->N);
5084  return TRUE;
5085  }
5086  return FALSE;
5087 }
5089 {
5090  if (currRing==NULL)
5091  {
5092  WerrorS("no ring active");
5093  return TRUE;
5094  }
5095  int i=(int)(long)v->Data();
5096  if ((0<i) && (i<=currRing->N))
5097  res->data=omStrDup(currRing->names[i-1]);
5098  else
5099  {
5100  Werror("var number %d out of range 1..%d",i,currRing->N);
5101  return TRUE;
5102  }
5103  return FALSE;
5104 }
5105 static BOOLEAN jjVDIM(leftv res, leftv v)
5106 {
5107  assumeStdFlag(v);
5108  res->data = (char *)(long)scMult0Int((ideal)v->Data(),currRing->qideal);
5109  return FALSE;
5110 }
5112 {
5113 // input: u: a list with links of type
5114 // ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch
5115 // returns: -1: the read state of all links is eof
5116 // i>0: (at least) u[i] is ready
5117  lists Lforks = (lists)u->Data();
5118  int i = slStatusSsiL(Lforks, -1);
5119  if(i == -2) /* error */
5120  {
5121  return TRUE;
5122  }
5123  res->data = (void*)(long)i;
5124  return FALSE;
5125 }
5127 {
5128 // input: u: a list with links of type
5129 // ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch
5130 // returns: -1: the read state of all links is eof
5131 // 1: all links are ready
5132 // (caution: at least one is ready, but some maybe dead)
5133  lists Lforks = (lists)u->CopyD();
5134  int i;
5135  int j = -1;
5136  for(int nfinished = 0; nfinished < Lforks->nr+1; nfinished++)
5137  {
5138  i = slStatusSsiL(Lforks, -1);
5139  if(i == -2) /* error */
5140  {
5141  return TRUE;
5142  }
5143  if(i == -1)
5144  {
5145  break;
5146  }
5147  j = 1;
5148  Lforks->m[i-1].CleanUp();
5149  Lforks->m[i-1].rtyp=DEF_CMD;
5150  Lforks->m[i-1].data=NULL;
5151  }
5152  res->data = (void*)(long)j;
5153  Lforks->Clean();
5154  return FALSE;
5155 }
5156 
5157 BOOLEAN jjLOAD(const char *s, BOOLEAN autoexport)
5158 {
5159  char libnamebuf[1024];
5160  lib_types LT = type_of_LIB(s, libnamebuf);
5161 
5162 #ifdef HAVE_DYNAMIC_LOADING
5163  extern BOOLEAN load_modules(const char *newlib, char *fullpath, BOOLEAN autoexport);
5164 #endif /* HAVE_DYNAMIC_LOADING */
5165  switch(LT)
5166  {
5167  default:
5168  case LT_NONE:
5169  Werror("%s: unknown type", s);
5170  break;
5171  case LT_NOTFOUND:
5172  Werror("cannot open %s", s);
5173  break;
5174 
5175  case LT_SINGULAR:
5176  {
5177  char *plib = iiConvName(s);
5178  idhdl pl = IDROOT->get(plib,0);
5179  if (pl==NULL)
5180  {
5181  pl = enterid( plib,0, PACKAGE_CMD, &(basePack->idroot), TRUE );
5182  IDPACKAGE(pl)->language = LANG_SINGULAR;
5183  IDPACKAGE(pl)->libname=plib;
5184  }
5185  else if (IDTYP(pl)!=PACKAGE_CMD)
5186  {
5187  Werror("can not create package `%s`",plib);
5188  omFree(plib);
5189  return TRUE;
5190  }
5191  else
5192  omFree(plib);
5193  package savepack=currPack;
5194  currPack=IDPACKAGE(pl);
5195  IDPACKAGE(pl)->loaded=TRUE;
5196  char libnamebuf[1024];
5197  FILE * fp = feFopen( s, "r", libnamebuf, TRUE );
5198  BOOLEAN bo=iiLoadLIB(fp, libnamebuf, s, pl, autoexport, TRUE);
5199  currPack=savepack;
5200  IDPACKAGE(pl)->loaded=(!bo);
5201  return bo;
5202  }
5203  case LT_BUILTIN:
5204  SModulFunc_t iiGetBuiltinModInit(const char*);
5205  return load_builtin(s,autoexport, iiGetBuiltinModInit(s));
5206  case LT_MACH_O:
5207  case LT_ELF:
5208  case LT_HPUX:
5209 #ifdef HAVE_DYNAMIC_LOADING
5210  return load_modules(s, libnamebuf, autoexport);
5211 #else /* HAVE_DYNAMIC_LOADING */
5212  WerrorS("Dynamic modules are not supported by this version of Singular");
5213  break;
5214 #endif /* HAVE_DYNAMIC_LOADING */
5215  }
5216  return TRUE;
5217 }
5218 static int WerrorS_dummy_cnt=0;
5219 static void WerrorS_dummy(const char *)
5220 {
5221  WerrorS_dummy_cnt++;
5222 }
5223 BOOLEAN jjLOAD_TRY(const char *s)
5224 {
5225  void (*WerrorS_save)(const char *s) = WerrorS_callback;
5227  WerrorS_dummy_cnt=0;
5228  BOOLEAN bo=jjLOAD(s,TRUE);
5229  if (TEST_OPT_PROT && (bo || (WerrorS_dummy_cnt>0)))
5230  Print("loading of >%s< failed\n",s);
5231  WerrorS_callback=WerrorS_save;
5232  errorreported=0;
5233  return FALSE;
5234 }
5235 
5236 static BOOLEAN jjstrlen(leftv res, leftv v)
5237 {
5238  res->data = (char *)strlen((char *)v->Data());
5239  return FALSE;
5240 }
5242 {
5243  res->data = (char *)(long)pLength((poly)v->Data());
5244  return FALSE;
5245 }
5246 static BOOLEAN jjidElem(leftv res, leftv v)
5247 {
5248  res->data = (char *)(long)idElem((ideal)v->Data());
5249  return FALSE;
5250 }
5252 {
5253  res->data = (char *)id_FreeModule((int)(long)v->Data(), currRing);
5254  return FALSE;
5255 }
5257 {
5258  res->data = (char *)id_Vec2Ideal((poly)v->Data(), currRing);
5259  return FALSE;
5260 }
5262 {
5263  res->data = rCharStr((ring)v->Data());
5264  return FALSE;
5265 }
5266 static BOOLEAN jjpHead(leftv res, leftv v)
5267 {
5268  res->data = (char *)pHead((poly)v->Data());
5269  return FALSE;
5270 }
5271 static BOOLEAN jjidHead(leftv res, leftv v)
5272 {
5273  res->data = (char *)id_Head((ideal)v->Data(),currRing);
5274  setFlag(res,FLAG_STD);
5275  return FALSE;
5276 }
5278 {
5279  res->data = (char *)idMinBase((ideal)v->Data());
5280  return FALSE;
5281 }
5282 #if 0 // unused
5283 static BOOLEAN jjsyMinBase(leftv res, leftv v)
5284 {
5285  res->data = (char *)syMinBase((ideal)v->Data());
5286  return FALSE;
5287 }
5288 #endif
5290 {
5291  res->data = (char *)pMaxComp((poly)v->Data());
5292  return FALSE;
5293 }
5295 {
5296  res->data = (char *)mp_Trace((matrix)v->Data(),currRing);
5297  return FALSE;
5298 }
5300 {
5301  res->data = (char *)mp_Transp((matrix)v->Data(),currRing);
5302  return FALSE;
5303 }
5305 {
5306  res->data = rOrdStr((ring)v->Data());
5307  return FALSE;
5308 }
5310 {
5311  res->data = rVarStr((ring)v->Data());
5312  return FALSE;
5313 }
5315 {
5316  res->data = rParStr((ring)v->Data());
5317  return FALSE;
5318 }
5320 {
5321  res->data=(char *)(long)sySize((syStrategy)v->Data());
5322  return FALSE;
5323 }
5324 static BOOLEAN jjDIM_R(leftv res, leftv v)
5325 {
5326  res->data = (char *)(long)syDim((syStrategy)v->Data());
5327  return FALSE;
5328 }
5330 {
5331  res->data = (char *)id_Transp((ideal)v->Data(),currRing);
5332  return FALSE;
5333 }
5334 static BOOLEAN jjnInt(leftv res, leftv u)
5335 {
5336  number n=(number)u->CopyD(); // n_Int may call n_Normalize
5337  res->data=(char *)(long)iin_Int(n,currRing->cf);
5338  n_Delete(&n,currRing->cf);
5339  return FALSE;
5340 }
5341 static BOOLEAN jjnlInt(leftv res, leftv u)
5342 {
5343  number n=(number)u->Data();
5344  res->data=(char *)(long)iin_Int(n,coeffs_BIGINT );
5345  return FALSE;
5346 }
5347 /*=================== operations with 3 args.: static proc =================*/
5348 /* must be ordered: first operations for chars (infix ops),
5349  * then alphabetically */
5351 {
5352  char *s= (char *)u->Data();
5353  int r = (int)(long)v->Data();
5354  int c = (int)(long)w->Data();
5355  int l = strlen(s);
5356 
5357  if ( (r<1) || (r>l) || (c<0) )
5358  {
5359  Werror("wrong range[%d,%d] in string %s",r,c,u->Fullname());
5360  return TRUE;
5361  }
5362  res->data = (char *)omAlloc((long)(c+1));
5363  sprintf((char *)res->data,"%-*.*s",c,c,s+r-1);
5364  return FALSE;
5365 }
5367 {
5368  intvec *iv = (intvec *)u->Data();
5369  int r = (int)(long)v->Data();
5370  int c = (int)(long)w->Data();
5371  if ((r<1)||(r>iv->rows())||(c<1)||(c>iv->cols()))
5372  {
5373  Werror("wrong range[%d,%d] in intmat %s(%d x %d)",
5374  r,c,u->Fullname(),iv->rows(),iv->cols());
5375  return TRUE;
5376  }
5377  res->data=u->data; u->data=NULL;
5378  res->rtyp=u->rtyp; u->rtyp=0;
5379  res->name=u->name; u->name=NULL;
5380  Subexpr e=jjMakeSub(v);
5381  e->next=jjMakeSub(w);
5382  if (u->e==NULL) res->e=e;
5383  else
5384  {
5385  Subexpr h=u->e;
5386  while (h->next!=NULL) h=h->next;
5387  h->next=e;
5388  res->e=u->e;
5389  u->e=NULL;
5390  }
5391  return FALSE;
5392 }
5394 {
5395  bigintmat *bim = (bigintmat *)u->Data();
5396  int r = (int)(long)v->Data();
5397  int c = (int)(long)w->Data();
5398  if ((r<1)||(r>bim->rows())||(c<1)||(c>bim->cols()))
5399  {
5400  Werror("wrong range[%d,%d] in bigintmat %s(%d x %d)",
5401  r,c,u->Fullname(),bim->rows(),bim->cols());
5402  return TRUE;
5403  }
5404  res->data=u->data; u->data=NULL;
5405  res->rtyp=u->rtyp; u->rtyp=0;
5406  res->name=u->name; u->name=NULL;
5407  Subexpr e=jjMakeSub(v);
5408  e->next=jjMakeSub(w);
5409  if (u->e==NULL)
5410  res->e=e;
5411  else
5412  {
5413  Subexpr h=u->e;
5414  while (h->next!=NULL) h=h->next;
5415  h->next=e;
5416  res->e=u->e;
5417  u->e=NULL;
5418  }
5419  return FALSE;
5420 }
5422 {
5423  matrix m= (matrix)u->Data();
5424  int r = (int)(long)v->Data();
5425  int c = (int)(long)w->Data();
5426  //Print("gen. elem %d, %d\n",r,c);
5427  if ((r<1)||(r>MATROWS(m))||(c<1)||(c>MATCOLS(m)))
5428  {
5429  Werror("wrong range[%d,%d] in matrix %s(%d x %d)",r,c,u->Fullname(),
5430  MATROWS(m),MATCOLS(m));
5431  return TRUE;
5432  }
5433  res->data=u->data; u->data=NULL;
5434  res->rtyp=u->rtyp; u->rtyp=0;
5435  res->name=u->name; u->name=NULL;
5436  Subexpr e=jjMakeSub(v);
5437  e->next=jjMakeSub(w);
5438  if (u->e==NULL)
5439  res->e=e;
5440  else
5441  {
5442  Subexpr h=u->e;
5443  while (h->next!=NULL) h=h->next;
5444  h->next=e;
5445  res->e=u->e;
5446  u->e=NULL;
5447  }
5448  return FALSE;
5449 }
5451 {
5452  sleftv t;
5453  sleftv ut;
5454  leftv p=NULL;
5455  intvec *iv=(intvec *)w->Data();
5456  int l;
5457  BOOLEAN nok;
5458 
5459  if ((u->rtyp!=IDHDL)||(u->e!=NULL))
5460  {
5461  WerrorS("cannot build expression lists from unnamed objects");
5462  return TRUE;
5463  }
5464  memcpy(&ut,u,sizeof(ut));
5465  memset(&t,0,sizeof(t));
5466  t.rtyp=INT_CMD;
5467  for (l=0;l< iv->length(); l++)
5468  {
5469  t.data=(char *)(long)((*iv)[l]);
5470  if (p==NULL)
5471  {
5472  p=res;
5473  }
5474  else
5475  {
5477  p=p->next;
5478  }
5479  memcpy(u,&ut,sizeof(ut));
5480  if (u->Typ() == MATRIX_CMD)
5481  nok=jjBRACK_Ma(p,u,v,&t);
5482  else if (u->Typ() == BIGINTMAT_CMD)
5483  nok=jjBRACK_Bim(p,u,v,&t);
5484  else /* INTMAT_CMD */
5485  nok=jjBRACK_Im(p,u,v,&t);
5486  if (nok)
5487  {
5488  while (res->next!=NULL)
5489  {
5490  p=res->next->next;
5491  omFreeBin((ADDRESS)res->next, sleftv_bin);
5492  // res->e aufraeumen !!!!
5493  res->next=p;
5494  }
5495  return TRUE;
5496  }
5497  }
5498  return FALSE;
5499 }
5501 {
5502  sleftv t;
5503  sleftv ut;
5504  leftv p=NULL;
5505  intvec *iv=(intvec *)v->Data();
5506  int l;
5507  BOOLEAN nok;
5508 
5509  if ((u->rtyp!=IDHDL)||(u->e!=NULL))
5510  {
5511  WerrorS("cannot build expression lists from unnamed objects");
5512  return TRUE;
5513  }
5514  memcpy(&ut,u,sizeof(ut));
5515  memset(&t,0,sizeof(t));
5516  t.rtyp=INT_CMD;
5517  for (l=0;l< iv->length(); l++)
5518  {
5519  t.data=(char *)(long)((*iv)[l]);
5520  if (p==NULL)
5521  {
5522  p=res;
5523  }
5524  else
5525  {
5527  p=p->next;
5528  }
5529  memcpy(u,&ut,sizeof(ut));
5530  if (u->Typ() == MATRIX_CMD)
5531  nok=jjBRACK_Ma(p,u,&t,w);
5532  else if (u->Typ() == BIGINTMAT_CMD)
5533  nok=jjBRACK_Bim(p,u,&t,w);
5534  else /* INTMAT_CMD */
5535  nok=jjBRACK_Im(p,u,&t,w);
5536  if (nok)
5537  {
5538  while (res->next!=NULL)
5539  {
5540  p=res->next->next;
5541  omFreeBin((ADDRESS)res->next, sleftv_bin);
5542  // res->e aufraeumen !!
5543  res->next=p;
5544  }
5545  return TRUE;
5546  }
5547  }
5548  return FALSE;
5549 }
5551 {
5552  sleftv t1,t2,ut;
5553  leftv p=NULL;
5554  intvec *vv=(intvec *)v->Data();
5555  intvec *wv=(intvec *)w->Data();
5556  int vl;
5557  int wl;
5558  BOOLEAN nok;
5559 
5560  if ((u->rtyp!=IDHDL)||(u->e!=NULL))
5561  {
5562  WerrorS("cannot build expression lists from unnamed objects");
5563  return TRUE;
5564  }
5565  memcpy(&ut,u,sizeof(ut));
5566  memset(&t1,0,sizeof(sleftv));
5567  memset(&t2,0,sizeof(sleftv));
5568  t1.rtyp=INT_CMD;
5569  t2.rtyp=INT_CMD;
5570  for (vl=0;vl< vv->length(); vl++)
5571  {
5572  t1.data=(char *)(long)((*vv)[vl]);
5573  for (wl=0;wl< wv->length(); wl++)
5574  {
5575  t2.data=(char *)(long)((*wv)[wl]);
5576  if (p==NULL)
5577  {
5578  p=res;
5579  }
5580  else
5581  {
5583  p=p->next;
5584  }
5585  memcpy(u,&ut,sizeof(ut));
5586  if (u->Typ() == MATRIX_CMD)
5587  nok=jjBRACK_Ma(p,u,&t1,&t2);
5588  else if (u->Typ() == BIGINTMAT_CMD)
5589  nok=jjBRACK_Bim(p,u,&t1,&t2);
5590  else /* INTMAT_CMD */
5591  nok=jjBRACK_Im(p,u,&t1,&t2);
5592  if (nok)
5593  {
5594  res->CleanUp();
5595  return TRUE;
5596  }
5597  }
5598  }
5599  return FALSE;
5600 }
5601 static BOOLEAN jjPROC3(leftv res, leftv u, leftv v, leftv w)
5602 {
5604  memcpy(v->next,w,sizeof(sleftv));
5605  memset(w,0,sizeof(sleftv));
5606  return jjPROC(res,u,v);
5607 }
5608 static BOOLEAN jjRING_2(leftv res, leftv u, leftv v, leftv w)
5609 {
5610  u->next=(leftv)omAlloc(sizeof(sleftv));
5611  memcpy(u->next,v,sizeof(sleftv));
5612  memset(v,0,sizeof(sleftv));
5613  u->next->next=(leftv)omAlloc(sizeof(sleftv));
5614  memcpy(u->next->next,w,sizeof(sleftv));
5615  memset(w,0,sizeof(sleftv));
5616  BOOLEAN bo=iiExprArithM(res,u,'[');
5617  u->next=NULL;
5618  return bo;
5619 }
5620 static BOOLEAN jjBAREISS3(leftv res, leftv u, leftv v, leftv w)
5621 {
5622  intvec *iv;
5623  ideal m;
5625  int k=(int)(long)w->Data();
5626  if (k>=0)
5627  {
5628  sm_CallBareiss((ideal)u->Data(),(int)(long)v->Data(),(int)(long)w->Data(),m,&iv, currRing);
5629  l->Init(2);
5630  l->m[0].rtyp=MODUL_CMD;
5631  l->m[1].rtyp=INTVEC_CMD;
5632  l->m[0].data=(void *)m;
5633  l->m[1].data=(void *)iv;
5634  }
5635  else
5636  {
5637  m=sm_CallSolv((ideal)u->Data(), currRing);
5638  l->Init(1);
5639  l->m[0].rtyp=IDEAL_CMD;
5640  l->m[0].data=(void *)m;
5641  }
5642  res->data = (char *)l;
5643  return FALSE;
5644 }
5646 {
5647  if ((w->rtyp!=IDHDL)||(w->e!=NULL))
5648  {
5649  WerrorS("3rd argument must be a name of a matrix");
5650  return TRUE;
5651  }
5652  ideal i=(ideal)u->Data();
5653  int rank=(int)i->rank;
5654  BOOLEAN r=jjCOEFFS_Id(res,u,v);
5655  if (r) return TRUE;
5656  mp_Monomials((matrix)res->data, rank, pVar((poly)v->Data()),(matrix)w->Data(),currRing);
5657  return FALSE;
5658 }
5660 {
5661  res->data=(void*)idCoeffOfKBase((ideal)(u->Data()),
5662  (ideal)(v->Data()),(poly)(w->Data()));
5663  return FALSE;
5664 }
5666 {
5667  if ((w->rtyp!=IDHDL)||(w->e!=NULL))
5668  {
5669  WerrorS("3rd argument must be a name of a matrix");
5670  return TRUE;
5671  }
5672  // CopyD for POLY_CMD and VECTOR_CMD are identical:
5673  poly p=(poly)u->CopyD(POLY_CMD);
5674  ideal i=idInit(1,1);
5675  i->m[0]=p;
5676  sleftv t;
5677  memset(&t,0,sizeof(t));
5678  t.data=(char *)i;
5679  t.rtyp=IDEAL_CMD;
5680  int rank=1;
5681  if (u->Typ()==VECTOR_CMD)
5682  {
5683  i->rank=rank=pMaxComp(p);
5684  t.rtyp=MODUL_CMD;
5685  }
5686  BOOLEAN r=jjCOEFFS_Id(res,&t,v);
5687  t.CleanUp();
5688  if (r) return TRUE;
5689  mp_Monomials((matrix)res->data, rank, pVar((poly)v->Data()),(matrix)w->Data(),currRing);
5690  return FALSE;
5691 }
5693 {
5694  res->data=(char *)idElimination((ideal)u->Data(),(poly)v->Data(),
5695  (intvec *)w->Data());
5696  //setFlag(res,FLAG_STD);
5697  return FALSE;
5698 }
5699 static BOOLEAN jjFIND3(leftv res, leftv u, leftv v, leftv w)
5700 {
5701  /*4
5702  * look for the substring what in the string where
5703  * starting at position n
5704  * return the position of the first char of what in where
5705  * or 0
5706  */
5707  int n=(int)(long)w->Data();
5708  char *where=(char *)u->Data();
5709  char *what=(char *)v->Data();
5710  char *found;
5711  if ((1>n)||(n>(int)strlen(where)))
5712  {
5713  Werror("start position %d out of range",n);
5714  return TRUE;
5715  }
5716  found = strchr(where+n-1,*what);
5717  if (*(what+1)!='\0')
5718  {
5719  while((found !=NULL) && (strncmp(found+1,what+1,strlen(what+1))!=0))
5720  {
5721  found=strchr(found+1,*what);
5722  }
5723  }
5724  if (found != NULL)
5725  {
5726  res->data=(char *)((found-where)+1);
5727  }
5728  return FALSE;
5729 }
5730 static BOOLEAN jjFWALK3(leftv res, leftv u, leftv v, leftv w)
5731 {
5732  if ((int)(long)w->Data()==0)
5733  res->data=(char *)walkProc(u,v);
5734  else
5735  res->data=(char *)fractalWalkProc(u,v);
5736  setFlag( res, FLAG_STD );
5737  return FALSE;
5738 }
5739 static BOOLEAN jjHILBERT3(leftv res, leftv u, leftv v, leftv w)
5740 {
5741  intvec *wdegree=(intvec*)w->Data();
5742  if (wdegree->length()!=currRing->N)
5743  {
5744  Werror("weight vector must have size %d, not %d",
5745  currRing->N,wdegree->length());
5746  return TRUE;
5747  }
5748 #ifdef HAVE_RINGS
5750  {
5751  PrintS("// NOTE: computation of Hilbert series etc. is being\n");
5752  PrintS("// performed for generic fibre, that is, over Q\n");
5753  }
5754 #endif
5755  assumeStdFlag(u);
5756  intvec *module_w=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
5757  intvec *iv=hFirstSeries((ideal)u->Data(),module_w,currRing->qideal,wdegree);
5758  switch((int)(long)v->Data())
5759  {
5760  case 1:
5761  res->data=(void *)iv;
5762  return FALSE;
5763  case 2:
5764  res->data=(void *)hSecondSeries(iv);
5765  delete iv;
5766  return FALSE;
5767  }
5768  delete iv;
5770  return TRUE;
5771 }
5772 static BOOLEAN jjHOMOG_ID_W(leftv res, leftv u, leftv v, leftv /*w*/)
5773 {
5774  PrintS("TODO\n");
5775  int i=pVar((poly)v->Data());
5776  if (i==0)
5777  {
5778  WerrorS("ringvar expected");
5779  return TRUE;
5780  }
5781  poly p=pOne(); pSetExp(p,i,1); pSetm(p);
5782  int d=pWTotaldegree(p);
5783  pLmDelete(p);
5784  if (d==1)
5785  res->data = (char *)id_Homogen((ideal)u->Data(), i, currRing);
5786  else
5787  WerrorS("variable must have weight 1");
5788  return (d!=1);
5789 }
5790 static BOOLEAN jjHOMOG_P_W(leftv res, leftv u, leftv v,leftv /*w*/)
5791 {
5792  PrintS("TODO\n");
5793  int i=pVar((poly)v->Data());
5794  if (i==0)
5795  {
5796  WerrorS("ringvar expected");
5797  return TRUE;
5798  }
5799  poly p=pOne(); pSetExp(p,i,1); pSetm(p);
5800  int d=pWTotaldegree(p);
5801  pLmDelete(p);
5802  if (d==1)
5803  res->data = (char *)p_Homogen((poly)u->Data(), i, currRing);
5804  else
5805  WerrorS("variable must have weight 1");
5806  return (d!=1);
5807 }
5809 {
5810  intvec* im= new intvec((int)(long)v->Data(),(int)(long)w->Data(), 0);
5811  intvec* arg = (intvec*) u->Data();
5812  int i, n = si_min(im->cols()*im->rows(), arg->cols()*arg->rows());
5813 
5814  for (i=0; i<n; i++)
5815  {
5816  (*im)[i] = (*arg)[i];
5817  }
5818 
5819  res->data = (char *)im;
5820  return FALSE;
5821 }
5822 static BOOLEAN jjJET_P_IV(leftv res, leftv u, leftv v, leftv w)
5823 {
5824  short *iw=iv2array((intvec *)w->Data(),currRing);
5825  res->data = (char *)ppJetW((poly)u->Data(),(int)(long)v->Data(),iw);
5826  omFreeSize( (ADDRESS)iw, (rVar(currRing)+1)*sizeof(short) );
5827  return FALSE;
5828 }
5829 static BOOLEAN jjJET_P_P(leftv res, leftv u, leftv v, leftv w)
5830 {
5831  if (!pIsUnit((poly)v->Data()))
5832  {
5833  WerrorS("2nd argument must be a unit");
5834  return TRUE;
5835  }
5836  res->data = (char *)p_Series((int)(long)w->Data(),(poly)u->CopyD(),(poly)v->CopyD(),NULL,currRing);
5837  return FALSE;
5838 }
5840 {
5841  res->data = (char *)id_JetW((ideal)u->Data(),(int)(long)v->Data(),
5842  (intvec *)w->Data(),currRing);
5843  return FALSE;
5844 }
5845 static BOOLEAN jjJET_ID_M(leftv res, leftv u, leftv v, leftv w)
5846 {
5847  if (!mp_IsDiagUnit((matrix)v->Data(), currRing))
5848  {
5849  WerrorS("2nd argument must be a diagonal matrix of units");
5850  return TRUE;
5851  }
5852  res->data = (char *)idSeries((int)(long)w->Data(),(ideal)u->CopyD(),
5853  (matrix)v->CopyD());
5854  return FALSE;
5855 }
5857 {
5858  /* Here's the use pattern for the minor command:
5859  minor ( matrix_expression m, int_expression minorSize,
5860  optional ideal_expression IasSB, optional int_expression k,
5861  optional string_expression algorithm,
5862  optional int_expression cachedMinors,
5863  optional int_expression cachedMonomials )
5864  This method here assumes that there are at least two arguments.
5865  - If IasSB is present, it must be a std basis. All minors will be
5866  reduced w.r.t. IasSB.
5867  - If k is absent, all non-zero minors will be computed.
5868  If k is present and k > 0, the first k non-zero minors will be
5869  computed.
5870  If k is present and k < 0, the first |k| minors (some of which
5871  may be zero) will be computed.
5872  If k is present and k = 0, an error is reported.
5873  - If algorithm is absent, all the following arguments must be absent too.
5874  In this case, a heuristic picks the best-suited algorithm (among
5875  Bareiss, Laplace, and Laplace with caching).
5876  If algorithm is present, it must be one of "Bareiss", "bareiss",
5877  "Laplace", "laplace", "Cache", "cache". In the cases "Cache" and
5878  "cache" two more arguments may be given, determining how many entries
5879  the cache may have at most, and how many cached monomials there are at
5880  most. (Cached monomials are counted over all cached polynomials.)
5881  If these two additional arguments are not provided, 200 and 100000
5882  will be used as defaults.
5883  */
5884  matrix m;
5885  leftv u=v->next;
5886  v->next=NULL;
5887  int v_typ=v->Typ();
5888  if (v_typ==MATRIX_CMD)
5889  {
5890  m = (const matrix)v->Data();
5891  }
5892  else
5893  {
5894  if (v_typ==0)
5895  {
5896  Werror("`%s` is undefined",v->Fullname());
5897  return TRUE;
5898  }
5899  // try to convert to MATRIX:
5900  int ii=iiTestConvert(v_typ,MATRIX_CMD);
5901  BOOLEAN bo;
5902  sleftv tmp;
5903  if (ii>0) bo=iiConvert(v_typ,MATRIX_CMD,ii,v,&tmp);
5904  else bo=TRUE;
5905  if (bo)
5906  {
5907  Werror("cannot convert %s to matrix",Tok2Cmdname(v_typ));
5908  return TRUE;
5909  }
5910  m=(matrix)tmp.data;
5911  }
5912  const int mk = (const int)(long)u->Data();
5913  bool noIdeal = true; bool noK = true; bool noAlgorithm = true;
5914  bool noCacheMinors = true; bool noCacheMonomials = true;
5915  ideal IasSB; int k; char* algorithm; int cacheMinors; int cacheMonomials;
5916 
5917  /* here come the different cases of correct argument sets */
5918  if ((u->next != NULL) && (u->next->Typ() == IDEAL_CMD))
5919  {
5920  IasSB = (ideal)u->next->Data();
5921  noIdeal = false;
5922  if ((u->next->next != NULL) && (u->next->next->Typ() == INT_CMD))
5923  {
5924  k = (int)(long)u->next->next->Data();
5925  noK = false;
5926  assume(k != 0);
5927  if ((u->next->next->next != NULL) &&
5928  (u->next->next->next->Typ() == STRING_CMD))
5929  {
5930  algorithm = (char*)u->next->next->next->Data();
5931  noAlgorithm = false;
5932  if ((u->next->next->next->next != NULL) &&
5933  (u->next->next->next->next->Typ() == INT_CMD))
5934  {
5935  cacheMinors = (int)(long)u->next->next->next->next->Data();
5936  noCacheMinors = false;
5937  if ((u->next->next->next->next->next != NULL) &&
5938  (u->next->next->next->next->next->Typ() == INT_CMD))
5939  {
5940  cacheMonomials =
5941  (int)(long)u->next->next->next->next->next->Data();
5942  noCacheMonomials = false;
5943  }
5944  }
5945  }
5946  }
5947  }
5948  else if ((u->next != NULL) && (u->next->Typ() == INT_CMD))
5949  {
5950  k = (int)(long)u->next->Data();
5951  noK = false;
5952  assume(k != 0);
5953  if ((u->next->next != NULL) && (u->next->next->Typ() == STRING_CMD))
5954  {
5955  algorithm = (char*)u->next->next->Data();
5956  noAlgorithm = false;
5957  if ((u->next->next->next != NULL) &&
5958  (u->next->next->next->Typ() == INT_CMD))
5959  {
5960  cacheMinors = (int)(long)u->next->next->next->Data();
5961  noCacheMinors = false;
5962  if ((u->next->next->next->next != NULL) &&
5963  (u->next->next->next->next->Typ() == INT_CMD))
5964  {
5965  cacheMonomials = (int)(long)u->next->next->next->next->Data();
5966  noCacheMonomials = false;
5967  }
5968  }
5969  }
5970  }
5971  else if ((u->next != NULL) && (u->next->Typ() == STRING_CMD))
5972  {
5973  algorithm = (char*)u->next->Data();
5974  noAlgorithm = false;
5975  if ((u->next->next != NULL) && (u->next->next->Typ() == INT_CMD))
5976  {
5977  cacheMinors = (int)(long)u->next->next->Data();
5978  noCacheMinors = false;
5979  if ((u->next->next->next != NULL) &&
5980  (u->next->next->next->Typ() == INT_CMD))
5981  {
5982  cacheMonomials = (int)(long)u->next->next->next->Data();
5983  noCacheMonomials = false;
5984  }
5985  }
5986  }
5987 
5988  /* upper case conversion for the algorithm if present */
5989  if (!noAlgorithm)
5990  {
5991  if (strcmp(algorithm, "bareiss") == 0)
5992  algorithm = (char*)"Bareiss";
5993  if (strcmp(algorithm, "laplace") == 0)
5994  algorithm = (char*)"Laplace";
5995  if (strcmp(algorithm, "cache") == 0)
5996  algorithm = (char*)"Cache";
5997  }
5998 
5999  v->next=u;
6000  /* here come some tests */
6001  if (!noIdeal)
6002  {
6003  assumeStdFlag(u->next);
6004  }
6005  if ((!noK) && (k == 0))
6006  {
6007  WerrorS("Provided number of minors to be computed is zero.");
6008  return TRUE;
6009  }
6010  if ((!noAlgorithm) && (strcmp(algorithm, "Bareiss") != 0)
6011  && (strcmp(algorithm, "Laplace") != 0)
6012  && (strcmp(algorithm, "Cache") != 0))
6013  {
6014  WerrorS("Expected as algorithm one of 'B/bareiss', 'L/laplace', or 'C/cache'.");
6015  return TRUE;
6016  }
6017  if ((!noAlgorithm) && (strcmp(algorithm, "Bareiss") == 0)
6018  && (!rField_is_Domain(currRing)))
6019  {
6020  Werror("Bareiss algorithm not defined over coefficient rings %s",
6021  "with zero divisors.");
6022  return TRUE;
6023  }
6024  res->rtyp=IDEAL_CMD;
6025  if ((mk < 1) || (mk > m->rows()) || (mk > m->cols()))
6026  {
6027  ideal I=idInit(1,1);
6028  if (mk<1) I->m[0]=p_One(currRing);
6029  //Werror("invalid size of minors: %d (matrix is (%d x %d))", mk,
6030  // m->rows(), m->cols());
6031  res->data=(void*)I;
6032  return FALSE;
6033  }
6034  if ((!noAlgorithm) && (strcmp(algorithm, "Cache") == 0)
6035  && (noCacheMinors || noCacheMonomials))
6036  {
6037  cacheMinors = 200;
6038  cacheMonomials = 100000;
6039  }
6040 
6041  /* here come the actual procedure calls */
6042  if (noAlgorithm)
6043  res->data = getMinorIdealHeuristic(m, mk, (noK ? 0 : k),
6044  (noIdeal ? 0 : IasSB), false);
6045  else if (strcmp(algorithm, "Cache") == 0)
6046  res->data = getMinorIdealCache(m, mk, (noK ? 0 : k),
6047  (noIdeal ? 0 : IasSB), 3, cacheMinors,
6048  cacheMonomials, false);
6049  else
6050  res->data = getMinorIdeal(m, mk, (noK ? 0 : k), algorithm,
6051  (noIdeal ? 0 : IasSB), false);
6052  if (v_typ!=MATRIX_CMD) idDelete((ideal *)&m);
6053  return FALSE;
6054 }
6056 {
6057  // u: the name of the new type
6058  // v: the parent type
6059  // w: the elements
6060  newstruct_desc d=newstructChildFromString((const char *)v->Data(),
6061  (const char *)w->Data());
6062  if (d!=NULL) newstruct_setup((const char *)u->Data(),d);
6063  return (d==NULL);
6064 }
6065 static BOOLEAN jjPREIMAGE(leftv res, leftv u, leftv v, leftv w)
6066 {
6067  // handles preimage(r,phi,i) and kernel(r,phi)
6068  idhdl h;
6069  ring rr;
6070  map mapping;
6071  BOOLEAN kernel_cmd= (iiOp==KERNEL_CMD);
6072 
6073  if ((v->name==NULL) || (!kernel_cmd && (w->name==NULL)))
6074  {
6075  WerrorS("2nd/3rd arguments must have names");
6076  return TRUE;
6077  }
6078  rr=(ring)u->Data();
6079  const char *ring_name=u->Name();
6080  if ((h=rr->idroot->get(v->name,myynest))!=NULL)
6081  {
6082  if (h->typ==MAP_CMD)
6083  {
6084  mapping=IDMAP(h);
6085  idhdl preim_ring=IDROOT->get(mapping->preimage,myynest);
6086  if ((preim_ring==NULL)
6087  || (IDRING(preim_ring)!=currRing))
6088  {
6089  Werror("preimage ring `%s` is not the basering",mapping->preimage);
6090  return TRUE;
6091  }
6092  }
6093  else if (h->typ==IDEAL_CMD)
6094  {
6095  mapping=IDMAP(h);
6096  }
6097  else
6098  {
6099  Werror("`%s` is no map nor ideal",IDID(h));
6100  return TRUE;
6101  }
6102  }
6103  else
6104  {
6105  Werror("`%s` is not defined in `%s`",v->name,ring_name);
6106  return TRUE;
6107  }
6108  ideal image;
6109  if (kernel_cmd) image=idInit(1,1);
6110  else
6111  {
6112  if ((h=rr->idroot->get(w->name,myynest))!=NULL)
6113  {
6114  if (h->typ==IDEAL_CMD)
6115  {
6116  image=IDIDEAL(h);
6117  }
6118  else
6119  {
6120  Werror("`%s` is no ideal",IDID(h));
6121  return TRUE;
6122  }
6123  }
6124  else
6125  {
6126  Werror("`%s` is not defined in `%s`",w->name,ring_name);
6127  return TRUE;
6128  }
6129  }
6130  if (((currRing->qideal!=NULL) && (rHasLocalOrMixedOrdering(currRing)))
6131  || ((rr->qideal!=NULL) && (rHasLocalOrMixedOrdering(rr))))
6132  {
6133  WarnS("preimage in local qring may be wrong: use Ring::preimageLoc instead");
6134  }
6135  res->data=(char *)maGetPreimage(rr,mapping,image,currRing);
6136  if (kernel_cmd) idDelete(&image);
6137  return (res->data==NULL/* is of type ideal, should not be NULL*/);
6138 }
6140 {
6141  int di, k;
6142  int i=(int)(long)u->Data();
6143  int r=(int)(long)v->Data();
6144  int c=(int)(long)w->Data();
6145  if ((r<=0) || (c<=0)) return TRUE;
6146  intvec *iv = new intvec(r, c, 0);
6147  if (iv->rows()==0)
6148  {
6149  delete iv;
6150  return TRUE;
6151  }
6152  if (i!=0)
6153  {
6154  if (i<0) i = -i;
6155  di = 2 * i + 1;
6156  for (k=0; k<iv->length(); k++)
6157  {
6158  (*iv)[k] = ((siRand() % di) - i);
6159  }
6160  }
6161  res->data = (char *)iv;
6162  return FALSE;
6163 }
6164 #ifdef SINGULAR_4_2
6165 static BOOLEAN jjRANDOM_CF(leftv res, leftv u, leftv v, leftv w)
6166 // <coeff>, par1, par2 -> number2
6167 {
6168  coeffs cf=(coeffs)u->Data();
6169  if ((cf==NULL) ||(cf->cfRandom==NULL))
6170  {
6171  Werror("no random function defined for coeff %d",cf->type);
6172  return TRUE;
6173  }
6174  else
6175  {
6176  number n= n_Random(siRand,(number)v->Data(),(number)w->Data(),cf);
6177  number2 nn=(number2)omAlloc(sizeof(*nn));
6178  nn->cf=cf;
6179  nn->n=n;
6180  res->data=nn;
6181  return FALSE;
6182  }
6183  return TRUE;
6184 }
6185 #endif
6187  int &ringvar, poly &monomexpr)
6188 {
6189  monomexpr=(poly)w->Data();
6190  poly p=(poly)v->Data();
6191 #if 0
6192  if (pLength(monomexpr)>1)
6193  {
6194  Werror("`%s` substitutes a ringvar only by a term",
6196  return TRUE;
6197  }
6198 #endif
6199  if ((ringvar=pVar(p))==0)
6200  {
6201  if ((p!=NULL) && (currRing->cf->extRing!=NULL))
6202  {
6203  number n = pGetCoeff(p);
6204  ringvar= -n_IsParam(n, currRing);
6205  }
6206  if(ringvar==0)
6207  {
6208  WerrorS("ringvar/par expected");
6209  return TRUE;
6210  }
6211  }
6212  return FALSE;
6213 }
6215 {
6216  int ringvar;
6217  poly monomexpr;
6218  BOOLEAN nok=jjSUBST_Test(v,w,ringvar,monomexpr);
6219  if (nok) return TRUE;
6220  poly p=(poly)u->Data();
6221  if (ringvar>0)
6222  {
6223  if ((monomexpr!=NULL) && (p!=NULL) && (pTotaldegree(p)!=0) &&
6224  ((unsigned long)pTotaldegree(monomexpr) > (currRing->bitmask / (unsigned long)pTotaldegree(p)/2)))
6225  {
6226  Warn("possible OVERFLOW in subst, max exponent is %ld, substituting deg %d by deg %d",currRing->bitmask/2, pTotaldegree(monomexpr), pTotaldegree(p));
6227  //return TRUE;
6228  }
6229  if ((monomexpr==NULL)||(pNext(monomexpr)==NULL))
6230  res->data = pSubst((poly)u->CopyD(res->rtyp),ringvar,monomexpr);
6231  else
6232  res->data= pSubstPoly(p,ringvar,monomexpr);
6233  }
6234  else
6235  {
6236  res->data=pSubstPar(p,-ringvar,monomexpr);
6237  }
6238  return FALSE;
6239 }
6241 {
6242  int ringvar;
6243  poly monomexpr;
6244  BOOLEAN nok=jjSUBST_Test(v,w,ringvar,monomexpr);
6245  if (nok) return TRUE;
6246  ideal id=(ideal)u->Data();
6247  if (ringvar>0)
6248  {
6249  BOOLEAN overflow=FALSE;
6250  if (monomexpr!=NULL)
6251  {
6252  long deg_monexp=pTotaldegree(monomexpr);
6253  for(int i=IDELEMS(id)-1;i>=0;i--)
6254  {
6255  poly p=id->m[i];
6256  if ((p!=NULL) && (pTotaldegree(p)!=0) &&
6257  ((unsigned long)deg_monexp > (currRing->bitmask / (unsigned long)pTotaldegree(p)/2)))
6258  {
6259  overflow=TRUE;
6260  break;
6261  }
6262  }
6263  }
6264  if (overflow)
6265  Warn("possible OVERFLOW in subst, max exponent is %ld",currRing->bitmask/2);
6266  if ((monomexpr==NULL)||(pNext(monomexpr)==NULL))
6267  {
6268  if (res->rtyp==MATRIX_CMD) id=(ideal)mp_Copy((matrix)id,currRing);
6269  else id=id_Copy(id,currRing);
6270  res->data = id_Subst(id, ringvar, monomexpr, currRing);
6271  }
6272  else
6273  res->data = idSubstPoly(id,ringvar,monomexpr);
6274  }
6275  else
6276  {
6277  res->data = idSubstPar(id,-ringvar,monomexpr);
6278  }
6279  return FALSE;
6280 }
6281 // we do not want to have jjSUBST_Id_X inlined:
6282 static BOOLEAN jjSUBST_Id_X(leftv res, leftv u, leftv v,leftv w,
6283  int input_type);
6285 {
6286  return jjSUBST_Id_X(res,u,v,w,INT_CMD);
6287 }
6289 {
6290  return jjSUBST_Id_X(res,u,v,w,NUMBER_CMD);
6291 }
6292 static BOOLEAN jjSUBST_Id_X(leftv res, leftv u, leftv v,leftv w, int input_type)
6293 {
6294  sleftv tmp;
6295  memset(&tmp,0,sizeof(tmp));
6296  // do not check the result, conversion from int/number to poly works always
6297  iiConvert(input_type,POLY_CMD,iiTestConvert(input_type,POLY_CMD),w,&tmp);
6298  BOOLEAN b=jjSUBST_Id(res,u,v,&tmp);
6299  tmp.CleanUp();
6300  return b;
6301 }
6303 {
6304  int mi=(int)(long)v->Data();
6305  int ni=(int)(long)w->Data();
6306  if ((mi<1)||(ni<1))
6307  {
6308  Werror("converting ideal to matrix: dimensions must be positive(%dx%d)",mi,ni);
6309  return TRUE;
6310  }
6311  matrix m=mpNew(mi,ni);
6312  ideal I=(ideal)u->CopyD(IDEAL_CMD);
6313  int i=si_min(IDELEMS(I),mi*ni);
6314  //for(i=i-1;i>=0;i--)
6315  //{
6316  // m->m[i]=I->m[i];
6317  // I->m[i]=NULL;
6318  //}
6319  memcpy(m->m,I->m,i*sizeof(poly));
6320  memset(I->m,0,i*sizeof(poly));
6321  id_Delete(&I,currRing);
6322  res->data = (char *)m;
6323  return FALSE;
6324 }
6326 {
6327  int mi=(int)(long)v->Data();
6328  int ni=(int)(long)w->Data();
6329  if ((mi<1)||(ni<1))
6330  {
6331  Werror("converting module to matrix: dimensions must be positive(%dx%d)",mi,ni);
6332  return TRUE;
6333  }
6334  res->data = (char *)id_Module2formatedMatrix((ideal)u->CopyD(MODUL_CMD),
6335  mi,ni,currRing);
6336  return FALSE;
6337 }
6339 {
6340  int mi=(int)(long)v->Data();
6341  int ni=(int)(long)w->Data();
6342  if ((mi<1)||(ni<1))
6343  {
6344  Werror("converting matrix to matrix: dimensions must be positive(%dx%d)",mi,ni);
6345  return TRUE;
6346  }
6347  matrix m=mpNew(mi,ni);
6348  matrix I=(matrix)u->CopyD(MATRIX_CMD);
6349  int r=si_min(MATROWS(I),mi);
6350  int c=si_min(MATCOLS(I),ni);
6351  int i,j;
6352  for(i=r;i>0;i--)
6353  {
6354  for(j=c;j>0;j--)
6355  {
6356  MATELEM(m,i,j)=MATELEM(I,i,j);
6357  MATELEM(I,i,j)=NULL;
6358  }
6359  }
6360  id_Delete((ideal *)&I,currRing);
6361  res->data = (char *)m;
6362  return FALSE;
6363 }
6364 static BOOLEAN jjLIFT3(leftv res, leftv u, leftv v, leftv w)
6365 {
6366  if (w->rtyp!=IDHDL) return TRUE;
6367  int ul= IDELEMS((ideal)u->Data());
6368  int vl= IDELEMS((ideal)v->Data());
6369  ideal m
6370  = idLift((ideal)u->Data(),(ideal)v->Data(),NULL,FALSE,hasFlag(u,FLAG_STD),
6371  FALSE, (matrix *)(&(IDMATRIX((idhdl)(w->data)))));
6372  if (m==NULL) return TRUE;
6373  res->data = (char *)id_Module2formatedMatrix(m,ul,vl,currRing);
6374  return FALSE;
6375 }
6376 static BOOLEAN jjLIFTSTD3(leftv res, leftv u, leftv v, leftv w)
6377 {
6378  if ((v->rtyp!=IDHDL)||(v->e!=NULL)) return TRUE;
6379  if ((w->rtyp!=IDHDL)||(w->e!=NULL)) return TRUE;
6380  idhdl hv=(idhdl)v->data;
6381  idhdl hw=(idhdl)w->data;
6382  // CopyD for IDEAL_CMD and MODUL_CMD are identical:
6383  res->data = (char *)idLiftStd((ideal)u->Data(),
6384  &(hv->data.umatrix),testHomog,
6385  &(hw->data.uideal));
6386  setFlag(res,FLAG_STD); v->flag=0; w->flag=0;
6387  return FALSE;
6388 }
6390 {
6391  assumeStdFlag(v);
6392  if (!idIsZeroDim((ideal)v->Data()))
6393  {
6394  Werror("`%s` must be 0-dimensional",v->Name());
6395  return TRUE;
6396  }
6397  res->data = (char *)redNF((ideal)v->CopyD(),(poly)u->CopyD(),
6398  (poly)w->CopyD());
6399  return FALSE;
6400 }
6402 {
6403  assumeStdFlag(v);
6404  if (!idIsZeroDim((ideal)v->Data()))
6405  {
6406  Werror("`%s` must be 0-dimensional",v->Name());
6407  return TRUE;
6408  }
6409  res->data = (char *)redNF((ideal)v->CopyD(),(ideal)u->CopyD(),
6410  (matrix)w->CopyD());
6411  return FALSE;
6412 }
6414 {
6415  assumeStdFlag(v);
6416  res->data = (char *)kNF((ideal)v->Data(),currRing->qideal,(poly)u->Data(),
6417  0,(int)(long)w->Data());
6418  return FALSE;
6419 }
6421 {
6422  assumeStdFlag(v);
6423  res->data = (char *)kNF((ideal)v->Data(),currRing->qideal,(ideal)u->Data(),
6424  0,(int)(long)w->Data());
6425  return FALSE;
6426 }
6427 #ifdef OLD_RES
6428 static BOOLEAN jjRES3(leftv res, leftv u, leftv v, leftv w)
6429 {
6430  int maxl=(int)v->Data();
6431  ideal u_id=(ideal)u->Data();
6432  int l=0;
6433  resolvente r;
6434  intvec **weights=NULL;
6435  int wmaxl=maxl;
6436  maxl--;
6437  if ((maxl==-1) && (iiOp!=MRES_CMD))
6438  maxl = currRing->N-1;
6439  if ((iiOp == RES_CMD) || (iiOp == MRES_CMD))
6440  {
6441  intvec * iv=(intvec*)atGet(u,"isHomog",INTVEC_CMD);
6442  if (iv!=NULL)
6443  {
6444  l=1;
6445  if (!idTestHomModule(u_id,currRing->qideal,iv))
6446  {
6447  WarnS("wrong weights");
6448  iv=NULL;
6449  }
6450  else
6451  {
6452  weights = (intvec**)omAlloc0Bin(char_ptr_bin);
6453  weights[0] = ivCopy(iv);
6454  }
6455  }
6456  r=syResolvente(u_id,maxl,&l, &weights, iiOp==MRES_CMD);
6457  }
6458  else
6459  r=sySchreyerResolvente((ideal)u->Data(),maxl+1,&l);
6460  if (r==NULL) return TRUE;
6461  int t3=u->Typ();
6462  iiMakeResolv(r,l,wmaxl,w->name,t3,weights);
6463  return FALSE;
6464 }
6465 #endif
6466 static BOOLEAN jjRING3(leftv res, leftv u, leftv v, leftv w)
6467 {
6468  res->data=(void *)rInit(u,v,w);
6469  return (res->data==NULL);
6470 }
6471 static BOOLEAN jjSTATUS3(leftv res, leftv u, leftv v, leftv w)
6472 {
6473  int yes;
6474  jjSTATUS2(res, u, v);
6475  yes = (strcmp((char *) res->data, (char *) w->Data()) == 0);
6476  omFree((ADDRESS) res->data);
6477  res->data = (void *)(long)yes;
6478  return FALSE;
6479 }
6481 {
6482  intvec *vw=(intvec *)w->Data(); // weights of vars
6483  if (vw->length()!=currRing->N)
6484  {
6485  Werror("%d weights for %d variables",vw->length(),currRing->N);
6486  return TRUE;
6487  }
6488  ideal result;
6489  intvec *ww=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
6490  tHomog hom=testHomog;
6491  ideal u_id=(ideal)(u->Data());
6492  if (ww!=NULL)
6493  {
6494  if (!idTestHomModule(u_id,currRing->qideal,ww))
6495  {
6496  WarnS("wrong weights");
6497  ww=NULL;
6498  }
6499  else
6500  {
6501  ww=ivCopy(ww);
6502  hom=isHomog;
6503  }
6504  }
6505  result=kStd(u_id,
6506  currRing->qideal,
6507  hom,
6508  &ww, // module weights
6509  (intvec *)v->Data(), // hilbert series
6510  0,0, // syzComp, newIdeal
6511  vw); // weights of vars
6512  idSkipZeroes(result);
6513  res->data = (char *)result;
6514  setFlag(res,FLAG_STD);
6515  if (ww!=NULL) atSet(res,omStrDup("isHomog"),ww,INTVEC_CMD);
6516  return FALSE;
6517 }
6518 
6519 /*=================== operations with many arg.: static proc =================*/
6520 /* must be ordered: first operations for chars (infix ops),
6521  * then alphabetically */
6523 {
6524 #ifdef HAVE_SDB
6525  sdb_show_bp();
6526 #endif
6527  return FALSE;
6528 }
6530 {
6531 #ifdef HAVE_SDB
6532  if(v->Typ()==PROC_CMD)
6533  {
6534  int lineno=0;
6535  if((v->next!=NULL) && (v->next->Typ()==INT_CMD))
6536  {
6537  lineno=(int)(long)v->next->Data();
6538  }
6539  return sdb_set_breakpoint(v->Name(),lineno);
6540  }
6541  return TRUE;
6542 #else
6543  return FALSE;
6544 #endif
6545 }
6547 {
6548  return iiExprArith1(res,v,iiOp);
6549 }
6551 {
6552  leftv v=u->next;
6553  u->next=NULL;
6554  BOOLEAN b=iiExprArith2(res,u,iiOp,v, (iiOp > 255));
6555  u->next=v;
6556  return b;
6557 }
6559 {
6560  leftv v = u->next;
6561  leftv w = v->next;
6562  u->next = NULL;
6563  v->next = NULL;
6564  BOOLEAN b = iiExprArith3(res, iiOp, u, v, w);
6565  u->next = v;
6566  v->next = w;
6567  return b;
6568 }
6569 
6571 {
6572  const short t[]={5,VECTOR_CMD,POLY_CMD,MATRIX_CMD,MATRIX_CMD,IDHDL};
6573  if (iiCheckTypes(v,t))
6574  return TRUE;
6575  idhdl c=(idhdl)v->next->next->data;
6576  if (v->next->next->next->rtyp!=IDHDL) return TRUE;
6577  idhdl m=(idhdl)v->next->next->next->data;
6578  idDelete((ideal *)&(c->data.uideal));
6579  idDelete((ideal *)&(m->data.uideal));
6580  mp_Coef2((poly)v->Data(),(poly)v->next->Data(),
6581  (matrix *)&(c->data.umatrix),(matrix *)&(m->data.umatrix),currRing);
6582  return FALSE;
6583 }
6584 
6586 { // may have 3 or 4 arguments
6587  leftv v1=v;
6588  leftv v2=v1->next;
6589  leftv v3=v2->next;
6590  leftv v4=v3->next;
6591  assumeStdFlag(v2);
6592 
6593  int i1=iiTestConvert(v1->Typ(),MODUL_CMD);
6594  int i2=iiTestConvert(v2->Typ(),MODUL_CMD);
6595 
6596  if((i1==0)||(i2==0)
6597  ||(v3->Typ()!=INT_CMD)||((v4!=NULL)&&(v4->Typ()!=INTVEC_CMD)))
6598  {
6599  WarnS("<module>,<module>,<int>[,<intvec>] expected!");
6600  return TRUE;
6601  }
6602 
6603  sleftv w1,w2;
6604  iiConvert(v1->Typ(),MODUL_CMD,i1,v1,&w1);
6605  iiConvert(v2->Typ(),MODUL_CMD,i2,v2,&w2);
6606  ideal P=(ideal)w1.Data();
6607  ideal Q=(ideal)w2.Data();
6608 
6609  int n=(int)(long)v3->Data();
6610  short *w=NULL;
6611  if(v4!=NULL)
6612  {
6613  w = iv2array((intvec *)v4->Data(),currRing);
6614  short * w0 = w + 1;
6615  int i = currRing->N;
6616  while( (i > 0) && ((*w0) > 0) )
6617  {
6618  w0++;
6619  i--;
6620  }
6621  if(i>0)
6622  WarnS("not all weights are positive!");
6623  }
6624 
6625  matrix T;
6626  ideal R;
6627  idLiftW(P,Q,n,T,R,w);
6628 
6629  w1.CleanUp();
6630  w2.CleanUp();
6631  if(w!=NULL)
6632  omFreeSize( (ADDRESS)w, (rVar(currRing)+1)*sizeof(short) );
6633 
6635  L->Init(2);
6636  L->m[1].rtyp=v1->Typ();
6637  if(v1->Typ()==POLY_CMD||v1->Typ()==VECTOR_CMD)
6638  {
6639  if(v1->Typ()==POLY_CMD)
6640  p_Shift(&R->m[0],-1,currRing);
6641  L->m[1].data=(void *)R->m[0];
6642  R->m[0]=NULL;
6643  idDelete(&R);
6644  }
6645  else if(v1->Typ()==IDEAL_CMD||v1->Typ()==MATRIX_CMD)
6646  L->m[1].data=(void *)id_Module2Matrix(R,currRing);
6647  else
6648  {
6649  L->m[1].rtyp=MODUL_CMD;
6650  L->m[1].data=(void *)R;
6651  }
6652  L->m[0].rtyp=MATRIX_CMD;
6653  L->m[0].data=(char *)T;
6654 
6655  res->data=L;
6656  res->rtyp=LIST_CMD;
6657 
6658  return FALSE;
6659 }
6660 
6661 //BOOLEAN jjDISPATCH(leftv res, leftv v)
6662 //{
6663 // WerrorS("`dispatch`: not implemented");
6664 // return TRUE;
6665 //}
6666 
6667 //static BOOLEAN jjEXPORTTO_M(leftv res, leftv u)
6668 //{
6669 // int l=u->listLength();
6670 // if (l<2) return TRUE;
6671 // BOOLEAN b;
6672 // leftv v=u->next;
6673 // leftv zz=v;
6674 // leftv z=zz;
6675 // u->next=NULL;
6676 // do
6677 // {
6678 // leftv z=z->next;
6679 // b=iiExprArith2(res,u,iiOp,z, (iiOp > 255));
6680 // if (b) break;
6681 // } while (z!=NULL);
6682 // u->next=zz;
6683 // return b;
6684 //}
6686 {
6687  int s=1;
6688  leftv h=v;
6689  if (h!=NULL) s=exprlist_length(h);
6690  ideal id=idInit(s,1);
6691  int rank=1;
6692  int i=0;
6693  poly p;
6694  while (h!=NULL)
6695  {
6696  switch(h->Typ())
6697  {
6698  case POLY_CMD:
6699  {
6700  p=(poly)h->CopyD(POLY_CMD);
6701  break;
6702  }
6703  case INT_CMD:
6704  {
6705  number n=nInit((int)(long)h->Data());
6706  if (!nIsZero(n))
6707  {
6708  p=pNSet(n);
6709  }
6710  else
6711  {
6712  p=NULL;
6713  nDelete(&n);
6714  }
6715  break;
6716  }
6717  case BIGINT_CMD:
6718  {
6719  number b=(number)h->Data();
6721  if (nMap==NULL) return TRUE;
6722  number n=nMap(b,coeffs_BIGINT,currRing->cf);
6723  if (!nIsZero(n))
6724  {
6725  p=pNSet(n);
6726  }
6727  else
6728  {
6729  p=NULL;
6730  nDelete(&n);
6731  }
6732  break;
6733  }
6734  case NUMBER_CMD:
6735  {
6736  number n=(number)h->CopyD(NUMBER_CMD);
6737  if (!nIsZero(n))
6738  {
6739  p=pNSet(n);
6740  }
6741  else
6742  {
6743  p=NULL;
6744  nDelete(&n);
6745  }
6746  break;
6747  }
6748  case VECTOR_CMD:
6749  {
6750  p=(poly)h->CopyD(VECTOR_CMD);
6751  if (iiOp!=MODUL_CMD)
6752  {
6753  idDelete(&id);
6754  pDelete(&p);
6755  return TRUE;
6756  }
6757  rank=si_max(rank,(int)pMaxComp(p));
6758  break;
6759  }
6760  default:
6761  {
6762  idDelete(&id);
6763  return TRUE;
6764  }
6765  }
6766  if ((iiOp==MODUL_CMD)&&(p!=NULL)&&(pGetComp(p)==0))
6767  {
6768  pSetCompP(p,1);
6769  }
6770  id->m[i]=p;
6771  i++;
6772  h=h->next;
6773  }
6774  id->rank=rank;
6775  res->data=(char *)id;
6776  return FALSE;
6777 }
6779 {
6780  ring r=(ring)u->Data();
6781  leftv v=u->next;
6782  leftv perm_var_l=v->next;
6783  leftv perm_par_l=v->next->next;
6784  if ((perm_var_l->Typ()!=INTVEC_CMD)
6785  ||((perm_par_l!=NULL)&&(perm_par_l->Typ()!=INTVEC_CMD))
6786  ||(u->Typ()!=RING_CMD))
6787  {
6788  WerrorS("fetch(<ring>,<name>[,<intvec>[,<intvec>])");
6789  return TRUE;
6790  }
6791  intvec *perm_var_v=(intvec*)perm_var_l->Data();
6792  intvec *perm_par_v=NULL;
6793  if (perm_par_l!=NULL)
6794  perm_par_v=(intvec*)perm_par_l->Data();
6795  idhdl w;
6796  nMapFunc nMap;
6797 
6798  if ((w=r->idroot->get(v->Name(),myynest))!=NULL)
6799  {
6800  int *perm=NULL;
6801  int *par_perm=NULL;
6802  int par_perm_size=0;
6803  BOOLEAN bo;
6804  if ((nMap=n_SetMap(r->cf,currRing->cf))==NULL)
6805  {
6806  // Allow imap/fetch to be make an exception only for:
6807  if ( (rField_is_Q_a(r) && // Q(a..) -> Q(a..) || Q || Zp || Zp(a)
6810  ||
6811  (rField_is_Zp_a(r) && // Zp(a..) -> Zp(a..) || Zp
6812  (rField_is_Zp(currRing, r->cf->ch) ||
6813  rField_is_Zp_a(currRing, r->cf->ch))) )
6814  {
6815  par_perm_size=rPar(r);
6816  }
6817  else
6818  {
6819  goto err_fetch;
6820  }
6821  }
6822  else
6823  par_perm_size=rPar(r);
6824  perm=(int *)omAlloc0((rVar(r)+1)*sizeof(int));
6825  if (par_perm_size!=0)
6826  par_perm=(int *)omAlloc0(par_perm_size*sizeof(int));
6827  int i;
6828  if (perm_par_l==NULL)
6829  {
6830  if (par_perm_size!=0)
6831  for(i=si_min(rPar(r),rPar(currRing))-1;i>=0;i--) par_perm[i]=-(i+1);
6832  }
6833  else
6834  {
6835  if (par_perm_size==0) WarnS("source ring has no parameters");
6836  else
6837  {
6838  for(i=rPar(r)-1;i>=0;i--)
6839  {
6840  if (i<perm_par_v->length()) par_perm[i]=(*perm_par_v)[i];
6841  if ((par_perm[i]<-rPar(currRing))
6842  || (par_perm[i]>rVar(currRing)))
6843  {
6844  Warn("invalid entry for par %d: %d\n",i,par_perm[i]);
6845  par_perm[i]=0;
6846  }
6847  }
6848  }
6849  }
6850  for(i=rVar(r)-1;i>=0;i--)
6851  {
6852  if (i<perm_var_v->length()) perm[i+1]=(*perm_var_v)[i];
6853  if ((perm[i]<-rPar(currRing))
6854  || (perm[i]>rVar(currRing)))
6855  {
6856  Warn("invalid entry for var %d: %d\n",i,perm[i]);
6857  perm[i]=0;
6858  }
6859  }
6860  if (BVERBOSE(V_IMAP))
6861  {
6862  for(i=1;i<=si_min(rVar(r),rVar(currRing));i++)
6863  {
6864  if (perm[i]>0)
6865  Print("// var nr %d: %s -> var %s\n",i,r->names[i-1],currRing->names[perm[i]-1]);
6866  else if (perm[i]<0)
6867  Print("// var nr %d: %s -> par %s\n",i,r->names[i-1],rParameter(currRing)[-perm[i]-1]);
6868  }
6869  for(i=1;i<=si_min(rPar(r),rPar(currRing));i++) // possibly empty loop
6870  {
6871  if (par_perm[i-1]<0)
6872  Print("// par nr %d: %s -> par %s\n",
6873  i,rParameter(r)[i-1],rParameter(currRing)[-par_perm[i-1]-1]);
6874  else if (par_perm[i-1]>0)
6875  Print("// par nr %d: %s -> var %s\n",
6876  i,rParameter(r)[i-1],currRing->names[par_perm[i-1]-1]);
6877  }
6878  }
6879  if (IDTYP(w)==ALIAS_CMD) w=(idhdl)IDDATA(w);
6880  sleftv tmpW;
6881  memset(&tmpW,0,sizeof(sleftv));
6882  tmpW.rtyp=IDTYP(w);
6883  tmpW.data=IDDATA(w);
6884  if ((bo=maApplyFetch(IMAP_CMD,NULL,res,&tmpW, r,
6885  perm,par_perm,par_perm_size,nMap)))
6886  {
6887  Werror("cannot map %s of type %s(%d)",v->name, Tok2Cmdname(w->typ),w->typ);
6888  }
6889  if (perm!=NULL)
6890  omFreeSize((ADDRESS)perm,(rVar(r)+1)*sizeof(int));
6891  if (par_perm!=NULL)
6892  omFreeSize((ADDRESS)par_perm,par_perm_size*sizeof(int));
6893  return bo;
6894  }
6895  else
6896  {
6897  Werror("identifier %s not found in %s",v->Fullname(),u->Fullname());
6898  }
6899  return TRUE;
6900 err_fetch:
6901  char *s1=nCoeffString(r->cf);
6902  char *s2=nCoeffString(currRing->cf);
6903  Werror("no identity map from %s (%s -> %s)",u->Fullname(),s1,s2);
6904  omFree(s2);omFree(s1);
6905  return TRUE;
6906 }
6908 {
6909  leftv h=v;
6910  int l=v->listLength();
6911  resolvente r=(resolvente)omAlloc0(l*sizeof(ideal));
6912  BOOLEAN *copied=(BOOLEAN *)omAlloc0(l*sizeof(BOOLEAN));
6913  int t=0;
6914  // try to convert to IDEAL_CMD
6915  while (h!=NULL)
6916  {
6917  if (iiTestConvert(h->Typ(),IDEAL_CMD)!=0)
6918  {
6919  t=IDEAL_CMD;
6920  }
6921  else break;
6922  h=h->next;
6923  }
6924  // if failure, try MODUL_CMD
6925  if (t==0)
6926  {
6927  h=v;
6928  while (h!=NULL)
6929  {
6930  if (iiTestConvert(h->Typ(),MODUL_CMD)!=0)
6931  {
6932  t=MODUL_CMD;
6933  }
6934  else break;
6935  h=h->next;
6936  }
6937  }
6938  // check for success in converting
6939  if (t==0)
6940  {
6941  WerrorS("cannot convert to ideal or module");
6942  return TRUE;
6943  }
6944  // call idMultSect
6945  h=v;
6946  int i=0;
6947  sleftv tmp;
6948  while (h!=NULL)
6949  {
6950  if (h->Typ()==t)
6951  {
6952  r[i]=(ideal)h->Data(); /*no copy*/
6953  h=h->next;
6954  }
6955  else if(iiConvert(h->Typ(),t,iiTestConvert(h->Typ(),t),h,&tmp))
6956  {
6957  omFreeSize((ADDRESS)copied,l*sizeof(BOOLEAN));
6958  omFreeSize((ADDRESS)r,l*sizeof(ideal));
6959  Werror("cannot convert arg. %d to %s",i+1,Tok2Cmdname(t));
6960  return TRUE;
6961  }
6962  else
6963  {
6964  r[i]=(ideal)tmp.Data(); /*now it's a copy*/
6965  copied[i]=TRUE;
6966  h=tmp.next;
6967  }
6968  i++;
6969  }
6970  res->rtyp=t;
6971  res->data=(char *)idMultSect(r,i);
6972  while(i>0)
6973  {
6974  i--;
6975  if (copied[i]) idDelete(&(r[i]));
6976  }
6977  omFreeSize((ADDRESS)copied,l*sizeof(BOOLEAN));
6978  omFreeSize((ADDRESS)r,l*sizeof(ideal));
6979  return FALSE;
6980 }
6982 {
6983  /* computation of the inverse of a quadratic matrix A
6984  using the L-U-decomposition of A;
6985  There are two valid parametrisations:
6986  1) exactly one argument which is just the matrix A,
6987  2) exactly three arguments P, L, U which already
6988  realise the L-U-decomposition of A, that is,
6989  P * A = L * U, and P, L, and U satisfy the
6990  properties decribed in method 'jjLU_DECOMP';
6991  see there;
6992  If A is invertible, the list [1, A^(-1)] is returned,
6993  otherwise the list [0] is returned. Thus, the user may
6994  inspect the first entry of the returned list to see
6995  whether A is invertible. */
6996  matrix iMat; int invertible;
6997  const short t1[]={1,MATRIX_CMD};
6998  const short t2[]={3,MATRIX_CMD,MATRIX_CMD,MATRIX_CMD};
6999  if (iiCheckTypes(v,t1))
7000  {
7001  matrix aMat = (matrix)v->Data();
7002  int rr = aMat->rows();
7003  int cc = aMat->cols();
7004  if (rr != cc)
7005  {
7006  Werror("given matrix (%d x %d) is not quadratic, hence not invertible", rr, cc);
7007  return TRUE;
7008  }
7009  if (!idIsConstant((ideal)aMat))
7010  {
7011  WerrorS("matrix must be constant");
7012  return TRUE;
7013  }
7014  invertible = luInverse(aMat, iMat);
7015  }
7016  else if (iiCheckTypes(v,t2))
7017  {
7018  matrix pMat = (matrix)v->Data();
7019  matrix lMat = (matrix)v->next->Data();
7020  matrix uMat = (matrix)v->next->next->Data();
7021  int rr = uMat->rows();
7022  int cc = uMat->cols();
7023  if (rr != cc)
7024  {
7025  Werror("third matrix (%d x %d) is not quadratic, hence not invertible",
7026  rr, cc);
7027  return TRUE;
7028  }
7029  if (!idIsConstant((ideal)pMat)
7030  || (!idIsConstant((ideal)lMat))
7031  || (!idIsConstant((ideal)uMat))
7032  )
7033  {
7034  WerrorS("matricesx must be constant");
7035  return TRUE;
7036  }
7037  invertible = luInverseFromLUDecomp(pMat, lMat, uMat, iMat);
7038  }
7039  else
7040  {
7041  Werror("expected either one or three matrices");
7042  return TRUE;
7043  }
7044 
7045  /* build the return structure; a list with either one or two entries */
7047  if (invertible)
7048  {
7049  ll->Init(2);
7050  ll->m[0].rtyp=INT_CMD; ll->m[0].data=(void *)(long)invertible;
7051  ll->m[1].rtyp=MATRIX_CMD; ll->m[1].data=(void *)iMat;
7052  }
7053  else
7054  {
7055  ll->Init(1);
7056  ll->m[0].rtyp=INT_CMD; ll->m[0].data=(void *)(long)invertible;
7057  }
7058 
7059  res->data=(char*)ll;
7060  return FALSE;
7061 }
7063 {
7064  /* for solving a linear equation system A * x = b, via the
7065  given LU-decomposition of the matrix A;
7066  There is one valid parametrisation:
7067  1) exactly four arguments P, L, U, b;
7068  P, L, and U realise the L-U-decomposition of A, that is,
7069  P * A = L * U, and P, L, and U satisfy the
7070  properties decribed in method 'jjLU_DECOMP';
7071  see there;
7072  b is the right-hand side vector of the equation system;
7073  The method will return a list of either 1 entry or three entries:
7074  1) [0] if there is no solution to the system;
7075  2) [1, x, H] if there is at least one solution;
7076  x is any solution of the given linear system,
7077  H is the matrix with column vectors spanning the homogeneous
7078  solution space.
7079  The method produces an error if matrix and vector sizes do not fit. */
7080  const short t[]={4,MATRIX_CMD,MATRIX_CMD,MATRIX_CMD,MATRIX_CMD};
7081  if (!iiCheckTypes(v,t))
7082  {
7083  WerrorS("expected exactly three matrices and one vector as input");
7084  return TRUE;
7085  }
7086  matrix pMat = (matrix)v->Data();
7087  matrix lMat = (matrix)v->next->Data();
7088  matrix uMat = (matrix)v->next->next->Data();
7089  matrix bVec = (matrix)v->next->next->next->Data();
7090  matrix xVec; int solvable; matrix homogSolSpace;
7091  if (pMat->rows() != pMat->cols())
7092  {
7093  Werror("first matrix (%d x %d) is not quadratic",
7094  pMat->rows(), pMat->cols());
7095  return TRUE;
7096  }
7097  if (lMat->rows() != lMat->cols())
7098  {
7099  Werror("second matrix (%d x %d) is not quadratic",
7100  lMat->rows(), lMat->cols());
7101  return TRUE;
7102  }
7103  if (lMat->rows() != uMat->rows())
7104  {
7105  Werror("second matrix (%d x %d) and third matrix (%d x %d) do not fit",
7106  lMat->rows(), lMat->cols(), uMat->rows(), uMat->cols());
7107  return TRUE;
7108  }
7109  if (uMat->rows() != bVec->rows())
7110  {
7111  Werror("third matrix (%d x %d) and vector (%d x 1) do not fit",
7112  uMat->rows(), uMat->cols(), bVec->rows());
7113  return TRUE;
7114  }
7115  if (!idIsConstant((ideal)pMat)
7116  ||(!idIsConstant((ideal)lMat))
7117  ||(!idIsConstant((ideal)uMat))
7118  )
7119  {
7120  WerrorS("matrices must be constant");
7121  return TRUE;
7122  }
7123  solvable = luSolveViaLUDecomp(pMat, lMat, uMat, bVec, xVec, homogSolSpace);
7124 
7125  /* build the return structure; a list with either one or three entries */
7127  if (solvable)
7128  {
7129  ll->Init(3);
7130  ll->m[0].rtyp=INT_CMD; ll->m[0].data=(void *)(long)solvable;
7131  ll->m[1].rtyp=MATRIX_CMD; ll->m[1].data=(void *)xVec;
7132  ll->m[2].rtyp=MATRIX_CMD; ll->m[2].data=(void *)homogSolSpace;
7133  }
7134  else
7135  {
7136  ll->Init(1);
7137  ll->m[0].rtyp=INT_CMD; ll->m[0].data=(void *)(long)solvable;
7138  }
7139 
7140  res->data=(char*)ll;
7141  return FALSE;
7142 }
7144 {
7145  int i=0;
7146  leftv h=v;
7147  if (h!=NULL) i=exprlist_length(h);
7148  intvec *iv=new intvec(i);
7149  i=0;
7150  while (h!=NULL)
7151  {
7152  if(h->Typ()==INT_CMD)
7153  {
7154  (*iv)[i]=(int)(long)h->Data();
7155  }
7156  else if (h->Typ()==INTVEC_CMD)
7157  {
7158  intvec *ivv=(intvec*)h->Data();
7159  for(int j=0;j<ivv->length();j++,i++)
7160  {
7161  (*iv)[i]=(*ivv)[j];
7162  }
7163  i--;
7164  }
7165  else
7166  {
7167  delete iv;
7168  return TRUE;
7169  }
7170  i++;
7171  h=h->next;
7172  }
7173  res->data=(char *)iv;
7174  return FALSE;
7175 }
7176 static BOOLEAN jjJET4(leftv res, leftv u)
7177 {
7178  const short t1[]={4,POLY_CMD,POLY_CMD,POLY_CMD,INTVEC_CMD};
7179  const short t2[]={4,VECTOR_CMD,POLY_CMD,POLY_CMD,INTVEC_CMD};
7180  const short t3[]={4,IDEAL_CMD,MATRIX_CMD,INT_CMD,INTVEC_CMD};
7181  const short t4[]={4,MODUL_CMD,MATRIX_CMD,INT_CMD,INTVEC_CMD};
7182  leftv u1=u;
7183  leftv u2=u1->next;
7184  leftv u3=u2->next;
7185  leftv u4=u3->next;
7186  if (iiCheckTypes(u,t1)||iiCheckTypes(u,t2))
7187  {
7188  if(!pIsUnit((poly)u2->Data()))
7189  {
7190  WerrorS("2nd argument must be a unit");
7191  return TRUE;
7192  }
7193  res->rtyp=u1->Typ();
7194  res->data=(char*)pSeries((int)(long)u3->Data(),pCopy((poly)u1->Data()),
7195  pCopy((poly)u2->Data()),(intvec*)u4->Data());
7196  return FALSE;
7197  }
7198  else
7199  if (iiCheckTypes(u,t3)||iiCheckTypes(u,t4))
7200  {
7201  if(!mp_IsDiagUnit((matrix)u2->Data(), currRing))
7202  {
7203  WerrorS("2nd argument must be a diagonal matrix of units");
7204  return TRUE;
7205  }
7206  res->rtyp=u1->Typ();
7207  res->data=(char*)idSeries(
7208  (int)(long)u3->Data(),
7209  idCopy((ideal)u1->Data()),
7210  mp_Copy((matrix)u2->Data(), currRing),
7211  (intvec*)u4->Data()
7212  );
7213  return FALSE;
7214  }
7215  else
7216  {
7217  Werror("%s(`poly`,`poly`,`int`,`intvec`) exppected",
7218  Tok2Cmdname(iiOp));
7219  return TRUE;
7220  }
7221 }
7222 #if 0
7223 static BOOLEAN jjBRACKET_PL(leftv res, leftv u)
7224 {
7225  int ut=u->Typ();
7226  leftv v=u->next; u->next=NULL;
7227  leftv w=v->next; v->next=NULL;
7228  if ((ut!=CRING_CMD)&&(ut!=RING_CMD))
7229  {
7230  BOOLEAN bo=TRUE;
7231  if (w==NULL)
7232  {
7233  bo=iiExprArith2(res,u,'[',v);
7234  }
7235  else if (w->next==NULL)
7236  {
7237  bo=iiExprArith3(res,'[',u,v,w);
7238  }
7239  v->next=w;
7240  u->next=v;
7241  return bo;
7242  }
7243  v->next=w;
7244  u->next=v;
7245  #ifdef SINGULAR_4_1
7246  // construct new rings:
7247  while (u!=NULL)
7248  {
7249  Print("name: %s,\n",u->Name());
7250  u=u->next;
7251  }
7252  #else
7253  memset(res,0,sizeof(sleftv));
7254  res->rtyp=NONE;
7255  return TRUE;
7256  #endif
7257 }
7258 #endif
7260 {
7261  if ((yyInRingConstruction)
7262  && ((strcmp(u->Name(),"real")==0) || (strcmp(u->Name(),"complex")==0)))
7263  {
7264  memcpy(res,u,sizeof(sleftv));
7265  memset(u,0,sizeof(sleftv));
7266  return FALSE;
7267  }
7268  leftv v=u->next;
7269  BOOLEAN b;
7270  if(v==NULL) // p()
7271  b=iiExprArith1(res,u,iiOp);
7272  else if ((v->next==NULL) // p(1)
7273  || (u->Typ()!=UNKNOWN)) // p(1,2), p proc or map
7274  {
7275  u->next=NULL;
7276  b=iiExprArith2(res,u,iiOp,v);
7277  u->next=v;
7278  }
7279  else // p(1,2), p undefined
7280  {
7281  if (v->Typ()!=INT_CMD)
7282  {
7283  Werror("`int` expected while building `%s(`",u->name);
7284  return TRUE;
7285  }
7286  int l=u->listLength();
7287  char * nn = (char *)omAlloc(strlen(u->name) + 12*l);
7288  sprintf(nn,"%s(%d",u->name,(int)(long)v->Data());
7289  char *s=nn;
7290  do
7291  {
7292  while (*s!='\0') s++;
7293  v=v->next;
7294  if (v->Typ()!=INT_CMD)
7295  {
7296  Werror("`int` expected while building `%s`",nn);
7297  omFree((ADDRESS)nn);
7298  return TRUE;
7299  }
7300  sprintf(s,",%d",(int)(long)v->Data());
7301  } while (v->next!=NULL);
7302  while (*s!='\0') s++;
7303  nn=strcat(nn,")");
7304  char *n=omStrDup(nn);
7305  omFree((ADDRESS)nn);
7306  syMake(res,n);
7307  b=FALSE;
7308  }
7309  return b;
7310 }
7311 static BOOLEAN jjLIFT_4(leftv res, leftv U)
7312 {
7313  const short t1[]={4,IDEAL_CMD,IDEAL_CMD,MATRIX_CMD,STRING_CMD};
7314  const short t2[]={4,MODUL_CMD,MODUL_CMD,MATRIX_CMD,STRING_CMD};
7315  leftv u=U;
7316  leftv v=u->next;
7317  leftv w=v->next;
7318  leftv u4=w->next;
7319  if (w->rtyp!=IDHDL) return TRUE;
7320  if (iiCheckTypes(U,t1)||iiCheckTypes(U,t2))
7321  {
7322  // see jjLIFT3
7323  ideal I=(ideal)u->Data();
7324  int ul= IDELEMS(I /*(ideal)u->Data()*/);
7325  int vl= IDELEMS((ideal)v->Data());
7326  GbVariant alg=syGetAlgorithm((char*)u4->Data(),currRing,I);
7327  ideal m
7328  = idLift(I,(ideal)v->Data(),NULL,FALSE,hasFlag(u,FLAG_STD),
7329  FALSE, (matrix *)(&(IDMATRIX((idhdl)(w->data)))),alg);
7330  if (m==NULL) return TRUE;
7331  res->data = (char *)id_Module2formatedMatrix(m,ul,vl,currRing);
7332  return FALSE;
7333  }
7334  else
7335  {
7336  Werror("%s(`ideal`,`ideal`,`matrix`,`string`)\n"
7337  "or (`module`,`module`,`matrix`,`string`)expected",
7338  Tok2Cmdname(iiOp));
7339  return TRUE;
7340  }
7341 }
7343 {
7344  const short t1[]={4,IDEAL_CMD,IDEAL_CMD,MATRIX_CMD,STRING_CMD};
7345  const short t2[]={4,MODUL_CMD,MODUL_CMD,MATRIX_CMD,STRING_CMD};
7346  leftv u=U;
7347  leftv v=u->next;
7348  leftv w=v->next;
7349  leftv u4=w->next;
7350  if (v->rtyp!=IDHDL) return TRUE;
7351  if (w->rtyp!=IDHDL) return TRUE;
7352  if (iiCheckTypes(U,t1)||iiCheckTypes(U,t2))
7353  {
7354  // see jjLIFTSTD3
7355  ideal I=(ideal)u->Data();
7356  idhdl hv=(idhdl)v->data;
7357  idhdl hw=(idhdl)w->data;
7358  GbVariant alg=syGetAlgorithm((char*)u4->Data(),currRing,I);
7359  // CopyD for IDEAL_CMD and MODUL_CMD are identical:
7360  res->data = (char *)idLiftStd((ideal)u->Data(),
7361  &(hv->data.umatrix),testHomog,
7362  &(hw->data.uideal),alg);
7363  setFlag(res,FLAG_STD); v->flag=0; w->flag=0;
7364  return FALSE;
7365  }
7366  else
7367  {
7368  Werror("%s(`ideal`,`ideal`,`matrix`,`string`)\n"
7369  "or (`module`,`module`,`matrix`,`string`)expected",
7370  Tok2Cmdname(iiOp));
7371  return TRUE;
7372  }
7373 }
7375 {
7376  int sl=0;
7377  if (v!=NULL) sl = v->listLength();
7378  lists L;
7379  if((sl==1)&&(v->Typ()==RESOLUTION_CMD))
7380  {
7381  int add_row_shift = 0;
7382  intvec *weights=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
7383  if (weights!=NULL) add_row_shift=weights->min_in();
7384  L=syConvRes((syStrategy)v->Data(),FALSE,add_row_shift);
7385  }
7386  else
7387  {
7389  leftv h=NULL;
7390  int i;
7391  int rt;
7392 
7393  L->Init(sl);
7394  for (i=0;i<sl;i++)
7395  {
7396  if (h!=NULL)
7397  { /* e.g. not in the first step:
7398  * h is the pointer to the old sleftv,
7399  * v is the pointer to the next sleftv
7400  * (in this moment) */
7401  h->next=v;
7402  }
7403  h=v;
7404  v=v->next;
7405  h->next=NULL;
7406  rt=h->Typ();
7407  if (rt==0)
7408  {
7409  L->Clean();
7410  Werror("`%s` is undefined",h->Fullname());
7411  return TRUE;
7412  }
7413  if (rt==RING_CMD)
7414  {
7415  L->m[i].rtyp=rt; L->m[i].data=h->Data();
7416  ((ring)L->m[i].data)->ref++;
7417  }
7418  else
7419  L->m[i].Copy(h);
7420  }
7421  }
7422  res->data=(char *)L;
7423  return FALSE;
7424 }
7426 {
7427  res->data=(void *)ipNameList(IDROOT);
7428  return FALSE;
7429 }
7431 {
7432  if(v==NULL)
7433  {
7434  res->data=(char *)showOption();
7435  return FALSE;
7436  }
7437  res->rtyp=NONE;
7438  return setOption(res,v);
7439 }
7441 {
7442  leftv u1=u;
7443  leftv u2=u1->next;
7444  leftv u3=u2->next;
7445  leftv u4=u3->next;
7446  if((u3->Typ()==INT_CMD)&&(u4->Typ()==INTVEC_CMD))
7447  {
7448  int save_d=Kstd1_deg;
7449  Kstd1_deg=(int)(long)u3->Data();
7450  kModW=(intvec *)u4->Data();
7451  BITSET save2;
7452  SI_SAVE_OPT2(save2);
7454  u2->next=NULL;
7455  BOOLEAN r=jjCALL2ARG(res,u);
7456  kModW=NULL;
7457  Kstd1_deg=save_d;
7458  SI_RESTORE_OPT2(save2);
7459  u->next->next=u3;
7460  return r;
7461  }
7462  else
7463  if((u1->Typ()==IDEAL_CMD)&&(u2->Typ()==MATRIX_CMD)&&(u3->Typ()==IDEAL_CMD)&&
7464  (u4->Typ()==INT_CMD))
7465  {
7466  assumeStdFlag(u3);
7467  if(!mp_IsDiagUnit((matrix)u2->Data(), currRing))
7468  {
7469  WerrorS("2nd argument must be a diagonal matrix of units");
7470  return TRUE;
7471  }
7472  res->rtyp=IDEAL_CMD;
7473  res->data=(char*)redNF(
7474  idCopy((ideal)u3->Data()),
7475  idCopy((ideal)u1->Data()),
7476  mp_Copy((matrix)u2->Data(), currRing),
7477  (int)(long)u4->Data()
7478  );
7479  return FALSE;
7480  }
7481  else
7482  if((u1->Typ()==POLY_CMD)&&(u2->Typ()==POLY_CMD)&&(u3->Typ()==IDEAL_CMD)&&
7483  (u4->Typ()==INT_CMD))
7484  {
7485  assumeStdFlag(u3);
7486  if(!pIsUnit((poly)u2->Data()))
7487  {
7488  WerrorS("2nd argument must be a unit");
7489  return TRUE;
7490  }
7491  res->rtyp=POLY_CMD;
7492  res->data=(char*)redNF(idCopy((ideal)u3->Data()),pCopy((poly)u1->Data()),
7493  pCopy((poly)u2->Data()),(int)(long)u4->Data());
7494  return FALSE;
7495  }
7496  else
7497  {
7498  Werror("%s(`poly`,`ideal`,`int`,`intvec`) expected",Tok2Cmdname(iiOp));
7499  Werror("%s(`ideal`,`matrix`,`ideal`,`int`) expected",Tok2Cmdname(iiOp));
7500  Werror("%s(`poly`,`poly`,`ideal`,`int`) expected",Tok2Cmdname(iiOp));
7501  return TRUE;
7502  }
7503 }
7505 {
7506  leftv u1=u;
7507  leftv u2=u1->next;
7508  leftv u3=u2->next;
7509  leftv u4=u3->next;
7510  leftv u5=u4->next;
7511  if((u1->Typ()==IDEAL_CMD)&&(u2->Typ()==MATRIX_CMD)&&(u3->Typ()==IDEAL_CMD)&&
7512  (u4->Typ()==INT_CMD)&&(u5->Typ()==INTVEC_CMD))
7513  {
7514  assumeStdFlag(u3);
7515  if(!mp_IsDiagUnit((matrix)u2->Data(), currRing))
7516  {
7517  WerrorS("2nd argument must be a diagonal matrix of units");
7518  return TRUE;
7519  }
7520  res->rtyp=IDEAL_CMD;
7521  res->data=(char*)redNF(
7522  idCopy((ideal)u3->Data()),
7523  idCopy((ideal)u1->Data()),
7524  mp_Copy((matrix)u2->Data(),currRing),
7525  (int)(long)u4->Data(),
7526  (intvec*)u5->Data()
7527  );
7528  return FALSE;
7529  }
7530  else
7531  if((u1->Typ()==POLY_CMD)&&(u2->Typ()==POLY_CMD)&&(u3->Typ()==IDEAL_CMD)&&
7532  (u4->Typ()==INT_CMD)&&(u5->Typ()==INTVEC_CMD))
7533  {
7534  assumeStdFlag(u3);
7535  if(!pIsUnit((poly)u2->Data()))
7536  {
7537  WerrorS("2nd argument must be a unit");
7538  return TRUE;
7539  }
7540  res->rtyp=POLY_CMD;
7541  res->data=(char*)redNF(idCopy((ideal)u3->Data()),pCopy((poly)u1->Data()),
7542  pCopy((poly)u2->Data()),
7543  (int)(long)u4->Data(),(intvec*)u5->Data());
7544  return FALSE;
7545  }
7546  else
7547  {
7548  Werror("%s(`ideal`,`ideal`,`matrix`,`int`,`intvec`) exppected",
7549  Tok2Cmdname(iiOp));
7550  return TRUE;
7551  }
7552 }
7554 {
7555  unsigned i=1;
7556  unsigned nCount = (sArithBase.nCmdUsed-1)/3;
7557  if((3*nCount)<sArithBase.nCmdUsed) nCount++;
7558  //Print("CMDS: %d/%d\n", sArithBase.nCmdUsed,
7559  // sArithBase.nCmdAllocated);
7560  for(i=0; i<nCount; i++)
7561  {
7562  Print("%-20s",sArithBase.sCmds[i+1].name);
7563  if(i+1+nCount<sArithBase.nCmdUsed)
7564  Print("%-20s",sArithBase.sCmds[i+1+nCount].name);
7565  if(i+1+2*nCount<sArithBase.nCmdUsed)
7566  Print("%-20s",sArithBase.sCmds[i+1+2*nCount].name);
7567  //if ((i%3)==1) PrintLn();
7568  PrintLn();
7569  }
7570  PrintLn();
7572  return FALSE;
7573 }
7575 {
7576  if (v == NULL)
7577  {
7578  res->data = omStrDup("");
7579  return FALSE;
7580  }
7581  int n = v->listLength();
7582  if (n == 1)
7583  {
7584  res->data = v->String();
7585  return FALSE;
7586  }
7587 
7588  char** slist = (char**) omAlloc(n*sizeof(char*));
7589  int i, j;
7590 
7591  for (i=0, j=0; i<n; i++, v = v ->next)
7592  {
7593  slist[i] = v->String();
7594  assume(slist[i] != NULL);
7595  j+=strlen(slist[i]);
7596  }
7597  char* s = (char*) omAlloc((j+1)*sizeof(char));
7598  *s='\0';
7599  for (i=0;i<n;i++)
7600  {
7601  strcat(s, slist[i]);
7602  omFree(slist[i]);
7603  }
7604  omFreeSize(slist, n*sizeof(char*));
7605  res->data = s;
7606  return FALSE;
7607 }
7609 {
7610  do
7611  {
7612  if (v->Typ()!=INT_CMD)
7613  return TRUE;
7614  test_cmd((int)(long)v->Data());
7615  v=v->next;
7616  }
7617  while (v!=NULL);
7618  return FALSE;
7619 }
7620 
7621 #if defined(__alpha) && !defined(linux)
7622 extern "C"
7623 {
7624  void usleep(unsigned long usec);
7625 };
7626 #endif
7628 {
7629  /* compute two factors of h(x,y) modulo x^(d+1) in K[[x]][y],
7630  see a detailed documentation in /kernel/linear_algebra/linearAlgebra.h
7631 
7632  valid argument lists:
7633  - (poly h, int d),
7634  - (poly h, int d, poly f0, poly g0), optional: factors of h(0,y),
7635  - (poly h, int d, int xIndex, int yIndex), optional: indices of vars x & y
7636  in list of ring vars,
7637  - (poly h, int d, poly f0, poly g0, int xIndex, int yIndec),
7638  optional: all 4 optional args
7639  (The defaults are xIndex = 1, yIndex = 2, f0 and g0 polynomials as found
7640  by singclap_factorize and h(0, y)
7641  has exactly two distinct monic factors [possibly with exponent > 1].)
7642  result:
7643  - list with the two factors f and g such that
7644  h(x,y) = f(x,y)*g(x,y) mod x^(d+1) */
7645 
7646  poly h = NULL;
7647  int d = 1;
7648  poly f0 = NULL;
7649  poly g0 = NULL;
7650  int xIndex = 1; /* default index if none provided */
7651  int yIndex = 2; /* default index if none provided */
7652 
7653  leftv u = v; int factorsGiven = 0;
7654  if ((u == NULL) || (u->Typ() != POLY_CMD))
7655  {
7656  WerrorS("expected arguments (poly, int [, poly, poly] [, int, int])");
7657  return TRUE;
7658  }
7659  else h = (poly)u->Data();
7660  u = u->next;
7661  if ((u == NULL) || (u->Typ() != INT_CMD))
7662  {
7663  WerrorS("expected arguments (poly, int [, poly, poly] [, int, int])");
7664  return TRUE;
7665  }
7666  else d = (int)(long)u->Data();
7667  u = u->next;
7668  if ((u != NULL) && (u->Typ() == POLY_CMD))
7669  {
7670  if ((u->next == NULL) || (u->next->Typ() != POLY_CMD))
7671  {
7672  WerrorS("expected arguments (poly, int [, poly, poly] [, int, int])");
7673  return TRUE;
7674  }
7675  else
7676  {
7677  f0 = (poly)u->Data();
7678  g0 = (poly)u->next->Data();
7679  factorsGiven = 1;
7680  u = u->next->next;
7681  }
7682  }
7683  if ((u != NULL) && (u->Typ() == INT_CMD))
7684  {
7685  if ((u->next == NULL) || (u->next->Typ() != INT_CMD))
7686  {
7687  WerrorS("expected arguments (poly, int [, poly, poly] [, int, int])");
7688  return TRUE;
7689  }
7690  else
7691  {
7692  xIndex = (int)(long)u->Data();
7693  yIndex = (int)(long)u->next->Data();
7694  u = u->next->next;
7695  }
7696  }
7697  if (u != NULL)
7698  {
7699  WerrorS("expected arguments (poly, int [, poly, poly] [, int, int])");
7700  return TRUE;
7701  }
7702 
7703  /* checks for provided arguments */
7704  if (pIsConstant(h) || (factorsGiven && (pIsConstant(f0) || pIsConstant(g0))))
7705  {
7706  WerrorS("expected non-constant polynomial argument(s)");
7707  return TRUE;
7708  }
7709  int n = rVar(currRing);
7710  if ((xIndex < 1) || (n < xIndex))
7711  {
7712  Werror("index for variable x (%d) out of range [1..%d]", xIndex, n);
7713  return TRUE;
7714  }
7715  if ((yIndex < 1) || (n < yIndex))
7716  {
7717  Werror("index for variable y (%d) out of range [1..%d]", yIndex, n);
7718  return TRUE;
7719  }
7720  if (xIndex == yIndex)
7721  {
7722  WerrorS("expected distinct indices for variables x and y");
7723  return TRUE;
7724  }
7725 
7726  /* computation of f0 and g0 if missing */
7727  if (factorsGiven == 0)
7728  {
7729  poly h0 = pSubst(pCopy(h), xIndex, NULL);
7730  intvec* v = NULL;
7731  ideal i = singclap_factorize(h0, &v, 0,currRing);
7732 
7733  ivTest(v);
7734 
7735  if (i == NULL) return TRUE;
7736 
7737  idTest(i);
7738 
7739  if ((v->rows() != 3) || ((*v)[0] =! 1) || (!nIsOne(pGetCoeff(i->m[0]))))
7740  {
7741  WerrorS("expected h(0,y) to have exactly two distinct monic factors");
7742  return TRUE;
7743  }
7744  f0 = pPower(pCopy(i->m[1]), (*v)[1]);
7745  g0 = pPower(pCopy(i->m[2]), (*v)[2]);
7746  idDelete(&i);
7747  }
7748 
7749  poly f; poly g;
7750  henselFactors(xIndex, yIndex, h, f0, g0, d, f, g);
7752  L->Init(2);
7753  L->m[0].rtyp = POLY_CMD; L->m[0].data=(void*)f;
7754  L->m[1].rtyp = POLY_CMD; L->m[1].data=(void*)g;
7755  res->rtyp = LIST_CMD;
7756  res->data = (char*)L;
7757  return FALSE;
7758 }
7760 {
7761  if ((v->Typ() != LINK_CMD) ||
7762  (v->next->Typ() != STRING_CMD) ||
7763  (v->next->next->Typ() != STRING_CMD) ||
7764  (v->next->next->next->Typ() != INT_CMD))
7765  return TRUE;
7766  jjSTATUS3(res, v, v->next, v->next->next);
7767 #if defined(HAVE_USLEEP)
7768  if (((long) res->data) == 0L)
7769  {
7770  int i_s = (int)(long) v->next->next->next->Data();
7771  if (i_s > 0)
7772  {
7773  usleep((int)(long) v->next->next->next->Data());
7774  jjSTATUS3(res, v, v->next, v->next->next);
7775  }
7776  }
7777 #elif defined(HAVE_SLEEP)
7778  if (((int) res->data) == 0)
7779  {
7780  int i_s = (int) v->next->next->next->Data();
7781  if (i_s > 0)
7782  {
7783  si_sleep((is - 1)/1000000 + 1);
7784  jjSTATUS3(res, v, v->next, v->next->next);
7785  }
7786  }
7787 #endif
7788  return FALSE;
7789 }
7791 {
7792  leftv v = u->next; // number of args > 0
7793  if (v==NULL) return TRUE;
7794  leftv w = v->next;
7795  if (w==NULL) return TRUE;
7796  leftv rest = w->next;;
7797 
7798  u->next = NULL;
7799  v->next = NULL;
7800  w->next = NULL;
7801  BOOLEAN b = iiExprArith3(res, iiOp, u, v, w);
7802  if ((rest!=NULL) && (!b))
7803  {
7804  sleftv tmp_res;
7805  leftv tmp_next=res->next;
7806  res->next=rest;
7807  memset(&tmp_res,0,sizeof(tmp_res));
7808  b = iiExprArithM(&tmp_res,res,iiOp);
7809  memcpy(res,&tmp_res,sizeof(tmp_res));
7810  res->next=tmp_next;
7811  }
7812  u->next = v;
7813  v->next = w;
7814  // rest was w->next, but is already cleaned
7815  return b;
7816 }
7817 static BOOLEAN jjQRDS(leftv res, leftv INPUT)
7818 {
7819  if ((INPUT->Typ() != MATRIX_CMD) ||
7820  (INPUT->next->Typ() != NUMBER_CMD) ||
7821  (INPUT->next->next->Typ() != NUMBER_CMD) ||
7822  (INPUT->next->next->next->Typ() != NUMBER_CMD))
7823  {
7824  WerrorS("expected (matrix, number, number, number) as arguments");
7825  return TRUE;
7826  }
7827  leftv u = INPUT; leftv v = u->next; leftv w = v->next; leftv x = w->next;
7828  res->data = (char *)qrDoubleShift((matrix)(u->Data()),
7829  (number)(v->Data()),
7830  (number)(w->Data()),
7831  (number)(x->Data()));
7832  return FALSE;
7833 }
7834 static BOOLEAN jjSTD_HILB_WP(leftv res, leftv INPUT)
7835 { ideal result;
7836  leftv u = INPUT; /* an ideal, weighted homogeneous and standard */
7837  leftv v = u->next; /* one additional polynomial or ideal */
7838  leftv h = v->next; /* Hilbert vector */
7839  leftv w = h->next; /* weight vector */
7840  assumeStdFlag(u);
7841  ideal i1=(ideal)(u->Data());
7842  ideal i0;
7843  if (((u->Typ()!=IDEAL_CMD)&&(u->Typ()!=MODUL_CMD))
7844  || (h->Typ()!=INTVEC_CMD)
7845  || (w->Typ()!=INTVEC_CMD))
7846  {
7847  WerrorS("expected `std(`ideal/module`,`poly/vector`,`intvec`,`intvec`)");
7848  return TRUE;
7849  }
7850  intvec *vw=(intvec *)w->Data(); // weights of vars
7851  /* merging std_hilb_w and std_1 */
7852  if (vw->length()!=currRing->N)
7853  {
7854  Werror("%d weights for %d variables",vw->length(),currRing->N);
7855  return TRUE;
7856  }
7857  int r=v->Typ();
7858  BOOLEAN cleanup_i0=FALSE;
7859  if ((r==POLY_CMD) ||(r==VECTOR_CMD))
7860  {
7861  i0=idInit(1,i1->rank);
7862  i0->m[0]=(poly)v->Data();
7863  cleanup_i0=TRUE;
7864  }
7865  else if (r==IDEAL_CMD)/* IDEAL */
7866  {
7867  i0=(ideal)v->Data();
7868  }
7869  else
7870  {
7871  WerrorS("expected `std(`ideal/module`,`poly/vector`,`intvec`,`intvec`)");
7872  return TRUE;
7873  }
7874  int ii0=idElem(i0);
7875  i1 = idSimpleAdd(i1,i0);
7876  if (cleanup_i0)
7877  {
7878  memset(i0->m,0,sizeof(poly)*IDELEMS(i0));
7879  idDelete(&i0);
7880  }
7881  intvec *ww=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
7882  tHomog hom=testHomog;
7883  /* u_id from jjSTD_W is now i1 as in jjSTD_1 */
7884  if (ww!=NULL)
7885  {
7886  if (!idTestHomModule(i1,currRing->qideal,ww))
7887  {
7888  WarnS("wrong weights");
7889  ww=NULL;
7890  }
7891  else
7892  {
7893  ww=ivCopy(ww);
7894  hom=isHomog;
7895  }
7896  }
7897  BITSET save1;
7898  SI_SAVE_OPT1(save1);
7900  result=kStd(i1,
7901  currRing->qideal,
7902  hom,
7903  &ww, // module weights
7904  (intvec *)h->Data(), // hilbert series
7905  0, // syzComp, whatever it is...
7906  IDELEMS(i1)-ii0, // new ideal
7907  vw); // weights of vars
7908  SI_RESTORE_OPT1(save1);
7909  idDelete(&i1);
7910  idSkipZeroes(result);
7911  res->data = (char *)result;
7912  if (!TEST_OPT_DEGBOUND) setFlag(res,FLAG_STD);
7913  if (ww!=NULL) atSet(res,omStrDup("isHomog"),ww,INTVEC_CMD);
7914  return FALSE;
7915 }
7916 
7918 {
7919  //Print("construct ring\n");
7920  if (a->Typ()!=CRING_CMD)
7921  {
7922  WerrorS("expected `cring` [ `id` ... ]");
7923  return TRUE;
7924  }
7925  assume(a->next!=NULL);
7926  leftv names=a->next;
7927  int N=names->listLength();
7928  char **n=(char**)omAlloc0(N*sizeof(char*));
7929  for(int i=0; i<N;i++,names=names->next)
7930  {
7931  n[i]=(char *)names->Name();
7932  }
7933  coeffs cf=(coeffs)a->CopyD();
7934  res->data=rDefault(cf,N,n, ringorder_dp);
7935  omFreeSize(n,N*sizeof(char*));
7936  return FALSE;
7937 }
7938 
7939 static Subexpr jjMakeSub(leftv e)
7940 {
7941  assume( e->Typ()==INT_CMD );
7942  Subexpr r=(Subexpr)omAlloc0Bin(sSubexpr_bin);
7943  r->start =(int)(long)e->Data();
7944  return r;
7945 }
7946 #define D(A) (A)
7947 #define NULL_VAL NULL
7948 #define IPARITH
7949 #include "table.h"
7950 
7951 #include "iparith.inc"
7952 
7953 /*=================== operations with 2 args. ============================*/
7954 /* must be ordered: first operations for chars (infix ops),
7955  * then alphabetically */
7956 
7958  BOOLEAN proccall,
7959  const struct sValCmd2* dA2,
7960  int at, int bt,
7961  const struct sConvertTypes *dConvertTypes)
7962 {
7963  memset(res,0,sizeof(sleftv));
7964  BOOLEAN call_failed=FALSE;
7965 
7966  if (!errorreported)
7967  {
7968  int i=0;
7969  iiOp=op;
7970  while (dA2[i].cmd==op)
7971  {
7972  if ((at==dA2[i].arg1)
7973  && (bt==dA2[i].arg2))
7974  {
7975  res->rtyp=dA2[i].res;
7976  if (currRing!=NULL)
7977  {
7978  if (check_valid(dA2[i].valid_for,op)) break;
7979  }
7980  else
7981  {
7982  if (RingDependend(dA2[i].res))
7983  {
7984  WerrorS("no ring active");
7985  break;
7986  }
7987  }
7988  if (traceit&TRACE_CALL)
7989  Print("call %s(%s,%s)\n",iiTwoOps(op),Tok2Cmdname(at),Tok2Cmdname(bt));
7990  if ((call_failed=dA2[i].p(res,a,b)))
7991  {
7992  break;// leave loop, goto error handling
7993  }
7994  a->CleanUp();
7995  b->CleanUp();
7996  //Print("op: %d,result typ:%d\n",op,res->rtyp);
7997  return FALSE;
7998  }
7999  i++;
8000  }
8001  // implicite type conversion ----------------------------------------------
8002  if (dA2[i].cmd!=op)
8003  {
8004  int ai,bi;
8007  BOOLEAN failed=FALSE;
8008  i=0; /*iiTabIndex(dArithTab2,JJTAB2LEN,op);*/
8009  //Print("op: %c, type: %s %s\n",op,Tok2Cmdname(at),Tok2Cmdname(bt));
8010  while (dA2[i].cmd==op)
8011  {
8012  //Print("test %s %s\n",Tok2Cmdname(dA2[i].arg1),Tok2Cmdname(dA2[i].arg2));
8013  if ((dA2[i].valid_for & NO_CONVERSION)==0)
8014  {
8015  if ((ai=iiTestConvert(at,dA2[i].arg1,dConvertTypes))!=0)
8016  {
8017  if ((bi=iiTestConvert(bt,dA2[i].arg2,dConvertTypes))!=0)
8018  {
8019  res->rtyp=dA2[i].res;
8020  if (currRing!=NULL)
8021  {
8022  if (check_valid(dA2[i].valid_for,op)) break;
8023  }
8024  else
8025  {
8026  if (RingDependend(dA2[i].res))
8027  {
8028  WerrorS("no ring active");
8029  break;
8030  }
8031  }
8032  if (traceit&TRACE_CALL)
8033  Print("call %s(%s,%s)\n",iiTwoOps(op),
8034  Tok2Cmdname(dA2[i].arg1),Tok2Cmdname(dA2[i].arg2));
8035  failed= ((iiConvert(at,dA2[i].arg1,ai,a,an))
8036  || (iiConvert(bt,dA2[i].arg2,bi,b,bn))
8037  || (call_failed=dA2[i].p(res,an,bn)));
8038  // everything done, clean up temp. variables
8039  if (failed)
8040  {
8041  // leave loop, goto error handling
8042  break;
8043  }
8044  else
8045  {
8046  // everything ok, clean up and return
8047  an->CleanUp();
8048  bn->CleanUp();
8051  return FALSE;
8052  }
8053  }
8054  }
8055  }
8056  i++;
8057  }
8058  an->CleanUp();
8059  bn->CleanUp();
8062  }
8063  // error handling ---------------------------------------------------
8064  const char *s=NULL;
8065  if (!errorreported)
8066  {
8067  if ((at==0) && (a->Fullname()!=sNoName_fe))
8068  {
8069  s=a->Fullname();
8070  }
8071  else if ((bt==0) && (b->Fullname()!=sNoName_fe))
8072  {
8073  s=b->Fullname();
8074  }
8075  if (s!=NULL)
8076  Werror("`%s` is not defined",s);
8077  else
8078  {
8079  i=0; /*iiTabIndex(dArithTab2,JJTAB2LEN,op);*/
8080  s = iiTwoOps(op);
8081  if (proccall)
8082  {
8083  Werror("%s(`%s`,`%s`) failed"
8084  ,s,Tok2Cmdname(at),Tok2Cmdname(bt));
8085  }
8086  else
8087  {
8088  Werror("`%s` %s `%s` failed"
8089  ,Tok2Cmdname(at),s,Tok2Cmdname(bt));
8090  }
8091  if ((!call_failed) && BVERBOSE(V_SHOW_USE))
8092  {
8093  while (dA2[i].cmd==op)
8094  {
8095  if(((at==dA2[i].arg1)||(bt==dA2[i].arg2))
8096  && (dA2[i].res!=0)
8097  && (dA2[i].p!=jjWRONG2))
8098  {
8099  if (proccall)
8100  Werror("expected %s(`%s`,`%s`)"
8101  ,s,Tok2Cmdname(dA2[i].arg1),Tok2Cmdname(dA2[i].arg2));
8102  else
8103  Werror("expected `%s` %s `%s`"
8104  ,Tok2Cmdname(dA2[i].arg1),s,Tok2Cmdname(dA2[i].arg2));
8105  }
8106  i++;
8107  }
8108  }
8109  }
8110  }
8111  a->CleanUp();
8112  b->CleanUp();
8113  res->rtyp = UNKNOWN;
8114  }
8115  return TRUE;
8116 }
8118  const struct sValCmd2* dA2,
8119  int at,
8120  const struct sConvertTypes *dConvertTypes)
8121 {
8122  leftv b=a->next;
8123  a->next=NULL;
8124  int bt=b->Typ();
8125  BOOLEAN bo=iiExprArith2TabIntern(res,a,op,b,TRUE,dA2,at,bt,dConvertTypes);
8126  a->next=b;
8127  a->CleanUp(); // to clean up the chain, content already done in iiExprArith2TabIntern
8128  return bo;
8129 }
8130 BOOLEAN iiExprArith2(leftv res, leftv a, int op, leftv b, BOOLEAN proccall)
8131 {
8132  memset(res,0,sizeof(sleftv));
8133 
8134  if (!errorreported)
8135  {
8136 #ifdef SIQ
8137  if (siq>0)
8138  {
8139  //Print("siq:%d\n",siq);
8141  memcpy(&d->arg1,a,sizeof(sleftv));
8142  a->Init();
8143  memcpy(&d->arg2,b,sizeof(sleftv));
8144  b->Init();
8145  d->argc=2;
8146  d->op=op;
8147  res->data=(char *)d;
8148  res->rtyp=COMMAND;
8149  return FALSE;
8150  }
8151 #endif
8152  int at=a->Typ();
8153  int bt=b->Typ();
8154  // handling bb-objects ----------------------------------------------------
8155  if (at>MAX_TOK)
8156  {
8157  blackbox *bb=getBlackboxStuff(at);
8158  if (bb!=NULL)
8159  {
8160  if (!bb->blackbox_Op2(op,res,a,b)) return FALSE;
8161  if (errorreported) return TRUE;
8162  // else: no op defined
8163  }
8164  else return TRUE;
8165  }
8166  else if ((bt>MAX_TOK)&&(op!='('))
8167  {
8168  blackbox *bb=getBlackboxStuff(bt);
8169  if (bb!=NULL)
8170  {
8171  if(!bb->blackbox_Op2(op,res,a,b)) return FALSE;
8172  if (errorreported) return TRUE;
8173  // else: no op defined
8174  }
8175  else return TRUE;
8176  }
8177  int i=iiTabIndex(dArithTab2,JJTAB2LEN,op);
8178  return iiExprArith2TabIntern(res,a,op,b,proccall,dArith2+i,at,bt,dConvertTypes);
8179  }
8180  a->CleanUp();
8181  b->CleanUp();
8182  return TRUE;
8183 }
8184 
8185 /*==================== operations with 1 arg. ===============================*/
8186 /* must be ordered: first operations for chars (infix ops),
8187  * then alphabetically */
8188 
8189 BOOLEAN iiExprArith1Tab(leftv res, leftv a, int op, const struct sValCmd1* dA1, int at, const struct sConvertTypes *dConvertTypes)
8190 {
8191  memset(res,0,sizeof(sleftv));
8192  BOOLEAN call_failed=FALSE;
8193 
8194  if (!errorreported)
8195  {
8196  BOOLEAN failed=FALSE;
8197  iiOp=op;
8198  int i = 0;
8199  while (dA1[i].cmd==op)
8200  {
8201  if (at==dA1[i].arg)
8202  {
8203  if (currRing!=NULL)
8204  {
8205  if (check_valid(dA1[i].valid_for,op)) break;
8206  }
8207  else
8208  {
8209  if (RingDependend(dA1[i].res))
8210  {
8211  WerrorS("no ring active");
8212  break;
8213  }
8214  }
8215  if (traceit&TRACE_CALL)
8216  Print("call %s(%s)\n",iiTwoOps(op),Tok2Cmdname(at));
8217  res->rtyp=dA1[i].res;
8218  if ((call_failed=dA1[i].p(res,a)))
8219  {
8220  break;// leave loop, goto error handling
8221  }
8222  if (a->Next()!=NULL)
8223  {
8225  failed=iiExprArith1(res->next,a->next,op);
8226  }
8227  a->CleanUp();
8228  return failed;
8229  }
8230  i++;
8231  }
8232  // implicite type conversion --------------------------------------------
8233  if (dA1[i].cmd!=op)
8234  {
8236  i=0;
8237  //Print("fuer %c , typ: %s\n",op,Tok2Cmdname(at));
8238  while (dA1[i].cmd==op)
8239  {
8240  int ai;
8241  //Print("test %s\n",Tok2Cmdname(dA1[i].arg));
8242  if ((dA1[i].valid_for & NO_CONVERSION)==0)
8243  {
8244  if ((ai=iiTestConvert(at,dA1[i].arg,dConvertTypes))!=0)
8245  {
8246  if (currRing!=NULL)
8247  {
8248  if (check_valid(dA1[i].valid_for,op)) break;
8249  }
8250  else
8251  {
8252  if (RingDependend(dA1[i].res))
8253  {
8254  WerrorS("no ring active");
8255  break;
8256  }
8257  }
8258  if (traceit&TRACE_CALL)
8259  Print("call %s(%s)\n",iiTwoOps(op),Tok2Cmdname(dA1[i].arg));
8260  res->rtyp=dA1[i].res;
8261  failed= ((iiConvert(at,dA1[i].arg,ai,a,an,dConvertTypes))
8262  || (call_failed=dA1[i].p(res,an)));
8263  // everything done, clean up temp. variables
8264  if (failed)
8265  {
8266  // leave loop, goto error handling
8267  break;
8268  }
8269  else
8270  {
8271  if (an->Next() != NULL)
8272  {
8273  res->next = (leftv)omAllocBin(sleftv_bin);
8274  failed=iiExprArith1(res->next,an->next,op);
8275  }
8276  // everything ok, clean up and return
8277  an->CleanUp();
8279  return failed;
8280  }
8281  }
8282  }
8283  i++;
8284  }
8285  an->CleanUp();
8287  }
8288  // error handling
8289  if (!errorreported)
8290  {
8291  if ((at==0) && (a->Fullname()!=sNoName_fe))
8292  {
8293  Werror("`%s` is not defined",a->Fullname());
8294  }
8295  else
8296  {
8297  i=0;
8298  const char *s = iiTwoOps(op);
8299  Werror("%s(`%s`) failed"
8300  ,s,Tok2Cmdname(at));
8301  if ((!call_failed) && BVERBOSE(V_SHOW_USE))
8302  {
8303  while (dA1[i].cmd==op)
8304  {
8305  if ((dA1[i].res!=0)
8306  && (dA1[i].p!=jjWRONG))
8307  Werror("expected %s(`%s`)"
8308  ,s,Tok2Cmdname(dA1[i].arg));
8309  i++;
8310  }
8311  }
8312  }
8313  }
8314  res->rtyp = UNKNOWN;
8315  }
8316  a->CleanUp();
8317  return TRUE;
8318 }
8320 {
8321  memset(res,0,sizeof(sleftv));
8322 
8323  if (!errorreported)
8324  {
8325 #ifdef SIQ
8326  if (siq>0)
8327  {
8328  //Print("siq:%d\n",siq);
8330  memcpy(&d->arg1,a,sizeof(sleftv));
8331  a->Init();
8332  d->op=op;
8333  d->argc=1;
8334  res->data=(char *)d;
8335  res->rtyp=COMMAND;
8336  return FALSE;
8337  }
8338 #endif
8339  int at=a->Typ();
8340  // handling bb-objects ----------------------------------------------------
8341  if(op>MAX_TOK) // explicit type conversion to bb
8342  {
8343  blackbox *bb=getBlackboxStuff(op);
8344  if (bb!=NULL)
8345  {
8346  res->rtyp=op;
8347  res->data=bb->blackbox_Init(bb);
8348  if(!bb->blackbox_Assign(res,a)) return FALSE;
8349  if (errorreported) return TRUE;
8350  }
8351  else return TRUE;
8352  }
8353  else if (at>MAX_TOK) // argument is of bb-type
8354  {
8355  blackbox *bb=getBlackboxStuff(at);
8356  if (bb!=NULL)
8357  {
8358  if(!bb->blackbox_Op1(op,res,a)) return FALSE;
8359  if (errorreported) return TRUE;
8360  // else: no op defined
8361  }
8362  else return TRUE;
8363  }
8364 
8365  iiOp=op;
8366  int i=iiTabIndex(dArithTab1,JJTAB1LEN,op);
8367  return iiExprArith1Tab(res,a,op, dArith1+i,at,dConvertTypes);
8368  }
8369  a->CleanUp();
8370  return TRUE;
8371 }
8372 
8373 /*=================== operations with 3 args. ============================*/
8374 /* must be ordered: first operations for chars (infix ops),
8375  * then alphabetically */
8376 
8378  const struct sValCmd3* dA3, int at, int bt, int ct,
8379  const struct sConvertTypes *dConvertTypes)
8380 {
8381  memset(res,0,sizeof(sleftv));
8382  BOOLEAN call_failed=FALSE;
8383 
8384  assume(dA3[0].cmd==op);
8385 
8386  if (!errorreported)
8387  {
8388  int i=0;
8389  iiOp=op;
8390  while (dA3[i].cmd==op)
8391  {
8392  if ((at==dA3[i].arg1)
8393  && (bt==dA3[i].arg2)
8394  && (ct==dA3[i].arg3))
8395  {
8396  res->rtyp=dA3[i].res;
8397  if (currRing!=NULL)
8398  {
8399  if (check_valid(dA3[i].valid_for,op)) break;
8400  }
8401  if (traceit&TRACE_CALL)
8402  Print("call %s(%s,%s,%s)\n",
8403  iiTwoOps(op),Tok2Cmdname(at),Tok2Cmdname(bt),Tok2Cmdname(ct));
8404  if ((call_failed=dA3[i].p(res,a,b,c)))
8405  {
8406  break;// leave loop, goto error handling
8407  }
8408  a->CleanUp();
8409  b->CleanUp();
8410  c->CleanUp();
8411  return FALSE;
8412  }
8413  i++;
8414  }
8415  // implicite type conversion ----------------------------------------------
8416  if (dA3[i].cmd!=op)
8417  {
8418  int ai,bi,ci;
8422  BOOLEAN failed=FALSE;
8423  i=0;
8424  //while ((dA3[i].cmd!=op)&&(dA3[i].cmd!=0)) i++;
8425  while (dA3[i].cmd==op)
8426  {
8427  if ((dA3[i].valid_for & NO_CONVERSION)==0)
8428  {
8429  if ((ai=iiTestConvert(at,dA3[i].arg1,dConvertTypes))!=0)
8430  {
8431  if ((bi=iiTestConvert(bt,dA3[i].arg2,dConvertTypes))!=0)
8432  {
8433  if ((ci=iiTestConvert(ct,dA3[i].arg3,dConvertTypes))!=0)
8434  {
8435  res->rtyp=dA3[i].res;
8436  if (currRing!=NULL)
8437  {
8438  if (check_valid(dA3[i].valid_for,op)) break;
8439  }
8440  if (traceit&TRACE_CALL)
8441  Print("call %s(%s,%s,%s)\n",
8442  iiTwoOps(op),Tok2Cmdname(dA3[i].arg1),
8443  Tok2Cmdname(dA3[i].arg2),Tok2Cmdname(dA3[i].arg3));
8444  failed= ((iiConvert(at,dA3[i].arg1,ai,a,an,dConvertTypes))
8445  || (iiConvert(bt,dA3[i].arg2,bi,b,bn,dConvertTypes))
8446  || (iiConvert(ct,dA3[i].arg3,ci,c,cn,dConvertTypes))
8447  || (call_failed=dA3[i].p(res,an,bn,cn)));
8448  // everything done, clean up temp. variables
8449  if (failed)
8450  {
8451  // leave loop, goto error handling
8452  break;
8453  }
8454  else
8455  {
8456  // everything ok, clean up and return
8457  an->CleanUp();
8458  bn->CleanUp();
8459  cn->CleanUp();
8463  //Print("op: %d,result typ:%d\n",op,res->rtyp);
8464  return FALSE;
8465  }
8466  }
8467  }
8468  }
8469  }
8470  i++;
8471  }
8472  an->CleanUp();
8473  bn->CleanUp();
8474  cn->CleanUp();
8478  }
8479  // error handling ---------------------------------------------------
8480  if (!errorreported)
8481  {
8482  const char *s=NULL;
8483  if ((at==0) && (a->Fullname()!=sNoName_fe))
8484  {
8485  s=a->Fullname();
8486  }
8487  else if ((bt==0) && (b->Fullname()!=sNoName_fe))
8488  {
8489  s=b->Fullname();
8490  }
8491  else if ((ct==0) && (c->Fullname()!=sNoName_fe))
8492  {
8493  s=c->Fullname();
8494  }
8495  if (s!=NULL)
8496  Werror("`%s` is not defined",s);
8497  else
8498  {
8499  i=0;
8500  //while ((dA3[i].cmd!=op)&&(dA3[i].cmd!=0)) i++;
8501  const char *s = iiTwoOps(op);
8502  Werror("%s(`%s`,`%s`,`%s`) failed"
8503  ,s,Tok2Cmdname(at),Tok2Cmdname(bt),Tok2Cmdname(ct));
8504  if ((!call_failed) && BVERBOSE(V_SHOW_USE))
8505  {
8506  while (dA3[i].cmd==op)
8507  {
8508  if(((at==dA3[i].arg1)
8509  ||(bt==dA3[i].arg2)
8510  ||(ct==dA3[i].arg3))
8511  && (dA3[i].res!=0))
8512  {
8513  Werror("expected %s(`%s`,`%s`,`%s`)"
8514  ,s,Tok2Cmdname(dA3[i].arg1)
8515  ,Tok2Cmdname(dA3[i].arg2)
8516  ,Tok2Cmdname(dA3[i].arg3));
8517  }
8518  i++;
8519  }
8520  }
8521  }
8522  }
8523  res->rtyp = UNKNOWN;
8524  }
8525  a->CleanUp();
8526  b->CleanUp();
8527  c->CleanUp();
8528  //Print("op: %d,result typ:%d\n",op,res->rtyp);
8529  return TRUE;
8530 }
8532 {
8533  memset(res,0,sizeof(sleftv));
8534 
8535  if (!errorreported)
8536  {
8537 #ifdef SIQ
8538  if (siq>0)
8539  {
8540  //Print("siq:%d\n",siq);
8542  memcpy(&d->arg1,a,sizeof(sleftv));
8543  a->Init();
8544  memcpy(&d->arg2,b,sizeof(sleftv));
8545  b->Init();
8546  memcpy(&d->arg3,c,sizeof(sleftv));
8547  c->Init();
8548  d->op=op;
8549  d->argc=3;
8550  res->data=(char *)d;
8551  res->rtyp=COMMAND;
8552  return FALSE;
8553  }
8554 #endif
8555  int at=a->Typ();
8556  // handling bb-objects ----------------------------------------------
8557  if (at>MAX_TOK)
8558  {
8559  blackbox *bb=getBlackboxStuff(at);
8560  if (bb!=NULL)
8561  {
8562  if(!bb->blackbox_Op3(op,res,a,b,c)) return FALSE;
8563  if (errorreported) return TRUE;
8564  // else: no op defined
8565  }
8566  else return TRUE;
8567  if (errorreported) return TRUE;
8568  }
8569  int bt=b->Typ();
8570  int ct=c->Typ();
8571 
8572  iiOp=op;
8573  int i=0;
8574  while ((dArith3[i].cmd!=op)&&(dArith3[i].cmd!=0)) i++;
8575  return iiExprArith3TabIntern(res,op,a,b,c,dArith3+i,at,bt,ct,dConvertTypes);
8576  }
8577  a->CleanUp();
8578  b->CleanUp();
8579  c->CleanUp();
8580  //Print("op: %d,result typ:%d\n",op,res->rtyp);
8581  return TRUE;
8582 }
8584  const struct sValCmd3* dA3,
8585  int at,
8586  const struct sConvertTypes *dConvertTypes)
8587 {
8588  leftv b=a->next;
8589  a->next=NULL;
8590  int bt=b->Typ();
8591  leftv c=b->next;
8592  b->next=NULL;
8593  int ct=c->Typ();
8594  BOOLEAN bo=iiExprArith3TabIntern(res,op,a,b,c,dA3,at,bt,ct,dConvertTypes);
8595  b->next=c;
8596  a->next=b;
8597  a->CleanUp(); // to cleanup the chain, content already done
8598  return bo;
8599 }
8600 /*==================== operations with many arg. ===============================*/
8601 /* must be ordered: first operations for chars (infix ops),
8602  * then alphabetically */
8603 
8604 #if 0 // unused
8605 static BOOLEAN jjANY2LIST(leftv res, leftv v, int cnt)
8606 {
8607  // cnt = 0: all
8608  // cnt = 1: only first one
8609  leftv next;
8610  BOOLEAN failed = TRUE;
8611  if(v==NULL) return failed;
8612  res->rtyp = LIST_CMD;
8613  if(cnt) v->next = NULL;
8614  next = v->next; // saving next-pointer
8615  failed = jjLIST_PL(res, v);
8616  v->next = next; // writeback next-pointer
8617  return failed;
8618 }
8619 #endif
8620 
8622 {
8623  memset(res,0,sizeof(sleftv));
8624 
8625  if (!errorreported)
8626  {
8627 #ifdef SIQ
8628  if (siq>0)
8629  {
8630  //Print("siq:%d\n",siq);
8632  d->op=op;
8633  res->data=(char *)d;
8634  if (a!=NULL)
8635  {
8636  d->argc=a->listLength();
8637  // else : d->argc=0;
8638  memcpy(&d->arg1,a,sizeof(sleftv));
8639  switch(d->argc)
8640  {
8641  case 3:
8642  memcpy(&d->arg3,a->next->next,sizeof(sleftv));
8643  a->next->next->Init();
8644  /* no break */
8645  case 2:
8646  memcpy(&d->arg2,a->next,sizeof(sleftv));
8647  a->next->Init();
8648  a->next->next=d->arg2.next;
8649  d->arg2.next=NULL;
8650  /* no break */
8651  case 1:
8652  a->Init();
8653  a->next=d->arg1.next;
8654  d->arg1.next=NULL;
8655  }
8656  if (d->argc>3) a->next=NULL;
8657  a->name=NULL;
8658  a->rtyp=0;
8659  a->data=NULL;
8660  a->e=NULL;
8661  a->attribute=NULL;
8662  a->CleanUp();
8663  }
8664  res->rtyp=COMMAND;
8665  return FALSE;
8666  }
8667 #endif
8668  if ((a!=NULL) && (a->Typ()>MAX_TOK))
8669  {
8670  blackbox *bb=getBlackboxStuff(a->Typ());
8671  if (bb!=NULL)
8672  {
8673  if(!bb->blackbox_OpM(op,res,a)) return FALSE;
8674  if (errorreported) return TRUE;
8675  // else: no op defined
8676  }
8677  else return TRUE;
8678  }
8679  int args=0;
8680  if (a!=NULL) args=a->listLength();
8681 
8682  iiOp=op;
8683  int i=0;
8684  while ((dArithM[i].cmd!=op)&&(dArithM[i].cmd!=0)) i++;
8685  while (dArithM[i].cmd==op)
8686  {
8687  if ((args==dArithM[i].number_of_args)
8688  || (dArithM[i].number_of_args==-1)
8689  || ((dArithM[i].number_of_args==-2)&&(args>0)))
8690  {
8691  res->rtyp=dArithM[i].res;
8692  if (currRing!=NULL)
8693  {
8694  if (check_valid(dArithM[i].valid_for,op)) break;
8695  }
8696  if (traceit&TRACE_CALL)
8697  Print("call %s(... (%d args))\n", iiTwoOps(op),args);
8698  if (dArithM[i].p(res,a))
8699  {
8700  break;// leave loop, goto error handling
8701  }
8702  if (a!=NULL) a->CleanUp();
8703  //Print("op: %d,result typ:%d\n",op,res->rtyp);
8704  return FALSE;
8705  }
8706  i++;
8707  }
8708  // error handling
8709  if (!errorreported)
8710  {
8711  if ((args>0) && (a->rtyp==0) && (a->Name()!=sNoName_fe))
8712  {
8713  Werror("`%s` is not defined",a->Fullname());
8714  }
8715  else
8716  {
8717  const char *s = iiTwoOps(op);
8718  Werror("%s(...) failed",s);
8719  }
8720  }
8721  res->rtyp = UNKNOWN;
8722  }
8723  if (a!=NULL) a->CleanUp();
8724  //Print("op: %d,result typ:%d\n",op,res->rtyp);
8725  return TRUE;
8726 }
8727 
8728 /*=================== general utilities ============================*/
8729 int IsCmd(const char *n, int & tok)
8730 {
8731  int i;
8732  int an=1;
8733  int en=sArithBase.nLastIdentifier;
8734 
8735  loop
8736  //for(an=0; an<sArithBase.nCmdUsed; )
8737  {
8738  if(an>=en-1)
8739  {
8740  if (strcmp(n, sArithBase.sCmds[an].name) == 0)
8741  {
8742  i=an;
8743  break;
8744  }
8745  else if ((an!=en) && (strcmp(n, sArithBase.sCmds[en].name) == 0))
8746  {
8747  i=en;
8748  break;
8749  }
8750  else
8751  {
8752  // -- blackbox extensions:
8753  // return 0;
8754  return blackboxIsCmd(n,tok);
8755  }
8756  }
8757  i=(an+en)/2;
8758  if (*n < *(sArithBase.sCmds[i].name))
8759  {
8760  en=i-1;
8761  }
8762  else if (*n > *(sArithBase.sCmds[i].name))
8763  {
8764  an=i+1;
8765  }
8766  else
8767  {
8768  int v=strcmp(n,sArithBase.sCmds[i].name);
8769  if(v<0)
8770  {
8771  en=i-1;
8772  }
8773  else if(v>0)
8774  {
8775  an=i+1;
8776  }
8777  else /*v==0*/
8778  {
8779  break;
8780  }
8781  }
8782  }
8783  lastreserved=sArithBase.sCmds[i].name;
8784  tok=sArithBase.sCmds[i].tokval;
8785  if(sArithBase.sCmds[i].alias==2)
8786  {
8787  Warn("outdated identifier `%s` used - please change your code",
8788  sArithBase.sCmds[i].name);
8789  sArithBase.sCmds[i].alias=1;
8790  }
8791  #if 0
8792  if (currRingHdl==NULL)
8793  {
8794  #ifdef SIQ
8795  if (siq<=0)
8796  {
8797  #endif
8798  if ((tok>=BEGIN_RING) && (tok<=END_RING))
8799  {
8800  WerrorS("no ring active");
8801  return 0;
8802  }
8803  #ifdef SIQ
8804  }
8805  #endif
8806  }
8807  #endif
8808  if (!expected_parms)
8809  {
8810  switch (tok)
8811  {
8812  case IDEAL_CMD:
8813  case INT_CMD:
8814  case INTVEC_CMD:
8815  case MAP_CMD:
8816  case MATRIX_CMD:
8817  case MODUL_CMD:
8818  case POLY_CMD:
8819  case PROC_CMD:
8820  case RING_CMD:
8821  case STRING_CMD:
8822  cmdtok = tok;
8823  break;
8824  }
8825  }
8826  return sArithBase.sCmds[i].toktype;
8827 }
8828 static int iiTabIndex(const jjValCmdTab dArithTab, const int len, const int op)
8829 {
8830  // user defined types are not in the pre-computed table:
8831  if (op>MAX_TOK) return 0;
8832 
8833  int a=0;
8834  int e=len;
8835  int p=len/2;
8836  do
8837  {
8838  if (op==dArithTab[p].cmd) return dArithTab[p].start;
8839  if (op<dArithTab[p].cmd) e=p-1;
8840  else a = p+1;
8841  p=a+(e-a)/2;
8842  }
8843  while ( a <= e);
8844 
8845  // catch missing a cmd:
8846  // may be missing as a op for blackbox, if the first operand is "undef" instead of bb
8847  // Print("op %d (%c) unknown",op,op);
8848  return 0;
8849 }
8850 
8851 const char * Tok2Cmdname(int tok)
8852 {
8853  if (tok <= 0)
8854  {
8855  return sArithBase.sCmds[0].name;
8856  }
8857  if (tok==ANY_TYPE) return "any_type";
8858  if (tok==COMMAND) return "command";
8859  if (tok==NONE) return "nothing";
8860  //if (tok==IFBREAK) return "if_break";
8861  //if (tok==VECTOR_FROM_POLYS) return "vector_from_polys";
8862  //if (tok==ORDER_VECTOR) return "ordering";
8863  //if (tok==REF_VAR) return "ref";
8864  //if (tok==OBJECT) return "object";
8865  //if (tok==PRINT_EXPR) return "print_expr";
8866  if (tok==IDHDL) return "identifier";
8867  if (tok>MAX_TOK) return getBlackboxName(tok);
8868  unsigned i;
8869  for(i=0; i<sArithBase.nCmdUsed; i++)
8870  //while (sArithBase.sCmds[i].tokval!=0)
8871  {
8872  if ((sArithBase.sCmds[i].tokval == tok)&&
8873  (sArithBase.sCmds[i].alias==0))
8874  {
8875  return sArithBase.sCmds[i].name;
8876  }
8877  }
8878  // try gain for alias/old names:
8879  for(i=0; i<sArithBase.nCmdUsed; i++)
8880  {
8881  if (sArithBase.sCmds[i].tokval == tok)
8882  {
8883  return sArithBase.sCmds[i].name;
8884  }
8885  }
8886  return sArithBase.sCmds[0].name;
8887 }
8888 
8889 
8890 /*---------------------------------------------------------------------*/
8891 /**
8892  * @brief compares to entry of cmdsname-list
8893 
8894  @param[in] a
8895  @param[in] b
8896 
8897  @return <ReturnValue>
8898 **/
8899 /*---------------------------------------------------------------------*/
8900 static int _gentable_sort_cmds( const void *a, const void *b )
8901 {
8902  cmdnames *pCmdL = (cmdnames*)a;
8903  cmdnames *pCmdR = (cmdnames*)b;
8904 
8905  if(a==NULL || b==NULL) return 0;
8906 
8907  /* empty entries goes to the end of the list for later reuse */
8908  if(pCmdL->name==NULL) return 1;
8909  if(pCmdR->name==NULL) return -1;
8910 
8911  /* $INVALID$ must come first */
8912  if(strcmp(pCmdL->name, "$INVALID$")==0) return -1;
8913  if(strcmp(pCmdR->name, "$INVALID$")==0) return 1;
8914 
8915  /* tokval=-1 are reserved names at the end */
8916  if (pCmdL->tokval==-1)
8917  {
8918  if (pCmdR->tokval==-1)
8919  return strcmp(pCmdL->name, pCmdR->name);
8920  /* pCmdL->tokval==-1, pCmdL goes at the end */
8921  return 1;
8922  }
8923  /* pCmdR->tokval==-1, pCmdR goes at the end */
8924  if(pCmdR->tokval==-1) return -1;
8925 
8926  return strcmp(pCmdL->name, pCmdR->name);
8927 }
8928 
8929 /*---------------------------------------------------------------------*/
8930 /**
8931  * @brief initialisation of arithmetic structured data
8932 
8933  @retval 0 on success
8934 
8935 **/
8936 /*---------------------------------------------------------------------*/
8938 {
8939  //printf("iiInitArithmetic()\n");
8940  memset(&sArithBase, 0, sizeof(sArithBase));
8941  iiInitCmdName();
8942  /* fix last-identifier */
8943 #if 0
8944  /* we expect that gentable allready did every thing */
8945  for(sArithBase.nLastIdentifier=sArithBase.nCmdUsed-1;
8946  sArithBase.nLastIdentifier>0; sArithBase.nLastIdentifier--) {
8947  if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
8948  }
8949 #endif
8950  //Print("L=%d\n", sArithBase.nLastIdentifier);
8951 
8952  //iiArithAddCmd(szName, nAlias, nTokval, nToktype);
8953  //iiArithAddCmd("mygcd", 1, GCD_CMD, CMD_2);
8954 
8955  //iiArithAddCmd("Top", 0,-1,0);
8956 
8957 
8958  //for(i=0; i<sArithBase.nCmdUsed; i++) {
8959  // printf("CMD[%03d] %s, %d, %d, %d\n", i,
8960  // sArithBase.sCmds[i].name,
8961  // sArithBase.sCmds[i].alias,
8962  // sArithBase.sCmds[i].tokval,
8963  // sArithBase.sCmds[i].toktype);
8964  //}
8965  //iiArithRemoveCmd("Top");
8966  //iiArithAddCmd("mygcd", 2, GCD_CMD, CMD_2);
8967  //iiArithRemoveCmd("mygcd");
8968  //iiArithAddCmd("kkk", 1, 1234, CMD_1);
8969  return 0;
8970 }
8971 
8972 int iiArithFindCmd(const char *szName)
8973 {
8974  int an=0;
8975  int i = 0,v = 0;
8976  int en=sArithBase.nLastIdentifier;
8977 
8978  loop
8979  //for(an=0; an<sArithBase.nCmdUsed; )
8980  {
8981  if(an>=en-1)
8982  {
8983  if (strcmp(szName, sArithBase.sCmds[an].name) == 0)
8984  {
8985  //Print("RET-an=%d %s\n", an, sArithBase.sCmds[an].name);
8986  return an;
8987  }
8988  else if (strcmp(szName, sArithBase.sCmds[en].name) == 0)
8989  {
8990  //Print("RET-en=%d %s\n", en, sArithBase.sCmds[en].name);
8991  return en;
8992  }
8993  else
8994  {
8995  //Print("RET- 1\n");
8996  return -1;
8997  }
8998  }
8999  i=(an+en)/2;
9000  if (*szName < *(sArithBase.sCmds[i].name))
9001  {
9002  en=i-1;
9003  }
9004  else if (*szName > *(sArithBase.sCmds[i].name))
9005  {
9006  an=i+1;
9007  }
9008  else
9009  {
9010  v=strcmp(szName,sArithBase.sCmds[i].name);
9011  if(v<0)
9012  {
9013  en=i-1;
9014  }
9015  else if(v>0)
9016  {
9017  an=i+1;
9018  }
9019  else /*v==0*/
9020  {
9021  //Print("RET-i=%d %s\n", i, sArithBase.sCmds[i].name);
9022  return i;
9023  }
9024  }
9025  }
9026  //if(i>=0 && i<sArithBase.nCmdUsed)
9027  // return i;
9028  //PrintS("RET-2\n");
9029  return -2;
9030 }
9031 
9032 char *iiArithGetCmd( int nPos )
9033 {
9034  if(nPos<0) return NULL;
9035  if(nPos<(int)sArithBase.nCmdUsed)
9036  return sArithBase.sCmds[nPos].name;
9037  return NULL;
9038 }
9039 
9040 int iiArithRemoveCmd(const char *szName)
9041 {
9042  int nIndex;
9043  if(szName==NULL) return -1;
9044 
9045  nIndex = iiArithFindCmd(szName);
9046  if(nIndex<0 || nIndex>=(int)sArithBase.nCmdUsed)
9047  {
9048  Print("'%s' not found (%d)\n", szName, nIndex);
9049  return -1;
9050  }
9051  omFree(sArithBase.sCmds[nIndex].name);
9052  sArithBase.sCmds[nIndex].name=NULL;
9053  qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames),
9054  (&_gentable_sort_cmds));
9055  sArithBase.nCmdUsed--;
9056 
9057  /* fix last-identifier */
9058  for(sArithBase.nLastIdentifier=sArithBase.nCmdUsed-1;
9059  sArithBase.nLastIdentifier>0; sArithBase.nLastIdentifier--)
9060  {
9061  if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
9062  }
9063  //Print("L=%d\n", sArithBase.nLastIdentifier);
9064  return 0;
9065 }
9066 
9068  const char *szName,
9069  short nAlias,
9070  short nTokval,
9071  short nToktype,
9072  short nPos
9073  )
9074 {
9075  //printf("AddCmd(%s, %d, %d, %d, %d)\n", szName, nAlias,
9076  // nTokval, nToktype, nPos);
9077  if(nPos>=0)
9078  {
9079  // no checks: we rely on a correct generated code in iparith.inc
9080  assume((unsigned)nPos < sArithBase.nCmdAllocated);
9081  assume(szName!=NULL);
9082  sArithBase.sCmds[nPos].name = omStrDup(szName);
9083  sArithBase.sCmds[nPos].alias = nAlias;
9084  sArithBase.sCmds[nPos].tokval = nTokval;
9085  sArithBase.sCmds[nPos].toktype = nToktype;
9086  sArithBase.nCmdUsed++;
9087  //if(nTokval>0) sArithBase.nLastIdentifier++;
9088  }
9089  else
9090  {
9091  if(szName==NULL) return -1;
9092  int nIndex = iiArithFindCmd(szName);
9093  if(nIndex>=0)
9094  {
9095  Print("'%s' already exists at %d\n", szName, nIndex);
9096  return -1;
9097  }
9098 
9099  if(sArithBase.nCmdUsed>=sArithBase.nCmdAllocated)
9100  {
9101  /* needs to create new slots */
9102  unsigned long nSize = (sArithBase.nCmdAllocated+1)*sizeof(cmdnames);
9103  sArithBase.sCmds = (cmdnames *)omRealloc(sArithBase.sCmds, nSize);
9104  if(sArithBase.sCmds==NULL) return -1;
9105  sArithBase.nCmdAllocated++;
9106  }
9107  /* still free slots available */
9108  sArithBase.sCmds[sArithBase.nCmdUsed].name = omStrDup(szName);
9109  sArithBase.sCmds[sArithBase.nCmdUsed].alias = nAlias;
9110  sArithBase.sCmds[sArithBase.nCmdUsed].tokval = nTokval;
9111  sArithBase.sCmds[sArithBase.nCmdUsed].toktype = nToktype;
9112  sArithBase.nCmdUsed++;
9113 
9114  qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames),
9115  (&_gentable_sort_cmds));
9116  for(sArithBase.nLastIdentifier=sArithBase.nCmdUsed-1;
9117  sArithBase.nLastIdentifier>0; sArithBase.nLastIdentifier--)
9118  {
9119  if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
9120  }
9121  //Print("L=%d\n", sArithBase.nLastIdentifier);
9122  }
9123  return 0;
9124 }
9125 
9126 static BOOLEAN check_valid(const int p, const int op)
9127 {
9128  #ifdef HAVE_PLURAL
9129  if (rIsPluralRing(currRing))
9130  {
9131  if ((p & PLURAL_MASK)==0 /*NO_PLURAL*/)
9132  {
9133  WerrorS("not implemented for non-commutative rings");
9134  return TRUE;
9135  }
9136  else if ((p & PLURAL_MASK)==2 /*, COMM_PLURAL */)
9137  {
9138  Warn("assume commutative subalgebra for cmd `%s`",Tok2Cmdname(op));
9139  return FALSE;
9140  }
9141  /* else, ALLOW_PLURAL */
9142  }
9143  #endif
9144 #ifdef HAVE_RINGS
9145  if (rField_is_Ring(currRing))
9146  {
9147  if ((p & RING_MASK)==0 /*NO_RING*/)
9148  {
9149  WerrorS("not implemented for rings with rings as coeffients");
9150  return TRUE;
9151  }
9152  /* else ALLOW_RING */
9153  else if (((p & ZERODIVISOR_MASK)==NO_ZERODIVISOR)
9154  &&(!rField_is_Domain(currRing)))
9155  {
9156  WerrorS("domain required as coeffients");
9157  return TRUE;
9158  }
9159  /* else ALLOW_ZERODIVISOR */
9160  else if(((p & WARN_RING)==WARN_RING)&&(myynest==0))
9161  {
9162  WarnS("considering the image in Q[...]");
9163  }
9164  }
9165 #endif
9166  return FALSE;
9167 }
9168 // --------------------------------------------------------------------
9170 {
9171  coeffs cf;
9172  lists c=(lists)u->CopyD(); // list of ideal or bigint/int
9173  int rl=c->nr+1;
9174  int return_type=c->m[0].Typ();
9175  if ((return_type!=IDEAL_CMD)
9176  && (return_type!=MODUL_CMD)
9177  && (return_type!=MATRIX_CMD)
9178  && (return_type!=POLY_CMD))
9179  {
9180  if((return_type==BIGINT_CMD)
9181  ||(return_type==INT_CMD))
9182  return_type=BIGINT_CMD;
9183  else if (return_type==LIST_CMD)
9184  {
9185  // create a tmp list of the correct size
9186  lists res_l=(lists)omAllocBin(slists_bin);
9187  res_l->Init(rl /*c->nr+1*/);
9188  BOOLEAN bo=FALSE;
9189  int tab_pos=iiTabIndex(dArithTab2,JJTAB2LEN,CHINREM_CMD);
9190  for (unsigned i=0;i<=(unsigned)c->nr;i++)
9191  {
9192  sleftv tmp;
9193  tmp.Copy(v);
9194  bo=iiExprArith2TabIntern(&res_l->m[i],&c->m[i],CHINREM_CMD,&tmp,TRUE,dArith2+tab_pos,c->m[i].rtyp,tmp.rtyp,dConvertTypes);
9195  if (bo) { Werror("chinrem failed for list entry %d",i+1); break;}
9196  }
9197  c->Clean();
9198  res->data=res_l;
9199  res->rtyp=LIST_CMD;
9200  return bo;
9201  }
9202  else
9203  {
9204  c->Clean();
9205  WerrorS("poly/ideal/module/matrix/list expected");
9206  return TRUE;
9207  }
9208  }
9209  if (return_type==BIGINT_CMD)
9210  cf=coeffs_BIGINT;
9211  else
9212  {
9213  cf=currRing->cf;
9214  if (nCoeff_is_Extension(cf) && (cf->extRing!=NULL))
9215  cf=cf->extRing->cf;
9216  }
9217  lists pl=NULL;
9218  intvec *p=NULL;
9219  if (v->Typ()==LIST_CMD) pl=(lists)v->Data();
9220  else p=(intvec*)v->Data();
9221  ideal result;
9222  ideal *x=(ideal *)omAlloc(rl*sizeof(ideal));
9223  number *xx=NULL;
9224  nMapFunc nMap=n_SetMap(coeffs_BIGINT,cf);
9225  int i;
9226  if (return_type!=BIGINT_CMD)
9227  {
9228  for(i=rl-1;i>=0;i--)
9229  {
9230  if (c->m[i].Typ()!=return_type)
9231  {
9232  Werror("%s expected at pos %d",Tok2Cmdname(return_type),i+1);
9233  omFree(x); // delete c
9234  return TRUE;
9235  }
9236  if (return_type==POLY_CMD)
9237  {
9238  x[i]=idInit(1,1);
9239  x[i]->m[0]=(poly)c->m[i].CopyD();
9240  }
9241  else
9242  {
9243  x[i]=(ideal)c->m[i].CopyD();
9244  }
9245  //c->m[i].Init();
9246  }
9247  }
9248  else
9249  {
9250  if (nMap==NULL)
9251  {
9252  Werror("not implemented: map bigint -> %s", nCoeffName(cf));
9253  return TRUE;
9254  }
9255  xx=(number *)omAlloc(rl*sizeof(number));
9256  for(i=rl-1;i>=0;i--)
9257  {
9258  if (c->m[i].Typ()==INT_CMD)
9259  {
9260  xx[i]=n_Init(((int)(long)c->m[i].Data()),cf);
9261  }
9262  else if (c->m[i].Typ()==BIGINT_CMD)
9263  {
9264  xx[i]=nMap((number)c->m[i].Data(),coeffs_BIGINT,cf);
9265  }
9266  else
9267  {
9268  Werror("bigint expected at pos %d",i+1);
9269  omFree(x); // delete c
9270  omFree(xx); // delete c
9271  return TRUE;
9272  }
9273  }
9274  }
9275  number *q=(number *)omAlloc(rl*sizeof(number));
9276  if (p!=NULL)
9277  {
9278  for(i=rl-1;i>=0;i--)
9279  {
9280  q[i]=n_Init((*p)[i], cf);
9281  }
9282  }
9283  else
9284  {
9285  for(i=rl-1;i>=0;i--)
9286  {
9287  if (pl->m[i].Typ()==INT_CMD)
9288  {
9289  q[i]=n_Init((int)(long)pl->m[i].Data(),cf);
9290  }
9291  else if (pl->m[i].Typ()==BIGINT_CMD)
9292  {
9293  q[i]=nMap((number)(pl->m[i].Data()),coeffs_BIGINT,cf);
9294  }
9295  else
9296  {
9297  Werror("bigint expected at pos %d",i+1);
9298  for(i++;i<rl;i++)
9299  {
9300  n_Delete(&(q[i]),cf);
9301  }
9302  omFree(x); // delete c
9303  omFree(q); // delete pl
9304  if (xx!=NULL) omFree(xx); // delete c
9305  return TRUE;
9306  }
9307  }
9308  }
9309  if (return_type==BIGINT_CMD)
9310  {
9311  CFArray i_v(rl);
9312  number n=n_ChineseRemainderSym(xx,q,rl,TRUE,i_v,coeffs_BIGINT);
9313  res->data=(char *)n;
9314  }
9315  else
9316  {
9317  result=id_ChineseRemainder(x,q,rl,currRing); // deletes also x
9318  c->Clean();
9319  if ((return_type==POLY_CMD) &&(result!=NULL))
9320  {
9321  res->data=(char *)result->m[0];
9322  result->m[0]=NULL;
9323  idDelete(&result);
9324  }
9325  else
9326  res->data=(char *)result;
9327  }
9328  for(i=rl-1;i>=0;i--)
9329  {
9330  n_Delete(&(q[i]),cf);
9331  }
9332  omFree(q);
9333  res->rtyp=return_type;
9334  return result==NULL;
9335 }
9337 {
9338  lists c=(lists)u->CopyD();
9339  lists res_l=(lists)omAllocBin(slists_bin);
9340  res_l->Init(c->nr+1);
9341  BOOLEAN bo=FALSE;
9342  int tab_pos=iiTabIndex(dArithTab2,JJTAB2LEN,FAREY_CMD);
9343  for (unsigned i=0;i<=(unsigned)c->nr;i++)
9344  {
9345  sleftv tmp;
9346  tmp.Copy(v);
9347  bo=iiExprArith2TabIntern(&res_l->m[i],&c->m[i],FAREY_CMD,&tmp,TRUE,dArith2+tab_pos,c->m[i].rtyp,tmp.rtyp,dConvertTypes);
9348  if (bo) { Werror("farey failed for list entry %d",i+1); break;}
9349  }
9350  c->Clean();
9351  res->data=res_l;
9352  return bo;
9353 }
9354 // --------------------------------------------------------------------
9355 static int jjCOMPARE_ALL(const void * aa, const void * bb)
9356 {
9357  leftv a=(leftv)aa;
9358  int at=a->Typ();
9359  leftv b=(leftv)bb;
9360  int bt=b->Typ();;
9361  if (at < bt) return -1;
9362  if (at > bt) return 1;
9363  int tab_pos=iiTabIndex(dArithTab2,JJTAB2LEN,'<');
9364  sleftv tmp;
9365  memset(&tmp,0,sizeof(sleftv));
9366  iiOp='<';
9367  BOOLEAN bo=iiExprArith2TabIntern(&tmp,a,'<',b,FALSE,dArith2+tab_pos,at,bt,dConvertTypes);
9368  if (bo)
9369  {
9370  Werror(" no `<` for %s",Tok2Cmdname(at));
9371  unsigned long ad=(unsigned long)a->Data();
9372  unsigned long bd=(unsigned long)b->Data();
9373  if (ad<bd) return -1;
9374  else if (ad==bd) return 0;
9375  else return 1;
9376  }
9377  else if (tmp.data==NULL) /* not < */
9378  {
9379  iiOp=EQUAL_EQUAL;
9380  tab_pos=iiTabIndex(dArithTab2,JJTAB2LEN,EQUAL_EQUAL);
9381  bo=iiExprArith2TabIntern(&tmp,a,EQUAL_EQUAL,b,FALSE,dArith2+tab_pos,at,bt,dConvertTypes);
9382  if (bo)
9383  {
9384  Werror(" no `==` for %s",Tok2Cmdname(at));
9385  unsigned long ad=(unsigned long)a->Data();
9386  unsigned long bd=(unsigned long)b->Data();
9387  if (ad<bd) return -1;
9388  else if (ad==bd) return 0;
9389  else return 1;
9390  }
9391  else if (tmp.data==NULL) /* not <,== */ return 1;
9392  else return 0;
9393  }
9394  else return -1;
9395 }
9397 {
9398  lists l=(lists)arg->Data();
9399  if (l->nr>0)
9400  {
9401  qsort(l->m,l->nr+1,sizeof(sleftv),jjCOMPARE_ALL);
9402  }
9403  return FALSE;
9404 }
9406 {
9407  lists l=(lists)arg->Data();
9408  if (l->nr>0)
9409  {
9410  qsort(l->m,l->nr+1,sizeof(sleftv),jjCOMPARE_ALL);
9411  int i, j, len;
9412  len=l->nr;
9413  i=0;
9414  while(i<len)
9415  {
9416  if(jjCOMPARE_ALL(&(l->m[i]),&(l->m[i+1]))==0)
9417  {
9418  l->m[i].CleanUp();
9419  for(j=i; j<len;j++) l->m[j]=l->m[j+1];
9420  memset(&(l->m[len]),0,sizeof(sleftv));
9421  l->m[len].rtyp=DEF_CMD;
9422  len--;
9423  }
9424  else
9425  i++;
9426  }
9427  //Print("new len:%d\n",len);
9428  }
9429  return FALSE;
9430 }
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:752
static BOOLEAN jjINTMAT3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5808
#define idPosConstant(I)
index of generator with leading term in ground ring (if any); otherwise -1
Definition: ideals.h:37
int compare(const intvec *o) const
Definition: intvec.cc:207
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of &#39;a&#39; and &#39;b&#39;, i.e., a-b
Definition: coeffs.h:673
int iiInitArithmetic()
initialisation of arithmetic structured data
Definition: iparith.cc:8937
int & rows()
Definition: matpol.h:24
matrix idDiff(matrix i, int k)
Definition: ideals.cc:1953
static BOOLEAN jjBREAK0(leftv, leftv)
Definition: iparith.cc:6522
static BOOLEAN jjPLUS_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:761
static BOOLEAN jjE(leftv res, leftv v)
Definition: iparith.cc:3972
static BOOLEAN jjPAR1(leftv res, leftv v)
Definition: iparith.cc:4561
#define pSubst(p, n, e)
Definition: polys.h:348
static BOOLEAN jjRANK2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2843
static BOOLEAN jjIDEAL_PL(leftv res, leftv v)
Definition: iparith.cc:6685
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:3373
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
ideal singclap_sqrfree(poly f, intvec **v, int with_exps, const ring r)
Definition: clapsing.cc:1142
static void jjEQUAL_REST(leftv res, leftv u, leftv v)
Definition: iparith.cc:1346
CanonicalForm map(const CanonicalForm &primElem, const Variable &alpha, const CanonicalForm &F, const Variable &beta)
map from to such that is mapped onto
Definition: cf_map_ext.cc:400
static BOOLEAN jjDET_S(leftv res, leftv v)
Definition: iparith.cc:3866
BOOLEAN yyInRingConstruction
Definition: grammar.cc:172
ideal scKBase(int deg, ideal s, ideal Q, intvec *mv)
Definition: hdegree.cc:1353
#define SIMPL_LMDIV
Definition: iparith.cc:3156
static BOOLEAN jjPLUSMINUS_Gen(leftv res, leftv u, leftv v)
Definition: iparith.cc:637
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:990
static FORCE_INLINE number n_IntMod(number a, number b, const coeffs r)
for r a field, return n_Init(0,r) always: n_Div(a,b,r)*b+n_IntMod(a,b,r)==a n_IntMod(a,b,r) >=0
Definition: coeffs.h:632
matrix mp_CoeffProc(poly f, poly vars, const ring R)
Definition: matpol.cc:410
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:612
static BOOLEAN jjBI2IM(leftv res, leftv u)
Definition: iparith.cc:3640
static BOOLEAN jjOP_BI_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:285
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 &#39;a&#39; and &#39;b&#39; in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ...
Definition: coeffs.h:690
#define WARN_RING
Definition: iparith.cc:122
static BOOLEAN jjFAC_P(leftv res, leftv u)
Definition: iparith.cc:4033
#define idMaxIdeal(D)
initialise the maximal ideal (at 0)
Definition: ideals.h:33
const CanonicalForm int s
Definition: facAbsFact.cc:55
void id_DelDiv(ideal id, const ring r)
delete id[j], if LT(j) == coeff*mon*LT(i) and vice versa, i.e., delete id[i], if LT(i) == coeff*mon*L...
unsigned si_opt_1
Definition: options.c:5
#define pVar(m)
Definition: polys.h:364
This file provides miscellaneous functionality.
ring rEnvelope(ring R)
Definition: ring.cc:5519
static BOOLEAN jjCALL2ARG(leftv res, leftv u)
Definition: iparith.cc:6550
resolvente syResolvente(ideal arg, int maxlength, int *length, intvec ***weights, BOOLEAN minim)
Definition: syz.cc:394
static BOOLEAN iiExprArith3TabIntern(leftv res, int op, leftv a, leftv b, leftv c, const struct sValCmd3 *dA3, int at, int bt, int ct, const struct sConvertTypes *dConvertTypes)
Definition: iparith.cc:8377
syStrategy syKosz(ideal arg, int *length)
Definition: syz3.cc:1764
int iiTestConvert(int inputType, int outputType)
Definition: gentable.cc:293
static BOOLEAN jjREPART(leftv res, leftv v)
Definition: iparith.cc:4716
ideal id_FreeModule(int i, const ring r)
the free module of rank i
sleftv * m
Definition: lists.h:45
static BOOLEAN jjRING3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6466
static BOOLEAN jjRSUM(leftv res, leftv u, leftv v)
Definition: iparith.cc:3149
ideal id_Transp(ideal a, const ring rRing)
transpose a module
static BOOLEAN jjVAR1(leftv res, leftv v)
Definition: iparith.cc:5071
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:2254
poly pSubstPoly(poly p, int var, poly image)
Definition: maps_ip.cc:390
Definition: tok.h:143
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
static BOOLEAN jjTEST(leftv, leftv v)
Definition: iparith.cc:7608
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition: kstd1.cc:2971
ideal id_Homogen(ideal h, int varnum, const ring r)
#define pSetm(p)
Definition: polys.h:253
char * rVarStr(ring r)
Definition: ring.cc:598
static int _gentable_sort_cmds(const void *a, const void *b)
compares to entry of cmdsname-list
Definition: iparith.cc:8900
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:4577
static BOOLEAN jjRING_2(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5608
number ntDiff(number a, number d, const coeffs cf)
Definition: transext.cc:887
static BOOLEAN jjTIMES_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:914
const poly a
Definition: syzextra.cc:212
Definition: tok.h:108
static BOOLEAN jjLOAD_E(leftv, leftv v, leftv u)
Definition: iparith.cc:2478
void PrintLn()
Definition: reporter.cc:310
static BOOLEAN jjJET_ID_M(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5845
#define ANY_TYPE
Definition: tok.h:30
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:3346
#define Print
Definition: emacs.cc:83
static BOOLEAN jjCOMPARE_S(leftv res, leftv u, leftv v)
Definition: iparith.cc:486
CanonicalForm fp
Definition: cfModGcd.cc:4043
static BOOLEAN jjnInt(leftv res, leftv u)
Definition: iparith.cc:5334
static BOOLEAN jjLIFT(leftv res, leftv u, leftv v)
Definition: iparith.cc:2454
BOOLEAN jjSORTLIST(leftv, leftv arg)
Definition: iparith.cc:9396
void omPrintInfo(FILE *fd)
Definition: omStats.c:129
bigintmat * bimSub(bigintmat *a, bigintmat *b)
Definition: bigintmat.cc:219
static BOOLEAN jjPLUS_MA(leftv res, leftv u, leftv v)
Definition: iparith.cc:808
Definition: tok.h:95
#define TEST_OPT_DEGBOUND
Definition: options.h:108
static BOOLEAN jjKERNEL(leftv res, leftv u, leftv v)
Definition: iparith.cc:2438
static BOOLEAN jjCOMPARE_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:348
#define pAdd(p, q)
Definition: polys.h:186
static BOOLEAN jjPLUS_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:798
static BOOLEAN jjSQR_FREE(leftv res, leftv u)
Definition: iparith.cc:4916
static BOOLEAN jjPFAC1(leftv res, leftv v)
Definition: iparith.cc:4397
number det()
det (via LaPlace in general, hnf for euc. rings)
Definition: bigintmat.cc:1520
static BOOLEAN jjTIMES_MA_BI2(leftv res, leftv u, leftv v)
Definition: iparith.cc:1032
static BOOLEAN jjKBASE2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2425
static BOOLEAN jjHILBERT2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2294
static BOOLEAN idHomIdeal(ideal id, ideal Q=NULL)
Definition: ideals.h:91
static BOOLEAN jjJET_P_IV(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5822
ideal id_Subst(ideal id, int n, poly e, const ring r)
#define SIMPL_MULT
Definition: iparith.cc:3158
ideal idSubstPar(ideal id, int n, poly e)
Definition: maps_ip.cc:373
static BOOLEAN jjMULT(leftv res, leftv v)
Definition: iparith.cc:4484
static BOOLEAN jjSUBST_Id_I(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6284
static BOOLEAN jjPlural_mat_mat(leftv res, leftv a, leftv b)
Definition: iparith.cc:2715
#define pNSet(n)
Definition: polys.h:295
static BOOLEAN jjPOWER_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:631
Subexpr e
Definition: subexpr.h:105
#define idDelete(H)
delete an ideal
Definition: ideals.h:29
static BOOLEAN rField_is_Zp_a(const ring r)
Definition: ring.h:521
BITSET flag
Definition: subexpr.h:90
static BOOLEAN jjFACSTD(leftv res, leftv v)
Definition: iparith.cc:3993
static BOOLEAN jjTRANSP_IV(leftv res, leftv v)
Definition: iparith.cc:4981
static BOOLEAN jjCALL3ARG(leftv res, leftv u)
Definition: iparith.cc:6558
static BOOLEAN jjN2BI(leftv res, leftv v)
Definition: iparith.cc:4504
Definition: lists.h:22
static BOOLEAN jjCOUNT_N(leftv res, leftv v)
Definition: iparith.cc:3698
#define nNormalize(n)
Definition: numbers.h:30
static BOOLEAN jjGETDUMP(leftv, leftv v)
Definition: iparith.cc:4049
static BOOLEAN jjINTVEC_PL(leftv res, leftv v)
Definition: iparith.cc:7143
static BOOLEAN jjP2BI(leftv res, leftv v)
Definition: iparith.cc:4601
ideal_list kStdfac(ideal F, ideal Q, tHomog h, intvec **w, ideal D)
Definition: kstdfac.cc:808
static BOOLEAN jjTIMES_MA_P2(leftv res, leftv u, leftv v)
Definition: iparith.cc:1046
void idLiftW(ideal P, ideal Q, int n, matrix &T, ideal &R, short *w)
Definition: ideals.cc:1134
ideal interpolation(const std::vector< ideal > &L, intvec *v)
#define TEST_OPT_PROT
Definition: options.h:98
intvec * scIndIntvec(ideal S, ideal Q)
Definition: hdegree.cc:212
void henselFactors(const int xIndex, const int yIndex, const poly h, const poly f0, const poly g0, const int d, poly &f, poly &g)
Computes a factorization of a polynomial h(x, y) in K[[x]][y] up to a certain degree in x...
int ncols
Definition: matpol.h:22
#define pMaxComp(p)
Definition: polys.h:281
BOOLEAN mpKoszul(leftv res, leftv c, leftv b, leftv id)
Definition: ipshell.cc:3018
loop
Definition: myNF.cc:98
if(0 > strat->sl)
Definition: myNF.cc:73
const struct sConvertTypes dConvertTypes[]
Definition: table.h:1186
#define IDID(a)
Definition: ipid.h:119
static BOOLEAN jjCOUNT_M(leftv res, leftv v)
Definition: iparith.cc:3709
BOOLEAN iiExprArith1(leftv res, leftv a, int op)
Definition: iparith.cc:8319
static int WerrorS_dummy_cnt
Definition: iparith.cc:5218
#define pSetExp(p, i, v)
Definition: polys.h:42
static int si_min(const int a, const int b)
Definition: auxiliary.h:121
int getRTimer()
Definition: timer.cc:172
static BOOLEAN jjRANDOM(leftv res, leftv u, leftv v)
Definition: iparith.cc:2835
static BOOLEAN jjOP_REST(leftv res, leftv u, leftv v)
Definition: iparith.cc:513
#define FALSE
Definition: auxiliary.h:94
unsigned nCmdAllocated
number of commands-slots allocated
Definition: iparith.cc:194
static BOOLEAN jjFAREY_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:2102
poly pHeadProc(poly p)
Definition: iparith.cc:234
matrix mp_InitP(int r, int c, poly p, const ring R)
make it a p * unit matrix
Definition: matpol.cc:120
Compatiblity layer for legacy polynomial operations (over currRing)
static BOOLEAN jjDIVMOD_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1154
BOOLEAN iiConvert(int inputType, int outputType, int index, leftv input, leftv output, const struct sConvertTypes *dConvertTypes)
Definition: ipconv.cc:401
static BOOLEAN jjBRACK_Ma_I_IV(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5450
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:2416
poly p_Homogen(poly p, int varnum, const ring r)
Definition: p_polys.cc:3200
static BOOLEAN jjL2R(leftv res, leftv v)
Definition: iparith.cc:4332
static BOOLEAN jjOpenClose(leftv, leftv v)
Definition: iparith.cc:4549
Definition: tok.h:38
short res
Definition: gentable.cc:65
static BOOLEAN jjMEMORY(leftv res, leftv v)
Definition: iparith.cc:4436
return P p
Definition: myNF.cc:203
Definition: tok.h:178
BOOLEAN jjWAIT1ST1(leftv res, leftv u)
Definition: iparith.cc:5111
int exprlist_length(leftv v)
Definition: ipshell.cc:544
ideal id_Copy(ideal h1, const ring r)
copy an ideal
short * iv2array(intvec *iv, const ring R)
Definition: weight.cc:208
Definition: mod_raw.h:16
Matrices of numbers.
Definition: bigintmat.h:51
static int rPar(const ring r)
(r->cf->P)
Definition: ring.h:590
static BOOLEAN jjCOEFFS_Id(leftv res, leftv u, leftv v)
Definition: iparith.cc:1780
BOOLEAN iiExprArith3(leftv res, int op, leftv a, leftv b, leftv c)
Definition: iparith.cc:8531
static BOOLEAN jjCOLS(leftv res, leftv v)
Definition: iparith.cc:3670
const char sNoName_fe[]
Definition: fevoices.cc:65
matrix mp_Coeffs(ideal I, int var, const ring R)
corresponds to Maple&#39;s coeffs: var has to be the number of a variable
Definition: matpol.cc:323
#define nPower(a, b, res)
Definition: numbers.h:38
#define pLmCmp(p, q)
returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
Definition: polys.h:105
static BOOLEAN jjKLAMMER_rest(leftv res, leftv u, leftv v)
Definition: iparith.cc:1580
lists syConvRes(syStrategy syzstr, BOOLEAN toDel, int add_row_shift)
Definition: ipshell.cc:3109
static BOOLEAN jjALIGN_M(leftv res, leftv u, leftv v)
Definition: iparith.cc:1759
static BOOLEAN jjHOMOG1(leftv res, leftv v)
Definition: iparith.cc:4144
static BOOLEAN jjCHINREM_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1662
void omPrintBinStats(FILE *fd)
Definition: omBin.c:692
static BOOLEAN jjPLUS_MA_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:820
char * rParStr(ring r)
Definition: ring.cc:624
poly sm_CallDet(ideal I, const ring R)
Definition: sparsmat.cc:355
BOOLEAN idTestHomModule(ideal m, ideal Q, intvec *w)
Definition: ideals.cc:1884
static BOOLEAN jjGCD_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:2271
static BOOLEAN jjrVarStr(leftv res, leftv v)
Definition: iparith.cc:5309
static BOOLEAN jjPRIME(leftv res, leftv v)
Definition: iparith.cc:4639
static BOOLEAN jjMODULO(leftv res, leftv u, leftv v)
Definition: iparith.cc:2489
ideal id_ChineseRemainder(ideal *xx, number *q, int rl, const ring r)
static BOOLEAN jjROWS(leftv res, leftv v)
Definition: iparith.cc:4742
static BOOLEAN jjDET_BI(leftv res, leftv v)
Definition: iparith.cc:3816
static BOOLEAN jjDUMP(leftv, leftv v)
Definition: iparith.cc:3958
int rows() const
Definition: bigintmat.h:146
static BOOLEAN jjPLUS_S(leftv res, leftv u, leftv v)
Definition: iparith.cc:835
BOOLEAN iiTryLoadLib(leftv v, const char *id)
Definition: iplib.cc:782
GbVariant
Definition: ideals.h:121
static BOOLEAN jjBRACK_Bim(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5393
poly mp_Trace(matrix a, const ring R)
Definition: matpol.cc:285
static BOOLEAN jjCOEF(leftv res, leftv u, leftv v)
Definition: iparith.cc:1773
Definition: tok.h:213
static BOOLEAN jjREDUCE3_ID(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6420
static BOOLEAN jjTIMES_MA_I2(leftv res, leftv u, leftv v)
Definition: iparith.cc:1074
static BOOLEAN jjJACOB_M(leftv res, leftv a)
Definition: iparith.cc:4304
static BOOLEAN jjnlInt(leftv res, leftv u)
Definition: iparith.cc:5341
static BOOLEAN jjIS_RINGVAR0(leftv res, leftv)
Definition: iparith.cc:4268
sleftv iiRETURNEXPR
Definition: iplib.cc:473
static BOOLEAN jjINTERRED(leftv res, leftv v)
Definition: iparith.cc:4246
static BOOLEAN jjMINUS_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:866
static BOOLEAN jjSTD_1(leftv res, leftv u, leftv v)
Definition: iparith.cc:3291
static BOOLEAN jjDOTDOT(leftv res, leftv u, leftv v)
Definition: iparith.cc:342
void id_Norm(ideal id, const ring r)
ideal id = (id[i]), result is leadcoeff(id[i]) = 1
static BOOLEAN jjNULL(leftv, leftv)
Definition: iparith.cc:3499
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:542
#define pIsUnit(p)
return true if the Lm is a constant <>0
Definition: polys.h:223
static BOOLEAN jjCONTENT(leftv res, leftv v)
Definition: iparith.cc:3685
static BOOLEAN jjFAC_P2(leftv res, leftv u, leftv dummy)
Definition: iparith.cc:2033
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
int rows() const
Definition: intvec.h:88
static BOOLEAN jjREAD2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2852
static BOOLEAN jjKLAMMER_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1552
#define idSimpleAdd(A, B)
Definition: ideals.h:42
matrix idDiffOp(ideal I, ideal J, BOOLEAN multiply)
Definition: ideals.cc:1966
int singclap_det_i(intvec *m, const ring)
Definition: clapsing.cc:1591
static BOOLEAN jjpHead(leftv res, leftv v)
Definition: iparith.cc:5266
Definition: grammar.cc:270
static BOOLEAN jjSYZ_2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3381
static BOOLEAN jjCOLON(leftv res, leftv u, leftv v)
Definition: iparith.cc:329
static BOOLEAN jjPARSTR2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2638
int rChar(ring r)
Definition: ring.cc:688
static BOOLEAN jjBI2N(leftv res, leftv u)
Definition: iparith.cc:3625
static BOOLEAN jjUMINUS_MA(leftv res, leftv u)
Definition: iparith.cc:3549
static BOOLEAN jjSUBST_Id_N(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6288
#define IDROOT
Definition: ipid.h:20
static BOOLEAN jjDIV_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:1203
ring rOpposite(ring src)
Definition: ring.cc:5189
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:583
BOOLEAN jjPROC(leftv res, leftv u, leftv v)
Definition: iparith.cc:1599
poly singclap_gcd(poly f, poly g, const ring r)
destroys f and g
Definition: clapsing.cc:264
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
void sdb_show_bp()
Definition: sdb.cc:58
#define pNeg(p)
Definition: polys.h:181
intvec * ivCopy(const intvec *o)
Definition: intvec.h:126
struct sValCmd1 * psValCmd1
Definition: iparith.cc:189
static BOOLEAN jjDEGREE(leftv res, leftv v)
Definition: iparith.cc:3753
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:183
BOOLEAN siq
Definition: subexpr.cc:57
static BOOLEAN jjINTERSECT_PL(leftv res, leftv v)
Definition: iparith.cc:6907
static BOOLEAN jjBREAK1(leftv, leftv v)
Definition: iparith.cc:6529
static BOOLEAN jjEXTGCD_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1987
#define SIMPL_EQU
Definition: iparith.cc:3159
int listLength()
Definition: subexpr.cc:60
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:66
static BOOLEAN jjPlural_mat_poly(leftv res, leftv a, leftv b)
Definition: iparith.cc:2695
static BOOLEAN jjNEWSTRUCT3(leftv, leftv u, leftv v, leftv w)
Definition: iparith.cc:6055
static BOOLEAN jjTRACE_IV(leftv res, leftv v)
Definition: iparith.cc:4971
#define pLmDelete(p)
assume p != NULL, deletes Lm(p)->coef and Lm(p)
Definition: polys.h:76
resolvente res
Definition: syz.h:47
const struct sValCmd2 dArith2[]
Definition: table.h:291
static BOOLEAN jjGT_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1118
static BOOLEAN jjidFreeModule(leftv res, leftv v)
Definition: iparith.cc:5251
static BOOLEAN rField_is_Q_a(const ring r)
Definition: ring.h:531
static BOOLEAN jjINTERPOLATION(leftv res, leftv l, leftv v)
Definition: iparith.cc:2392
#define TRUE
Definition: auxiliary.h:98
#define nIsOne(n)
Definition: numbers.h:25
lists qrDoubleShift(const matrix A, const number tol1, const number tol2, const number tol3, const ring r=currRing)
Computes all eigenvalues of a given real quadratic matrix with multiplicites.
lib_types type_of_LIB(const char *newlib, char *libnamebuf)
Definition: mod_lib.cc:24
static BOOLEAN jjMINUS_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:850
static BOOLEAN jjDUMMY(leftv res, leftv u)
Definition: iparith.cc:3494
ideal kStd(ideal F, ideal Q, tHomog h, intvec **w, intvec *hilb, int syzComp, int newIdeal, intvec *vw, s_poly_proc_t sp)
Definition: kstd1.cc:2231
syStrategy syResolution(ideal arg, int maxlength, intvec *w, BOOLEAN minim)
Definition: syz.cc:621
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:49
#define IDIDEAL(a)
Definition: ipid.h:130
ideal idMultSect(resolvente arg, int length)
Definition: ideals.cc:344
static BOOLEAN jjHILBERT_IV(leftv res, leftv v)
Definition: iparith.cc:4132
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1430
intvec * ivSub(intvec *a, intvec *b)
Definition: intvec.cc:280
int syDim(syStrategy syzstr)
Definition: syz1.cc:1857
#define pSplit(p, r)
Definition: polys.h:247
void Init()
Definition: subexpr.h:107
static BOOLEAN rField_is_Domain(const ring r)
Definition: ring.h:480
#define UNKNOWN
Definition: tok.h:217
int cmdtok
Definition: grammar.cc:174
static BOOLEAN jjEQUAL_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1308
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
Definition: coeffs.h:582
poly iiHighCorner(ideal I, int ak)
Definition: ipshell.cc:1511
void * ADDRESS
Definition: auxiliary.h:115
static BOOLEAN jjTIMES_MA_BI1(leftv res, leftv u, leftv v)
Definition: iparith.cc:1022
sleftv * leftv
Definition: structs.h:60
static BOOLEAN jjWEDGE(leftv res, leftv u, leftv v)
Definition: iparith.cc:3478
BOOLEAN iiExprArithM(leftv res, leftv a, int op)
Definition: iparith.cc:8621
poly singclap_det(const matrix m, const ring s)
Definition: clapsing.cc:1568
#define SI_SAVE_OPT1(A)
Definition: options.h:20
sValCmdTab jjValCmdTab[]
Definition: iparith.cc:135
static BOOLEAN jjPROC1(leftv res, leftv u)
Definition: iparith.cc:3591
intvec * ivTranp(intvec *o)
Definition: intvec.cc:310
#define PLURAL_MASK
Definition: iparith.cc:98
g
Definition: cfModGcd.cc:4031
static BOOLEAN jjDEG_M(leftv res, leftv u)
Definition: iparith.cc:3742
static BOOLEAN jjDIM_R(leftv res, leftv v)
Definition: iparith.cc:5324
void WerrorS(const char *s)
Definition: feFopen.cc:24
static BOOLEAN jjPROC3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5601
void omPrintStats(FILE *fd)
Definition: omStats.c:115
int k
Definition: cfEzgcd.cc:93
static BOOLEAN jjJanetBasis2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2404
static BOOLEAN jjOP_BIM_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:272
static BOOLEAN jjBRACK_Im(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5366
ideal idModulo(ideal h2, ideal h1, tHomog hom, intvec **w)
Definition: ideals.cc:2038
int min_in()
Definition: intvec.h:113
static BOOLEAN jjDIV_Ma(leftv res, leftv u, leftv v)
Definition: iparith.cc:1278
static intvec * idSort(ideal id, BOOLEAN nolex=TRUE)
Definition: ideals.h:185
static BOOLEAN jjNAMES0(leftv res, leftv)
Definition: iparith.cc:7425
static BOOLEAN rField_is_GF(const ring r)
Definition: ring.h:513
Definition: tok.h:119
static char const ** rParameter(const ring r)
(r->cf->parameter)
Definition: ring.h:616
int inerror
Definition: grammar.cc:175
static BOOLEAN jjTIMES_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:926
static BOOLEAN jjSTD(leftv res, leftv v)
Definition: iparith.cc:4885
static BOOLEAN jjJACOB_P(leftv res, leftv v)
Definition: iparith.cc:4273
static BOOLEAN jjpLength(leftv res, leftv v)
Definition: iparith.cc:5241
#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:717
const struct sValCmdM dArithM[]
Definition: table.h:826
BOOLEAN iiExprArith2Tab(leftv res, leftv a, int op, const struct sValCmd2 *dA2, int at, const struct sConvertTypes *dConvertTypes)
apply an operation &#39;op&#39; to arguments a and a->next return TRUE on failure
Definition: iparith.cc:8117
static BOOLEAN jjJET_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:2415
syStrategy syConvList(lists li)
Definition: ipshell.cc:3182
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
static BOOLEAN jjGE_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1093
int traceit
Definition: febase.cc:47
#define pEqualPolys(p1, p2)
Definition: polys.h:383
#define WarnS
Definition: emacs.cc:81
static FORCE_INLINE int n_ParDeg(number n, const coeffs r)
Definition: coeffs.h:804
BOOLEAN jjLOAD(const char *s, BOOLEAN autoexport)
load lib/module given in v
Definition: iparith.cc:5157
static BOOLEAN jjP2N(leftv res, leftv v)
Definition: iparith.cc:4669
ideal idMinEmbedding(ideal arg, BOOLEAN inPlace, intvec **w)
Definition: ideals.cc:2349
#define BITSET
Definition: structs.h:18
static BOOLEAN jjGCD_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:2250
poly singclap_pdivide(poly f, poly g, const ring r)
Definition: clapsing.cc:534
coeffs coeffs_BIGINT
Definition: ipid.cc:54
int Typ()
Definition: subexpr.cc:995
#define omAlloc(size)
Definition: omAllocDecl.h:210
static BOOLEAN jjFAREY_LI(leftv res, leftv u, leftv v)
Definition: iparith.cc:9336
static BOOLEAN jjOPPOSE(leftv res, leftv a, leftv b)
Definition: iparith.cc:2754
static BOOLEAN jjSUBST_Id(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6240
static BOOLEAN jjPRUNE(leftv res, leftv v)
Definition: iparith.cc:4645
static BOOLEAN jjOP_I_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:268
ideal idQuot(ideal h1, ideal h2, BOOLEAN h1IsStb, BOOLEAN resultIsIdeal)
Definition: ideals.cc:1308
#define Sy_bit(x)
Definition: options.h:30
short res
Definition: gentable.cc:74
static BOOLEAN iiExprArith2TabIntern(leftv res, leftv a, int op, leftv b, BOOLEAN proccall, const struct sValCmd2 *dA2, int at, int bt, const struct sConvertTypes *dConvertTypes)
Definition: iparith.cc:7957
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:1444
const char * Name()
Definition: subexpr.h:120
#define pGetComp(p)
Component.
Definition: polys.h:37
static BOOLEAN jjPARSTR1(leftv res, leftv v)
Definition: iparith.cc:4583
static BOOLEAN jjHOMOG1_W(leftv res, leftv v, leftv u)
Definition: iparith.cc:2359
static BOOLEAN jjGE_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1100
static int iiTabIndex(const jjValCmdTab dArithTab, const int len, const int op)
Definition: iparith.cc:8828
BOOLEAN iiExport(leftv v, int toLev)
Definition: ipshell.cc:1413
Definition: idrec.h:34
newstruct_desc newstructFromString(const char *s)
Definition: newstruct.cc:796
static BOOLEAN jjWAIT1ST2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3406
#define IDHDL
Definition: tok.h:31
ideal idOppose(ring Rop_src, ideal I, const ring Rop_dst)
opposes a module I from Rop to currRing(dst)
Definition: old.gring.cc:3412
poly redNF(poly h, int &max_ind, int nonorm, kStrategy strat)
Definition: kstd2.cc:1660
static BOOLEAN jjMAP(leftv res, leftv u, leftv v)
Definition: iparith.cc:1635
omBin char_ptr_bin
Definition: ring.cc:55
const char * Fullname()
Definition: subexpr.h:125
static BOOLEAN jjKoszul_Id(leftv res, leftv u, leftv v)
Definition: iparith.cc:2446
static BOOLEAN jjMINUS_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:871
static BOOLEAN idIsZeroDim(ideal i)
Definition: ideals.h:177
#define ivTest(v)
Definition: intvec.h:149
static BOOLEAN jjCOMPARE_MA(leftv res, leftv u, leftv v)
Definition: iparith.cc:431
idhdl get(const char *s, int lev)
Definition: ipid.cc:90
#define SI_PROT_I
Definition: reporter.h:52
ideal idMinBase(ideal h1)
Definition: ideals.cc:48
void monitor(void *F, int mode)
Definition: febase.cc:72
matrix idCoeffOfKBase(ideal arg, ideal kbase, poly how)
Definition: ideals.cc:2283
bool found
Definition: facFactorize.cc:56
static BOOLEAN jjTIMES_MA_I1(leftv res, leftv u, leftv v)
Definition: iparith.cc:1068
static BOOLEAN jjP2I(leftv res, leftv v)
Definition: iparith.cc:4621
ideal id_JetW(ideal i, int d, intvec *iv, const ring R)
static BOOLEAN jjMINOR_M(leftv res, leftv v)
Definition: iparith.cc:5856
static BOOLEAN jjEXPORTTO(leftv, leftv u, leftv v)
Definition: iparith.cc:1961
char * String(void *d=NULL, BOOLEAN typed=FALSE, int dim=1)
Called for conversion to string (used by string(..), write(..),..)
Definition: subexpr.cc:751
int iiRegularity(lists L)
Definition: ipshell.cc:956
static FORCE_INLINE number n_Random(siRandProc p, number p1, number p2, const coeffs cf)
Definition: coeffs.h:983
static BOOLEAN jjUMINUS_BI(leftv res, leftv u)
Definition: iparith.cc:3525
void * data
Definition: subexpr.h:88
static BOOLEAN jjTIMES_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:1010
static BOOLEAN jjCOUNT_RES(leftv res, leftv v)
Definition: iparith.cc:5319
static BOOLEAN jjJanetBasis(leftv res, leftv v)
Definition: iparith.cc:2410
void printBlackboxTypes()
list all defined type (for debugging)
Definition: blackbox.cc:208
#define mflush()
Definition: reporter.h:57
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:817
static BOOLEAN jjVARSTR2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3393
static BOOLEAN jjLE_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1137
static BOOLEAN jjROWS_IV(leftv res, leftv v)
Definition: iparith.cc:4753
#define pIter(p)
Definition: monomials.h:44
int rSum(ring r1, ring r2, ring &sum)
Definition: ring.cc:1306
static BOOLEAN jjEQUAL_Ma(leftv res, leftv u, leftv v)
Definition: iparith.cc:1320
poly res
Definition: myNF.cc:322
static BOOLEAN jjBAREISS(leftv res, leftv v)
Definition: iparith.cc:3595
static BOOLEAN idHomModule(ideal m, ideal Q, intvec **w)
Definition: ideals.h:96
intvec * kHomW
Definition: kstd1.cc:2206
matrix mp_Transp(matrix a, const ring R)
Definition: matpol.cc:264
#define IDPACKAGE(a)
Definition: ipid.h:136
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of &#39;a&#39; and &#39;b&#39;, i.e., a*b
Definition: coeffs.h:640
static BOOLEAN jjWAITALL2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3430
static int jjCOMPARE_ALL(const void *aa, const void *bb)
Definition: iparith.cc:9355
int myynest
Definition: febase.cc:46
int scMultInt(ideal S, ideal Q)
Definition: hdegree.cc:799
static BOOLEAN jjSetRing(leftv, leftv u)
Definition: iparith.cc:3570
#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:10
#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:5550
#define V_SHOW_USE
Definition: options.h:50
#define IDTYP(a)
Definition: ipid.h:116
static void WerrorS_dummy(const char *)
Definition: iparith.cc:5219
static BOOLEAN jjCOUNT_IV(leftv res, leftv v)
Definition: iparith.cc:3715
static BOOLEAN jjRES3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6428
static BOOLEAN jjTIMES_MA_N1(leftv res, leftv u, leftv v)
Definition: iparith.cc:1056
static BOOLEAN jjRINGLIST_C(leftv res, leftv v)
Definition: iparith.cc:4728
static BOOLEAN jjSTATUS2L(leftv res, leftv u, leftv v)
Definition: iparith.cc:3247
const struct sValCmd3 dArith3[]
Definition: table.h:716
static BOOLEAN check_valid(const int p, const int op)
Definition: iparith.cc:9126
static BOOLEAN jjPLUS_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:783
char * iiArithGetCmd(int nPos)
Definition: iparith.cc:9032
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:258
static BOOLEAN jjrCharStr(leftv res, leftv v)
Definition: iparith.cc:5261
static BOOLEAN jjKoszul(leftv res, leftv u, leftv v)
Definition: iparith.cc:2442
poly * m
Definition: matpol.h:19
static BOOLEAN jjBRACKET(leftv res, leftv a, leftv b)
Definition: iparith.cc:2735
const char * Tok2Cmdname(int tok)
Definition: iparith.cc:8851
static BOOLEAN jjINDEX_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:1427
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:691
char my_yylinebuf[80]
Definition: febase.cc:48
static BOOLEAN jjOP_BIM_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:253
int r_IsRingVar(const char *n, char **names, int N)
Definition: ring.cc:222
ideal idSect(ideal h1, ideal h2)
Definition: ideals.cc:204
static BOOLEAN jjREDUCE3_CID(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6401
static BOOLEAN jjIDEAL_Map(leftv res, leftv v)
Definition: iparith.cc:4201
static BOOLEAN jjSUBST_Test(leftv v, leftv w, int &ringvar, poly &monomexpr)
Definition: iparith.cc:6186
const ring r
Definition: syzextra.cc:208
static BOOLEAN jjIm2Iv(leftv res, leftv v)
Definition: iparith.cc:4228
static BOOLEAN jjSUBST_M(leftv res, leftv u)
Definition: iparith.cc:7790
static BOOLEAN jjLU_INVERSE(leftv res, leftv v)
Definition: iparith.cc:6981
static BOOLEAN jjHIGHCORNER_M(leftv res, leftv v)
Definition: iparith.cc:4070
BOOLEAN expected_parms
Definition: grammar.cc:173
static BOOLEAN jjINDEPSET2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2379
intvec * bim2iv(bigintmat *b)
Definition: bigintmat.cc:342
Coefficient rings, fields and other domains suitable for Singular polynomials.
static BOOLEAN jjLT_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1141
static BOOLEAN jjIMPART(leftv res, leftv v)
Definition: iparith.cc:4235
resolvente orderedRes
Definition: syz.h:48
static BOOLEAN jjLOAD1(leftv, leftv v)
Definition: iparith.cc:4386
ideal idSeries(int n, ideal M, matrix U, intvec *w)
Definition: ideals.cc:1936
intvec * kModW
Definition: kstd1.cc:2206
ideal idElimination(ideal h1, poly delVar, intvec *hilb)
Definition: ideals.cc:1402
#define FLAG_TWOSTD
Definition: ipid.h:107
static BOOLEAN jjSUBST_Id_X(leftv res, leftv u, leftv v, leftv w, int input_type)
Definition: iparith.cc:6292
static BOOLEAN jjREDUCE_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:2876
Definition: tok.h:77
#define TIMER_RESOLUTION
Definition: mod2.h:32
BOOLEAN jjWAITALL1(leftv res, leftv u)
Definition: iparith.cc:5126
void id_DelMultiples(ideal id, const ring r)
ideal id = (id[i]), c any unit if id[i] = c*id[j] then id[j] is deleted for j > i ...
Definition: intvec.h:14
#define pSub(a, b)
Definition: polys.h:269
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
void id_DelLmEquals(ideal id, const ring r)
Delete id[j], if Lm(j) == Lm(i) and both LC(j), LC(i) are units and j > i.
static FORCE_INLINE long n_Int(number &n, const coeffs r)
conversion of n to an int; 0 if not possible in Z/pZ: the representing int lying in (-p/2 ...
Definition: coeffs.h:551
const char * iiTwoOps(int t)
Definition: gentable.cc:253
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
poly p_One(const ring r)
Definition: p_polys.cc:1314
short cmd
Definition: iparith.cc:131
static BOOLEAN jjUMINUS_I(leftv res, leftv u)
Definition: iparith.cc:3532
matrix mp_Wedge(matrix a, int ar, const ring R)
Definition: matpol.cc:1660
static BOOLEAN jjWRONG(leftv, leftv)
Definition: iparith.cc:3485
static BOOLEAN jjLIFT_4(leftv res, leftv U)
Definition: iparith.cc:7311
static BOOLEAN jjMATRIX_Ma(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6338
static BOOLEAN jjMSTD(leftv res, leftv v)
Definition: iparith.cc:4469
BOOLEAN jjANY2LIST(leftv res, leftv v, int cnt)
leftv Next()
Definition: subexpr.h:136
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:3544
static BOOLEAN jjCOEFFS2_KB(leftv res, leftv u, leftv v)
Definition: iparith.cc:1791
static BOOLEAN jjmpTrace(leftv res, leftv v)
Definition: iparith.cc:5294
lists ipNameListLev(idhdl root, int lev)
Definition: ipid.cc:556
static BOOLEAN jjALIGN_V(leftv res, leftv u, leftv v)
Definition: iparith.cc:1749
Definition: tok.h:58
bigintmat * bimMult(bigintmat *a, bigintmat *b)
Definition: bigintmat.cc:256
const char * name
Definition: subexpr.h:87
void pSetDegProcs(ring r, pFDegProc new_FDeg, pLDegProc new_lDeg)
Definition: p_polys.cc:3543
static BOOLEAN jjEQUAL_R(leftv res, leftv u, leftv v)
Definition: iparith.cc:1326
Definition: tok.h:182
static BOOLEAN jjKLAMMER(leftv res, leftv u, leftv v)
Definition: iparith.cc:1539
#define pSetCompP(a, i)
Definition: polys.h:285
#define omFree(addr)
Definition: omAllocDecl.h:261
static long pTotaldegree(poly p)
Definition: polys.h:264
static BOOLEAN jjHOMOG_P_W(leftv res, leftv u, leftv v, leftv)
Definition: iparith.cc:5790
BOOLEAN setOption(leftv res, leftv v)
Definition: misc_ip.cc:575
omInfo_t om_Info
Definition: omStats.c:13
static BOOLEAN jjDIFF_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:1846
int scMult0Int(ideal S, ideal Q, const ring tailRing)
Definition: hdegree.cc:919
#define assume(x)
Definition: mod2.h:394
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:404
poly pSubstPar(poly p, int par, poly image)
Definition: maps_ip.cc:253
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 &#39;a&#39; and &#39;b&#39;, i.e., a+b
Definition: coeffs.h:660
static BOOLEAN jjRPAR(leftv res, leftv v)
Definition: iparith.cc:4758
static BOOLEAN jjERROR(leftv, leftv u)
Definition: iparith.cc:1966
static BOOLEAN jjVDIM(leftv res, leftv v)
Definition: iparith.cc:5105
static BOOLEAN jjEQUAL_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1332
static BOOLEAN jjJET4(leftv res, leftv u)
Definition: iparith.cc:7176
void scDegree(ideal S, intvec *modulweight, ideal Q)
Definition: hdegree.cc:822
static BOOLEAN jjOP_IM_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:310
#define nInpNeg(n)
Definition: numbers.h:21
static BOOLEAN jjLEADEXP(leftv res, leftv v)
Definition: iparith.cc:4353
Definition: tok.h:180
int scDimInt(ideal S, ideal Q)
Definition: hdegree.cc:72
static BOOLEAN jjSLIM_GB(leftv res, leftv u)
Definition: iparith.cc:4763
matrix mp_MultI(matrix a, int f, const ring R)
c = f*a
Definition: matpol.cc:142
proc2 p
Definition: iparith.cc:158
#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:276
static BOOLEAN jjDIVISION4(leftv res, leftv v)
Definition: iparith.cc:6585
static BOOLEAN jjKBASE(leftv res, leftv v)
Definition: iparith.cc:4326
#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:73
#define nMult(n1, n2)
Definition: numbers.h:17
static FORCE_INLINE BOOLEAN n_DivBy(number a, number b, const coeffs r)
test whether &#39;a&#39; is divisible &#39;b&#39;; for r encoding a field: TRUE iff &#39;b&#39; does not represent zero in Z:...
Definition: coeffs.h:787
static FORCE_INLINE number n_ChineseRemainderSym(number *a, number *b, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs r)
Definition: coeffs.h:798
static BOOLEAN jjVARSTR1(leftv res, leftv v)
Definition: iparith.cc:5088
static BOOLEAN jjREDUCE5(leftv res, leftv u)
Definition: iparith.cc:7504
pNormalize(P.p)
static BOOLEAN jjELIMIN(leftv res, leftv u, leftv v)
Definition: iparith.cc:1941
static BOOLEAN jjLIFTSTD_4(leftv res, leftv U)
Definition: iparith.cc:7342
static BOOLEAN jjSTD_HILB_W(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6480
const ring R
Definition: DebugPrint.cc:36
static BOOLEAN jjLIFT3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6364
BOOLEAN sm_CheckDet(ideal I, int d, BOOLEAN sw, const ring r)
Definition: sparsmat.cc:304
static BOOLEAN jjMONOM(leftv res, leftv v)
Definition: iparith.cc:2606
const char feNotImplemented[]
Definition: reporter.cc:54
void id_DelEquals(ideal id, const ring r)
ideal id = (id[i]) if id[i] = id[j] then id[j] is deleted for j > i
static BOOLEAN jjTIMES_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:933
BOOLEAN jjUNIQLIST(leftv, leftv arg)
Definition: iparith.cc:9405
static BOOLEAN jjMOD_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:2538
static BOOLEAN jjBRACK_Ma_IV_I(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5500
long kHomModDeg(poly p, ring r)
Definition: kstd1.cc:2218
static FORCE_INLINE char * nCoeffName(const coeffs cf)
Definition: coeffs.h:980
Definition: grammar.cc:269
static BOOLEAN jjPREIMAGE(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6065
void makeVector()
Definition: intvec.h:94
static BOOLEAN jjKLAMMER_PL(leftv res, leftv u)
Definition: iparith.cc:7259
omBin sSubexpr_bin
Definition: subexpr.cc:49
ideal kInterRed(ideal F, ideal Q)
Definition: kstd1.cc:3542
ideal id_Power(ideal given, int exp, const ring r)
#define SIMPL_NORM
Definition: iparith.cc:3161
BOOLEAN(* proc3)(leftv, leftv, leftv, leftv)
Definition: iparith.cc:166
ideal t_rep_gb(const ring r, ideal arg_I, int syz_comp, BOOLEAN F4_mode)
Definition: tgb.cc:3558
static BOOLEAN jjSTATUS_M(leftv res, leftv v)
Definition: iparith.cc:7759
static BOOLEAN jjDEG_M_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1810
ip_smatrix * matrix
static BOOLEAN jjDET(leftv res, leftv v)
Definition: iparith.cc:3801
BOOLEAN jjLOAD_TRY(const char *s)
Definition: iparith.cc:5223
static BOOLEAN jjSUBST_P(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6214
static BOOLEAN jjLIFTSTD(leftv res, leftv u, leftv v)
Definition: iparith.cc:2464
static BOOLEAN jjRES(leftv res, leftv u, leftv v)
Definition: iparith.cc:3003
static BOOLEAN jjINDEX_V_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1503
static BOOLEAN jjSTRING_PL(leftv res, leftv v)
Definition: iparith.cc:7574
static BOOLEAN jjRANK1(leftv res, leftv v)
Definition: iparith.cc:4700
static BOOLEAN jjHOMOG_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:2320
idhdl currRingHdl
Definition: ipid.cc:65
static BOOLEAN jjDIV_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1190
void Copy(leftv e)
Definition: subexpr.cc:688
BOOLEAN idInsertPoly(ideal h1, poly h2)
insert h2 into h1 (if h2 is not the zero polynomial) return TRUE iff h2 was indeed inserted ...
#define setFlag(A, F)
Definition: ipid.h:110
static BOOLEAN jjEXTGCD_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:2016
int cols() const
Definition: bigintmat.h:145
static BOOLEAN jjLEADCOEF(leftv res, leftv v)
Definition: iparith.cc:4340
#define pSetComp(p, v)
Definition: polys.h:38
static BOOLEAN jjSBA_2(leftv res, leftv v, leftv u, leftv t)
Definition: iparith.cc:4859
void atSet(idhdl root, char *name, void *data, int typ)
Definition: attrib.cc:158
struct sValCmd2 * psValCmd2
Definition: iparith.cc:190
#define pJet(p, m)
Definition: polys.h:350
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:1677
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:561
short ref
Definition: idrec.h:46
#define pIsConstant(p)
like above, except that Comp might be != 0
Definition: polys.h:221
static BOOLEAN jjSBA(leftv res, leftv v)
Definition: iparith.cc:4807
void hnf()
transforms INPLACE to HNF
Definition: bigintmat.cc:1668
static BOOLEAN jjREGULARITY(leftv res, leftv v)
Definition: iparith.cc:4711
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:172
static BOOLEAN jjDEFINED(leftv res, leftv v)
Definition: iparith.cc:3772
static BOOLEAN jjidVec2Ideal(leftv res, leftv v)
Definition: iparith.cc:5256
struct sValCmdM * psValCmdM
Definition: iparith.cc:192
static int si_max(const int a, const int b)
Definition: auxiliary.h:120
static BOOLEAN jjGE_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1105
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
Definition: coeffs.h:935
static BOOLEAN jjREDUCE_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:2868
idrec * idhdl
Definition: ring.h:18
#define ZERODIVISOR_MASK
Definition: iparith.cc:105
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:47
static BOOLEAN jjMINUS_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:876
FILE * f
Definition: checklibs.c:9
int p_Compare(const poly a, const poly b, const ring R)
Definition: p_polys.cc:4760
BOOLEAN assumeStdFlag(leftv h)
Definition: subexpr.cc:1474
static BOOLEAN jjOP_I_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:306
static BOOLEAN jjFAREY_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:2113
static BOOLEAN jjRESERVED0(leftv, leftv)
Definition: iparith.cc:7553
omBin sleftv_bin
Definition: subexpr.cc:50
int i
Definition: cfEzgcd.cc:123
ring rInit(leftv pn, leftv rv, leftv ord)
Definition: ipshell.cc:5524
static BOOLEAN jjENVELOPE(leftv res, leftv a)
Definition: iparith.cc:5002
static BOOLEAN jjPFAC2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3123
void PrintS(const char *s)
Definition: reporter.cc:284
static BOOLEAN jjDEG_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1821
lib_types
Definition: mod_raw.h:16
static BOOLEAN jjRINGLIST(leftv res, leftv v)
Definition: iparith.cc:4721
lists ipNameList(idhdl root)
Definition: ipid.cc:533
static BOOLEAN rField_is_Q(const ring r)
Definition: ring.h:501
static BOOLEAN jjCALL1ARG(leftv res, leftv v)
Definition: iparith.cc:6546
static BOOLEAN jjLOAD2(leftv, leftv, leftv v)
Definition: iparith.cc:2474
static BOOLEAN jjidTransp(leftv res, leftv v)
Definition: iparith.cc:5329
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos=-1)
Definition: iparith.cc:9067
lists rDecompose(const ring r)
Definition: ipshell.cc:2040
static long p_MinComp(poly p, ring lmRing, ring tailRing)
Definition: p_polys.h:308
char libnamebuf[1024]
Definition: libparse.cc:1096
BOOLEAN load_builtin(const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
Definition: iplib.cc:1206
#define SIMPL_LMEQ
Definition: iparith.cc:3157
static BOOLEAN jjSTD_HILB(leftv res, leftv u, leftv v)
Definition: iparith.cc:3265
int IsPrime(int p)
Definition: prime.cc:61
#define SIMPL_NULL
Definition: iparith.cc:3160
static BOOLEAN jjidMinBase(leftv res, leftv v)
Definition: iparith.cc:5277
#define pOne()
Definition: polys.h:297
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:3646
idhdl rFindHdl(ring r, idhdl n)
Definition: ipshell.cc:1594
int yyparse(void)
Definition: grammar.cc:2101
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:1862
static BOOLEAN jjPOWER_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:575
static BOOLEAN jjUMINUS_N(leftv res, leftv u)
Definition: iparith.cc:3537
ring rDefault(const coeffs cf, int N, char **n, int ord_size, rRingOrder_t *ord, int *block0, int *block1, int **wvhdl)
Definition: ring.cc:113
int sySize(syStrategy syzstr)
Definition: syz1.cc:1837
static BOOLEAN jjDIVISION(leftv res, leftv u, leftv v)
Definition: iparith.cc:1900
static BOOLEAN jjFWALK(leftv res, leftv u, leftv v)
Definition: iparith.cc:2244
static BOOLEAN jjREDUCE3_CP(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6389
static BOOLEAN jjINTERSECT(leftv res, leftv u, leftv v)
Definition: iparith.cc:2386
static unsigned pLength(poly a)
Definition: p_polys.h:189
static BOOLEAN jjREDUCE3_P(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6413
#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:5299
static BOOLEAN jjTYPEOF(leftv res, leftv v)
Definition: iparith.cc:5023
static BOOLEAN jjINDEX_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1369
#define IDELEMS(i)
Definition: simpleideals.h:24
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff &#39;n&#39; represents the zero element.
Definition: coeffs.h:468
static BOOLEAN jjFactModD_M(leftv res, leftv v)
Definition: iparith.cc:7627
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:725
lists scIndIndset(ideal S, BOOLEAN all, ideal Q)
Definition: ipshell.cc:1022
#define atKill(H, A)
Definition: attrib.h:44
int lSize(lists L)
Definition: lists.cc:25
void(* WerrorS_callback)(const char *s)
Definition: feFopen.cc:21
#define V_DEG_STOP
Definition: options.h:67
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
void iiMakeResolv(resolvente r, int length, int rlen, char *name, int typ0, intvec **weights)
Definition: ipshell.cc:766
static BOOLEAN jjPLUS_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:788
#define IDLEV(a)
Definition: ipid.h:118
char * SPrintEnd()
Definition: reporter.cc:273
resolvente fullres
Definition: syz.h:57
#define TRACE_CALL
Definition: reporter.h:43
#define nDelete(n)
Definition: numbers.h:16
#define IDMAP(a)
Definition: ipid.h:132
#define FLAG_STD
Definition: ipid.h:106
static BOOLEAN jjLISTRING(leftv res, leftv v)
Definition: iparith.cc:4390
static BOOLEAN jjOPTION_PL(leftv res, leftv v)
Definition: iparith.cc:7430
BOOLEAN rHasMixedOrdering(const ring r)
Definition: ring.h:753
poly p_Series(int n, poly p, poly u, intvec *w, const ring R)
Definition: p_polys.cc:4353
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:3785
static BOOLEAN jjIS_RINGVAR_P(leftv res, leftv v)
Definition: iparith.cc:4257
ideal idCopy(ideal A)
Definition: ideals.h:60
static BOOLEAN jjrOrdStr(leftv res, leftv v)
Definition: iparith.cc:5304
static BOOLEAN jjNAMES(leftv res, leftv v)
Definition: iparith.cc:4529
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:2264
short errorreported
Definition: feFopen.cc:23
ideal idLiftStd(ideal h1, matrix *ma, tHomog hi, ideal *syz, GbVariant alg)
Definition: ideals.cc:750
leftv next
Definition: subexpr.h:86
static BOOLEAN jjBRACK_S(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5350
void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg)
Definition: p_polys.cc:3555
static FORCE_INLINE number n_ImPart(number i, const coeffs cf)
Definition: coeffs.h:827
void test_cmd(int i)
Definition: ipshell.cc:506
void rChangeCurrRing(ring r)
Definition: polys.cc:12
static BOOLEAN jjFIND2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2227
static BOOLEAN jjFETCH_M(leftv res, leftv u)
Definition: iparith.cc:6778
static BOOLEAN jjMOD_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:2549
resolvente minres
Definition: syz.h:58
static BOOLEAN rField_is_Zp(const ring r)
Definition: ring.h:495
static FORCE_INLINE number n_Farey(number a, number b, const coeffs r)
Definition: coeffs.h:801
ideal idSyzygies(ideal h1, tHomog h, intvec **w, BOOLEAN setSyzComp, BOOLEAN setRegularity, int *deg, GbVariant alg)
Definition: ideals.cc:562
intvec * ivMult(intvec *a, intvec *b)
Definition: intvec.cc:332
ideal idSubstPoly(ideal id, int n, poly e)
Definition: maps_ip.cc:406
static BOOLEAN jjBAREISS3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5620
static BOOLEAN jjSIMPL_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:3253
#define BVERBOSE(a)
Definition: options.h:33
short start
Definition: iparith.cc:132
void p_Shift(poly *p, int i, const ring r)
shifts components of the vector p by i
Definition: p_polys.cc:4561
#define NO_ZERODIVISOR
Definition: iparith.cc:115
static BOOLEAN jjDIM(leftv res, leftv v)
Definition: iparith.cc:3882
INLINE_THIS void Init(int l=0)
static BOOLEAN jjCOEFFS3_KB(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5659
BOOLEAN(* proc2)(leftv, leftv, leftv)
Definition: iparith.cc:155
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition: matpol.cc:44
#define TEST_OPT_RETURN_SB
Definition: options.h:107
#define nInvers(a)
Definition: numbers.h:33
Definition: tok.h:34
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:843
matrix mp_MultP(matrix a, poly p, const ring R)
multiply a matrix &#39;a&#39; by a poly &#39;p&#39;, destroy the args
Definition: matpol.cc:155
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
static BOOLEAN jjOP_IV_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:289
static BOOLEAN jjTIMES_MA_P1(leftv res, leftv u, leftv v)
Definition: iparith.cc:1036
static BOOLEAN jjINDEX_V(leftv res, leftv u, leftv v)
Definition: iparith.cc:1473
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:697
static BOOLEAN jjNEWSTRUCT2(leftv, leftv u, leftv v)
Definition: iparith.cc:2630
#define p_SetmComp
Definition: p_polys.h:239
#define SI_RESTORE_OPT2(A)
Definition: options.h:24
static BOOLEAN jjCOMPARE_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:459
static BOOLEAN jjSQR_FREE2(leftv res, leftv u, leftv dummy)
Definition: iparith.cc:3195
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:38
static BOOLEAN jjGCD_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:2288
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:2693
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
static BOOLEAN jjEXECUTE(leftv, leftv v)
Definition: iparith.cc:3984
#define pSeries(n, p, u, w)
Definition: polys.h:354
BOOLEAN iiMake_proc(idhdl pn, package pack, leftv sl)
Definition: iplib.cc:503
static BOOLEAN jjidMaxIdeal(leftv res, leftv v)
Definition: iparith.cc:4177
unsigned nLastIdentifier
valid indentifieres are slot 1..nLastIdentifier
Definition: iparith.cc:195
ring rCopy(ring r)
Definition: ring.cc:1614
matrix mp_Mult(matrix a, matrix b, const ring R)
Definition: matpol.cc:220
int singclap_factorize_retry
Definition: iparith.cc:3194
static BOOLEAN jjMINRES_R(leftv res, leftv v)
Definition: iparith.cc:4490
static BOOLEAN jjPlural_num_mat(leftv res, leftv a, leftv b)
Definition: iparith.cc:2675
static BOOLEAN jjCOEFFS3_P(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5665
void * atGet(idhdl root, const char *name, int t, void *defaultReturnValue)
Definition: attrib.cc:137
short res
Definition: gentable.cc:92
int nr
Definition: lists.h:43
#define nDiv(a, b)
Definition: numbers.h:32
void mp_Coef2(poly v, poly mon, matrix *c, matrix *m, const ring R)
corresponds to Macauley&#39;s coef: the exponent vector of vars has to contain the variables, eg &#39;xy&#39;; 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:512
int & cols()
Definition: matpol.h:25
static BOOLEAN jjRING_LIST(leftv res, leftv v)
Definition: iparith.cc:4735
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:636
static BOOLEAN jjPLUS_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:778
ideal id_Jet(ideal i, int d, const ring R)
CanonicalForm cf
Definition: cfModGcd.cc:4024
Definition: tok.h:130
#define MATCOLS(i)
Definition: matpol.h:28
Definition: tok.h:116
static BOOLEAN jjJET_ID_IV(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5839
BOOLEAN jjLIST_PL(leftv res, leftv v)
Definition: iparith.cc:7374
BOOLEAN iiExprArith3Tab(leftv res, leftv a, int op, const struct sValCmd3 *dA3, int at, const struct sConvertTypes *dConvertTypes)
apply an operation &#39;op&#39; to arguments a, a->next and a->next->next return TRUE on failure ...
Definition: iparith.cc:8583
static BOOLEAN jjTIMES_MA(leftv res, leftv u, leftv v)
Definition: iparith.cc:1078
void mp_Monomials(matrix c, int r, int var, matrix m, const ring R)
Definition: matpol.cc:373
#define nIsZero(n)
Definition: numbers.h:19
short res
Definition: gentable.cc:82
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:477
matrix mp_Add(matrix a, matrix b, const ring R)
Definition: matpol.cc:186
#define NULL
Definition: omList.c:10
static BOOLEAN jjJET_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:2420
int ipower(int b, int m)
int ipower ( int b, int m )
Definition: cf_util.cc:25
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:2731
static BOOLEAN jjHILBERT(leftv, leftv v)
Definition: iparith.cc:4117
ideal id_Farey(ideal x, number N, const ring r)
Definition: ideals.cc:2510
package req_packhdl
Definition: subexpr.h:106
ring syRing
Definition: syz.h:56
static BOOLEAN jjIS_RINGVAR_S(leftv res, leftv v)
Definition: iparith.cc:4262
SRes resPairs
Definition: syz.h:49
static BOOLEAN jjGT_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1123
int length() const
Definition: intvec.h:86
omBin sip_command_bin
Definition: ipid.cc:49
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:333
static BOOLEAN jjLT_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1145
GbVariant syGetAlgorithm(char *n, const ring r, const ideal)
Definition: ideals.cc:2655
static BOOLEAN jjPOWER_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:609
SModulFunc_t iiGetBuiltinModInit(const char *libname)
Definition: iplib.cc:769
static BOOLEAN jjQUOT(leftv res, leftv u, leftv v)
Definition: iparith.cc:2827
#define IDINT(a)
Definition: ipid.h:122
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:36
#define pMult(p, q)
Definition: polys.h:190
static BOOLEAN jjCOEF_M(leftv, leftv v)
Definition: iparith.cc:6570
ideal walkProc(leftv first, leftv second)
Definition: walk_ip.cc:61
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2499
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of &#39;a&#39; and &#39;b&#39;, i.e., a/b; raises an error if &#39;b&#39; is not invertible in r exceptio...
Definition: coeffs.h:619
long(* pFDegProc)(poly p, ring r)
Definition: ring.h:46
intvec * hSecondSeries(intvec *hseries1)
Definition: hilb.cc:1317
#define jjWRONG2
Definition: iparith.cc:3483
ideal kMin_std(ideal F, ideal Q, tHomog h, intvec **w, ideal &M, intvec *hilb, int syzComp, int reduced)
Definition: kstd1.cc:2822
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:6466
#define ABS(x)
Definition: auxiliary.h:111
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:831
package basePack
Definition: ipid.cc:64
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...
coeffs basecoeffs() const
Definition: bigintmat.h:147
void omUpdateInfo()
Definition: omStats.c:24
static BOOLEAN rField_is_Ring_Z(const ring r)
Definition: ring.h:474
static BOOLEAN jjCOUNT_RG(leftv res, leftv v)
Definition: iparith.cc:3720
static BOOLEAN jjUMINUS_IV(leftv res, leftv u)
Definition: iparith.cc:3555
void pNorm(poly p, const ring R=currRing)
Definition: polys.h:345
static BOOLEAN jjTIMES_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:998
#define hasFlag(A, F)
Definition: ipid.h:109
unsigned nCmdUsed
number of commands used
Definition: iparith.cc:193
static BOOLEAN jjMONITOR1(leftv res, leftv v)
Definition: iparith.cc:2561
static BOOLEAN jjMINUS_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:891
static BOOLEAN jjQRDS(leftv res, leftv INPUT)
Definition: iparith.cc:7817
void show(int mat=0, int spaces=0) const
Definition: intvec.cc:150
ideal fractalWalkProc(leftv first, leftv second)
Definition: walk_ip.cc:167
char * name
Definition: iparith.cc:139
#define pInit()
allocates a new monomial and initializes everything to 0
Definition: polys.h:61
#define IDRING(a)
Definition: ipid.h:124
static BOOLEAN jjPREIMAGE_R(leftv res, leftv v)
Definition: iparith.cc:4633
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:773
ideal id_Head(ideal h, const ring r)
returns the ideals of initial terms
static BOOLEAN jjTIMES_MA_N2(leftv res, leftv u, leftv v)
Definition: iparith.cc:1064
Definition: tok.h:96
const CanonicalForm & w
Definition: facAbsFact.cc:55
#define pWTotaldegree(p)
Definition: polys.h:265
#define pDelete(p_ptr)
Definition: polys.h:169
package currPack
Definition: ipid.cc:63
static BOOLEAN jjNAMES_I(leftv res, leftv v)
Definition: iparith.cc:4534
static BOOLEAN jjEQUAL_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:1338
proc3 p
Definition: iparith.cc:169
number singclap_det_bi(bigintmat *m, const coeffs cf)
Definition: clapsing.cc:1609
static BOOLEAN jjEXTGCD_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1973
static BOOLEAN jjNAMEOF(leftv res, leftv v)
Definition: iparith.cc:4516
static BOOLEAN jjGT_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1111
static BOOLEAN jjNVARS(leftv res, leftv v)
Definition: iparith.cc:4544
static BOOLEAN jjCOLCOL(leftv res, leftv u, leftv v)
Definition: iparith.cc:699
int cols() const
Definition: intvec.h:87
Variable x
Definition: cfModGcd.cc:4023
int rtyp
Definition: subexpr.h:91
BOOLEAN singclap_extgcd(poly f, poly g, poly &res, poly &pa, poly &pb, const ring r)
Definition: clapsing.cc:447
BOOLEAN mp_IsDiagUnit(matrix U, const ring R)
Definition: matpol.cc:725
static BOOLEAN jjRING_PL(leftv res, leftv a)
Definition: iparith.cc:7917
#define nSize(n)
Definition: numbers.h:39
#define nCopy(n)
Definition: numbers.h:15
sleftv sLastPrinted
Definition: subexpr.cc:55
static SArithBase sArithBase
Base entry for arithmetic.
Definition: iparith.cc:203
int iiArithFindCmd(const char *szName)
Definition: iparith.cc:8972
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:607
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:5772
static BOOLEAN jjUMINUS_BIM(leftv res, leftv u)
Definition: iparith.cc:3562
void CleanUp(ring r=currRing)
Definition: subexpr.cc:332
Definition: tok.h:90
static FORCE_INLINE number n_RePart(number i, const coeffs cf)
Definition: coeffs.h:824
int(* SModulFunc_t)(SModulFunctions *)
Definition: ipid.h:82
static BOOLEAN jjMONITOR2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2565
static Subexpr jjMakeSub(leftv e)
Definition: iparith.cc:7939
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:4406
static BOOLEAN jjFWALK3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5730
void * Data()
Definition: subexpr.cc:1137
static BOOLEAN jjCOUNT_BI(leftv res, leftv v)
Definition: iparith.cc:3693
static BOOLEAN jjrParStr(leftv res, leftv v)
Definition: iparith.cc:5314
static BOOLEAN jjCOLS_BIM(leftv res, leftv v)
Definition: iparith.cc:3675
static FORCE_INLINE BOOLEAN n_Equal(number a, number b, const coeffs r)
TRUE iff &#39;a&#39; and &#39;b&#39; represent the same number; they may have different representations.
Definition: coeffs.h:464
static BOOLEAN jjLE_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1132
static BOOLEAN jjSYZYGY(leftv res, leftv v)
Definition: iparith.cc:4933
lists rDecompose_list_cf(const ring r)
Definition: ipshell.cc:1909
static BOOLEAN jjLIFTSTD3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6376
int typ
Definition: idrec.h:43
short list_length
Definition: syz.h:62
#define pSetCoeff0(p, n)
Definition: monomials.h:67
static BOOLEAN jjCHINREM_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:9169
Definition: tok.h:117
BOOLEAN mp_Equal(matrix a, matrix b, const ring R)
Definition: matpol.cc:593
static BOOLEAN jjDIFF_ID_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:1857
matrix mp_Copy(matrix a, const ring r)
copies matrix a (from ring r to r)
Definition: matpol.cc:71
static BOOLEAN jjDIFF_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:1835
static BOOLEAN jjELIMIN_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1947
ideal * resolvente
Definition: ideals.h:18
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition: fevoices.cc:171
void SPrintStart()
Definition: reporter.cc:246
void sm_CallBareiss(ideal I, int x, int y, ideal &M, intvec **iv, const ring R)
Definition: sparsmat.cc:400
static FORCE_INLINE number n_SubringGcd(number a, number b, const coeffs r)
Definition: coeffs.h:692
static BOOLEAN jjBAREISS_BIM(leftv res, leftv v)
Definition: iparith.cc:3618
static BOOLEAN jjRING_1(leftv res, leftv u, leftv v)
Definition: iparith.cc:1653
static BOOLEAN jjCALL1MANY(leftv res, leftv u)
Definition: iparith.cc:3661
const char * id
Definition: idrec.h:39
static BOOLEAN jjTIMES_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:943
static BOOLEAN jjROWS_BIM(leftv res, leftv v)
Definition: iparith.cc:4748
attr attribute
Definition: subexpr.h:89
omBin slists_bin
Definition: lists.cc:23
static BOOLEAN jjLE_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1128
ideal maGetPreimage(ring theImageRing, map theMap, ideal id, const ring dst_r)
Definition: preimage.cc:61
static BOOLEAN jjINDEX_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1391
static BOOLEAN jjSBA_1(leftv res, leftv v, leftv u)
Definition: iparith.cc:4833
static BOOLEAN jjMINUS_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:881
static BOOLEAN jjPOWER_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:591
cmdnames * sCmds
array of existing commands
Definition: iparith.cc:188
#define ii_div_by_0
Definition: iparith.cc:222
int idElem(const ideal F)
count non-zero elements
#define NO_CONVERSION
Definition: iparith.cc:124
#define pPower(p, q)
Definition: polys.h:187
static FORCE_INLINE BOOLEAN nCoeff_is_Extension(const coeffs r)
Definition: coeffs.h:863
static BOOLEAN jjMATRIX_Mo(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6325
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2439
static BOOLEAN jjidHead(leftv res, leftv v)
Definition: iparith.cc:5271
void newstruct_setup(const char *n, newstruct_desc d)
Definition: newstruct.cc:692
static BOOLEAN jjOP_I_IM(leftv res, leftv u, leftv v)
Definition: iparith.cc:325
static BOOLEAN jjSort_Id(leftv res, leftv v)
Definition: iparith.cc:4911
int mp_Compare(matrix a, matrix b, const ring R)
Definition: matpol.cc:574
static BOOLEAN jjJET_P_P(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5829
newstruct_desc newstructChildFromString(const char *parent, const char *s)
Definition: newstruct.cc:803
leftv iiMap(map theMap, const char *what)
Definition: ipshell.cc:607
int n_IsParam(const number m, const ring r)
TODO: rewrite somehow...
Definition: ring.cc:5644
static BOOLEAN jjPOWER_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:529
static BOOLEAN jjCOMPARE_IV_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:404
static BOOLEAN jjPLUSPLUS(leftv, leftv u)
Definition: iparith.cc:3513
BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char *newlib, idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
Definition: iplib.cc:933
#define pDiff(a, b)
Definition: polys.h:278
const struct sValCmd1 dArith1[]
Definition: table.h:19
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete &#39;p&#39;
Definition: coeffs.h:459
#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:622
static BOOLEAN jjFACSTD2(leftv res, leftv v, leftv w)
Definition: iparith.cc:2080
static FORCE_INLINE BOOLEAN n_GreaterZero(number n, const coeffs r)
ordered fields: TRUE iff &#39;n&#39; 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)/<p(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:498
#define SI_PROT_O
Definition: reporter.h:53
const char * getBlackboxName(const int t)
return the name to the type given by t (r/o)
Definition: blackbox.cc:185
ideal idLift(ideal mod, ideal submod, ideal *rest, BOOLEAN goodShape, BOOLEAN isSB, BOOLEAN divide, matrix *unit, GbVariant alg)
Definition: ideals.cc:938
ideal singclap_factorize(poly f, intvec **v, int with_exps, const ring r)
Definition: clapsing.cc:771
ideal idAdd(ideal h1, ideal h2)
h1 + h2
Definition: ideals.h:68
#define pIsUnivariate(p)
Definition: polys.h:232
Definition: tok.h:166
static BOOLEAN jjREDUCE4(leftv res, leftv u)
Definition: iparith.cc:7440
proc1 p
Definition: iparith.cc:179
static BOOLEAN jjUNIVARIATE(leftv res, leftv v)
Definition: iparith.cc:5066
#define MATROWS(i)
Definition: matpol.h:27
static BOOLEAN jjIDEAL_Ma(leftv res, leftv v)
Definition: iparith.cc:4183
static BOOLEAN jjSTATUS3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6471
static BOOLEAN jjIDEAL_R(leftv res, leftv v)
Definition: iparith.cc:4211
intvec * hFirstSeries(ideal S, intvec *modulweight, ideal Q, intvec *wdegree, ring tailRing)
Definition: hilb.cc:1309
ideal id_Vec2Ideal(poly vec, const ring R)
matrix mp_Sub(matrix a, matrix b, const ring R)
Definition: matpol.cc:203
static BOOLEAN jjDEG(leftv res, leftv v)
Definition: iparith.cc:3734
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:976
kBucketDestroy & P
Definition: myNF.cc:191
int iiTokType(int op)
Definition: iparith.cc:239
void hLookSeries(ideal S, intvec *modulweight, ideal Q, intvec *wdegree, ring tailRing)
Definition: hilb.cc:1388
static BOOLEAN jjCOUNT_L(leftv res, leftv v)
Definition: iparith.cc:3703
static jList * T
Definition: janet.cc:37
polyrec * poly
Definition: hilb.h:10
static BOOLEAN jjMATRIX_Id(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6302
static int iin_Int(number &n, coeffs cf)
Definition: iparith.cc:227
#define IDDATA(a)
Definition: ipid.h:123
static BOOLEAN jjOR_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1364
int Kstd1_deg
Definition: kutil.cc:236
static BOOLEAN jjMINUS_MA(leftv res, leftv u, leftv v)
Definition: iparith.cc:901
void rSetHdl(idhdl h)
Definition: ipshell.cc:5038
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
static BOOLEAN jjLU_SOLVE(leftv res, leftv v)
Definition: iparith.cc:7062
BOOLEAN rDecompose_CF(leftv res, const coeffs C)
Definition: ipshell.cc:1838
BOOLEAN(* proc1)(leftv, leftv)
Definition: ipshell.h:120
static BOOLEAN jjpMaxComp(leftv res, leftv v)
Definition: iparith.cc:5289
#define pISet(i)
Definition: polys.h:294
#define nInit(i)
Definition: numbers.h:24
char * iiConvName(const char *libname)
Definition: iplib.cc:1340
syStrategy syHilb(ideal arg, int *length)
Definition: syz2.cc:956
int iiOp
Definition: iparith.cc:224
unsigned si_opt_2
Definition: options.c:6
static BOOLEAN jjBRACK_Ma(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5421
static Poly * h
Definition: janet.cc:978
int compare(const bigintmat *op) const
Definition: bigintmat.cc:363
int BOOLEAN
Definition: auxiliary.h:85
static BOOLEAN jjPlural_num_poly(leftv res, leftv a, leftv b)
Definition: iparith.cc:2655
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:3794
static BOOLEAN jjNOT(leftv res, leftv v)
Definition: iparith.cc:4539
#define IMATELEM(M, I, J)
Definition: intvec.h:77
const poly b
Definition: syzextra.cc:213
BOOLEAN iiExprArith2(leftv res, leftv a, int op, leftv b, BOOLEAN proccall)
Definition: iparith.cc:8130
static BOOLEAN jjHOMOG_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:2337
#define omRealloc(addr, size)
Definition: omAllocDecl.h:225
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2755
#define NONE
Definition: tok.h:216
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition: polys.h:31
void syMake(leftv v, const char *id, package pa)
Definition: subexpr.cc:1500
static BOOLEAN jjRESERVEDNAME(leftv res, leftv v)
Definition: iparith.cc:4685
#define ppJetW(p, m, iv)
Definition: polys.h:351
#define SI_RESTORE_OPT1(A)
Definition: options.h:23
static BOOLEAN jjINDEPSET(leftv res, leftv v)
Definition: iparith.cc:4240
BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition: iplib.cc:1108
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:574
static BOOLEAN jjDET_I(leftv res, leftv v)
Definition: iparith.cc:3852
ideal id_Matrix2Module(matrix mat, const ring R)
static BOOLEAN jjTRANSP_BIM(leftv res, leftv v)
Definition: iparith.cc:4976
static BOOLEAN jjOPPOSITE(leftv res, leftv a)
Definition: iparith.cc:4987
static BOOLEAN jjCONTRACT(leftv res, leftv u, leftv v)
Definition: iparith.cc:1805
static BOOLEAN jjHIGHCORNER(leftv res, leftv v)
Definition: iparith.cc:4063
proc1 p
Definition: iparith.cc:148
static ideal idMult(ideal h1, ideal h2)
hh := h1 * h2
Definition: ideals.h:84
leftv LData()
Definition: subexpr.cc:1406
struct sValCmd3 * psValCmd3
Definition: iparith.cc:191
char * rOrdStr(ring r)
Definition: ring.cc:522
void Werror(const char *fmt,...)
Definition: reporter.cc:189
static BOOLEAN jjAND_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1359
BOOLEAN iiExprArith1Tab(leftv res, leftv a, int op, const struct sValCmd1 *dA1, int at, const struct sConvertTypes *dConvertTypes)
apply an operation &#39;op&#39; to an argument a return TRUE on failure
Definition: iparith.cc:8189
#define nAdd(n1, n2)
Definition: numbers.h:18
syStrategy syLaScala3(ideal arg, int *length)
Definition: syz1.cc:2434
static BOOLEAN jjREAD(leftv res, leftv v)
Definition: iparith.cc:4707
int ivTrace(intvec *o)
Definition: intvec.cc:322
void * CopyD(int t)
Definition: subexpr.cc:707
static BOOLEAN jjCHAR(leftv res, leftv v)
Definition: iparith.cc:3665
const char * lastreserved
Definition: ipshell.cc:80
static BOOLEAN jjEQUAL_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1314
static BOOLEAN jjLEADMONOM(leftv res, leftv v)
Definition: iparith.cc:4371
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:845
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:3162
static BOOLEAN jjELIMIN_HILB(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5692
intvec * ivAdd(intvec *a, intvec *b)
Definition: intvec.cc:250
static BOOLEAN jjstrlen(leftv res, leftv v)
Definition: iparith.cc:5236
static BOOLEAN jjFETCH(leftv res, leftv u, leftv v)
Definition: iparith.cc:2121
ideal syMinBase(ideal arg)
Definition: syz.cc:1025
static BOOLEAN jjTWOSTD(leftv res, leftv a)
Definition: iparith.cc:5013
static BOOLEAN jjSTD_HILB_WP(leftv res, leftv INPUT)
Definition: iparith.cc:7834
static BOOLEAN jjDIFF_COEF(leftv res, leftv u, leftv v)
Definition: iparith.cc:4285
static BOOLEAN jjSTATUS2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3242
static BOOLEAN jjORD(leftv res, leftv v)
Definition: iparith.cc:4555
long rank
Definition: matpol.h:20
static BOOLEAN jjFIND3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5699
static BOOLEAN jjDIV_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1177
static BOOLEAN jjCOLS_IV(leftv res, leftv v)
Definition: iparith.cc:3680
syStrategy syMinimize(syStrategy syzstr)
Definition: syz1.cc:2402
#define IDMATRIX(a)
Definition: ipid.h:131
#define nGreater(a, b)
Definition: numbers.h:28
#define pCopy(p)
return a copy of the poly
Definition: polys.h:168
#define COMMAND
Definition: tok.h:29
#define MATELEM(mat, i, j)
Definition: matpol.h:29
#define RING_MASK
Definition: iparith.cc:104
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:16
#define V_IMAP
Definition: options.h:51
ssyStrategy * syStrategy
Definition: syz.h:35
#define idTest(id)
Definition: ideals.h:47
utypes data
Definition: idrec.h:40
static BOOLEAN jjCOMPARE_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:376
#define SI_SAVE_OPT2(A)
Definition: options.h:21
int IsCmd(const char *n, int &tok)
Definition: iparith.cc:8729
static BOOLEAN jjHILBERT3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5739
ListNode * next
Definition: janet.h:31
static BOOLEAN jjRANDOM_Im(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6139
static BOOLEAN jjLT_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1150
static BOOLEAN jjidElem(leftv res, leftv v)
Definition: iparith.cc:5246
static BOOLEAN jjCOEFFS3_Id(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5645
#define Warn
Definition: emacs.cc:80
ideal twostd(ideal I)
Compute two-sided GB:
Definition: nc.cc:21
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define idIsConstant(I)
Definition: ideals.h:40