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