iparith.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 
5 /*
6 * ABSTRACT: table driven kernel interface, used by interpreter
7 */
8 
9 
10 #include <kernel/mod2.h>
11 
12 #include <omalloc/omalloc.h>
13 
14 #include <factory/factory.h>
15 
16 #include <coeffs/bigintmat.h>
17 #include <coeffs/coeffs.h>
18 #include <coeffs/numbers.h>
19 
20 
21 #include <misc/options.h>
22 #include <misc/intvec.h>
23 #include <misc/sirandom.h>
24 #include <misc/prime.h>
25 
26 #include <polys/prCopy.h>
27 #include <polys/matpol.h>
28 #include <polys/monomials/maps.h>
29 #include <polys/sparsmat.h>
30 #include <polys/weight.h>
32 #include <polys/clapsing.h>
33 
36 
40 
41 #include <kernel/spectrum/GMPrat.h>
43 #include <kernel/oswrapper/timer.h>
44 #include <kernel/fglm/fglm.h>
45 
47 #include <kernel/GBEngine/syz.h>
48 #include <kernel/GBEngine/kstd1.h>
49 #include <kernel/GBEngine/units.h>
50 #include <kernel/GBEngine/tgb.h>
51 
52 #include <kernel/preimage.h>
53 #include <kernel/polys.h>
54 #include <kernel/ideals.h>
55 
56 #include <Singular/mod_lib.h>
57 #include <Singular/fevoices.h>
58 #include <Singular/tok.h>
59 #include <Singular/ipid.h>
60 #include <Singular/sdb.h>
61 #include <Singular/subexpr.h>
62 #include <Singular/lists.h>
63 #include <Singular/maps_ip.h>
64 
65 #include <Singular/ipconv.h>
66 #include <Singular/ipprint.h>
67 #include <Singular/attrib.h>
68 #include <Singular/links/silink.h>
69 #include <Singular/misc_ip.h>
71 
72 #include <Singular/number2.h>
73 
74 # include <Singular/fglm.h>
75 
76 #include <Singular/blackbox.h>
77 #include <Singular/newstruct.h>
78 #include <Singular/ipshell.h>
79 //#include <kernel/mpr_inout.h>
80 #include <reporter/si_signals.h>
81 
82 #include <stdlib.h>
83 #include <string.h>
84 #include <ctype.h>
85 #include <stdio.h>
86 #include <time.h>
87 #include <unistd.h>
88 #include <vector>
89 
90 ring rCompose(const lists L, const BOOLEAN check_comp=TRUE);
91 
92 // defaults for all commands: NO_PLURAL | NO_RING | ALLOW_ZERODIVISOR
93 
94 #ifdef HAVE_PLURAL
96  #include <kernel/GBEngine/nc.h>
97  #include <polys/nc/nc.h>
98  #include <polys/nc/sca.h>
99  #define PLURAL_MASK 3
100 #else /* HAVE_PLURAL */
101  #define PLURAL_MASK 0
102 #endif /* HAVE_PLURAL */
103 
104 #ifdef HAVE_RINGS
105  #define RING_MASK 4
106  #define ZERODIVISOR_MASK 8
107 #else
108  #define RING_MASK 0
109  #define ZERODIVISOR_MASK 0
110 #endif
111 #define ALLOW_PLURAL 1
112 #define NO_PLURAL 0
113 #define COMM_PLURAL 2
114 #define ALLOW_RING 4
115 #define NO_RING 0
116 #define NO_ZERODIVISOR 8
117 #define ALLOW_ZERODIVISOR 0
118 
119 #define ALLOW_ZZ (ALLOW_RING|NO_ZERODIVISOR)
120 
121 
122 // bit 4 for warning, if used at toplevel
123 #define WARN_RING 16
124 // bit 5: do no try automatic conversions
125 #define NO_CONVERSION 32
126 
127 static BOOLEAN check_valid(const int p, const int op);
128 
129 /*=============== types =====================*/
131 {
132  short cmd;
133  short start;
134 };
135 
137 
138 struct _scmdnames
139 {
140  char *name;
141  short alias;
142  short tokval;
143  short toktype;
144 };
145 typedef struct _scmdnames cmdnames;
146 
147 struct sValCmd1
148 {
150  short cmd;
151  short res;
152  short arg;
153  short valid_for;
154 };
155 
157 struct sValCmd2
158 {
160  short cmd;
161  short res;
162  short arg1;
163  short arg2;
164  short valid_for;
165 };
166 
168 struct sValCmd3
169 {
171  short cmd;
172  short res;
173  short arg1;
174  short arg2;
175  short arg3;
176  short valid_for;
177 };
178 struct sValCmdM
179 {
181  short cmd;
182  short res;
183  short number_of_args; /* -1: any, -2: any >0, .. */
184  short valid_for;
185 };
186 
187 typedef struct
188 {
189  cmdnames *sCmds; /**< array of existing commands */
194  unsigned nCmdUsed; /**< number of commands used */
195  unsigned nCmdAllocated; /**< number of commands-slots allocated */
196  unsigned nLastIdentifier; /**< valid indentifieres are slot 1..nLastIdentifier */
197 } SArithBase;
198 
199 /*---------------------------------------------------------------------*
200  * File scope Variables (Variables share by several functions in
201  * the same file )
202  *
203  *---------------------------------------------------------------------*/
204 static SArithBase sArithBase; /**< Base entry for arithmetic */
205 
206 /*---------------------------------------------------------------------*
207  * Extern Functions declarations
208  *
209  *---------------------------------------------------------------------*/
210 static int _gentable_sort_cmds(const void *a, const void *b);
211 extern int iiArithRemoveCmd(char *szName);
212 extern int iiArithAddCmd(const char *szName, short nAlias, short nTokval,
213  short nToktype, short nPos=-1);
214 
215 /*============= proc =======================*/
216 static int iiTabIndex(const jjValCmdTab dArithTab, const int len, const int op);
217 static Subexpr jjMakeSub(leftv e);
218 
219 /*============= vars ======================*/
220 extern int cmdtok;
221 extern BOOLEAN expected_parms;
222 
223 #define ii_div_by_0 "div. by 0"
224 
225 int iiOp; /* the current operation*/
226 
227 /*=================== simple helpers =================*/
228 static int iin_Int(number &n,coeffs cf)
229 {
230  long l=n_Int(n,cf);
231  int i=(int)l;
232  if ((long)i==l) return l;
233  return 0;
234 }
236 {
237  return pHead(p);
238 }
239 
240 int iiTokType(int op)
241 {
242  for (unsigned i=0;i<sArithBase.nCmdUsed;i++)
243  {
244  if (sArithBase.sCmds[i].tokval==op)
245  return sArithBase.sCmds[i].toktype;
246  }
247  return 0;
248 }
249 
250 /*=================== operations with 2 args.: static proc =================*/
251 /* must be ordered: first operations for chars (infix ops),
252  * then alphabetically */
253 
255 {
256  bigintmat* aa= (bigintmat *)u->Data();
257  int bb = (int)(long)(v->Data());
258  if (errorreported) return TRUE;
259  bigintmat *cc=NULL;
260  switch (iiOp)
261  {
262  case '+': cc=bimAdd(aa,bb); break;
263  case '-': cc=bimSub(aa,bb); break;
264  case '*': cc=bimMult(aa,bb); break;
265  }
266  res->data=(char *)cc;
267  return cc==NULL;
268 }
270 {
271  return jjOP_BIM_I(res, v, u);
272 }
274 {
275  bigintmat* aa= (bigintmat *)u->Data();
276  number bb = (number)(v->Data());
277  if (errorreported) return TRUE;
278  bigintmat *cc=NULL;
279  switch (iiOp)
280  {
281  case '*': cc=bimMult(aa,bb,coeffs_BIGINT); break;
282  }
283  res->data=(char *)cc;
284  return cc==NULL;
285 }
287 {
288  return jjOP_BIM_BI(res, v, u);
289 }
291 {
292  intvec* aa= (intvec *)u->CopyD(INTVEC_CMD);
293  int bb = (int)(long)(v->Data());
294  if (errorreported) return TRUE;
295  switch (iiOp)
296  {
297  case '+': (*aa) += bb; break;
298  case '-': (*aa) -= bb; break;
299  case '*': (*aa) *= bb; break;
300  case '/':
301  case INTDIV_CMD: (*aa) /= bb; break;
302  case '%': (*aa) %= bb; break;
303  }
304  res->data=(char *)aa;
305  return FALSE;
306 }
308 {
309  return jjOP_IV_I(res,v,u);
310 }
312 {
313  intvec* aa= (intvec *)u->CopyD(INTVEC_CMD);
314  int bb = (int)(long)(v->Data());
315  int i=si_min(aa->rows(),aa->cols());
316  switch (iiOp)
317  {
318  case '+': for (;i>0;i--) IMATELEM(*aa,i,i) += bb;
319  break;
320  case '-': for (;i>0;i--) IMATELEM(*aa,i,i) -= bb;
321  break;
322  }
323  res->data=(char *)aa;
324  return FALSE;
325 }
327 {
328  return jjOP_IM_I(res,v,u);
329 }
331 {
332  int l=(int)(long)v->Data();
333  if (l>=0)
334  {
335  int d=(int)(long)u->Data();
336  intvec *vv=new intvec(l);
337  int i;
338  for(i=l-1;i>=0;i--) { (*vv)[i]=d; }
339  res->data=(char *)vv;
340  }
341  return (l<0);
342 }
344 {
345  res->data=(char *)new intvec((int)(long)u->Data(),(int)(long)v->Data());
346  return FALSE;
347 }
348 static void jjEQUAL_REST(leftv res,leftv u,leftv v);
350 {
351  intvec* a = (intvec * )(u->Data());
352  intvec* b = (intvec * )(v->Data());
353  int r=a->compare(b);
354  switch (iiOp)
355  {
356  case '<':
357  res->data = (char *) (r<0);
358  break;
359  case '>':
360  res->data = (char *) (r>0);
361  break;
362  case LE:
363  res->data = (char *) (r<=0);
364  break;
365  case GE:
366  res->data = (char *) (r>=0);
367  break;
368  case EQUAL_EQUAL:
369  case NOTEQUAL: /* negation handled by jjEQUAL_REST */
370  res->data = (char *) (r==0);
371  break;
372  }
373  jjEQUAL_REST(res,u,v);
374  if(r==-2) { WerrorS("size incompatible"); return TRUE; }
375  return FALSE;
376 }
378 {
379  bigintmat* a = (bigintmat * )(u->Data());
380  bigintmat* b = (bigintmat * )(v->Data());
381  int r=a->compare(b);
382  switch (iiOp)
383  {
384  case '<':
385  res->data = (char *) (r<0);
386  break;
387  case '>':
388  res->data = (char *) (r>0);
389  break;
390  case LE:
391  res->data = (char *) (r<=0);
392  break;
393  case GE:
394  res->data = (char *) (r>=0);
395  break;
396  case EQUAL_EQUAL:
397  case NOTEQUAL: /* negation handled by jjEQUAL_REST */
398  res->data = (char *) (r==0);
399  break;
400  }
401  jjEQUAL_REST(res,u,v);
402  if(r==-2) { WerrorS("size incompatible"); return TRUE; }
403  return FALSE;
404 }
406 {
407  intvec* a = (intvec * )(u->Data());
408  int b = (int)(long)(v->Data());
409  int r=a->compare(b);
410  switch (iiOp)
411  {
412  case '<':
413  res->data = (char *) (r<0);
414  break;
415  case '>':
416  res->data = (char *) (r>0);
417  break;
418  case LE:
419  res->data = (char *) (r<=0);
420  break;
421  case GE:
422  res->data = (char *) (r>=0);
423  break;
424  case EQUAL_EQUAL:
425  case NOTEQUAL: /* negation handled by jjEQUAL_REST */
426  res->data = (char *) (r==0);
427  break;
428  }
429  jjEQUAL_REST(res,u,v);
430  return FALSE;
431 }
433 {
434  //Print("in: >>%s<<\n",my_yylinebuf);
435  matrix a=(matrix)u->Data();
436  matrix b=(matrix)v->Data();
437  int r=mp_Compare(a,b,currRing);
438  switch (iiOp)
439  {
440  case '<':
441  res->data = (char *) (long)(r < 0);
442  break;
443  case '>':
444  res->data = (char *) (long)(r > 0);
445  break;
446  case LE:
447  res->data = (char *) (long)(r <= 0);
448  break;
449  case GE:
450  res->data = (char *) (long)(r >= 0);
451  break;
452  case EQUAL_EQUAL:
453  case NOTEQUAL: /* negation handled by jjEQUAL_REST */
454  res->data = (char *)(long) (r == 0);
455  break;
456  }
457  jjEQUAL_REST(res,u,v);
458  return FALSE;
459 }
461 {
462  poly p=(poly)u->Data();
463  poly q=(poly)v->Data();
464  int r=p_Compare(p,q,currRing);
465  switch (iiOp)
466  {
467  case '<':
468  res->data = (char *) (r < 0);
469  break;
470  case '>':
471  res->data = (char *) (r > 0);
472  break;
473  case LE:
474  res->data = (char *) (r <= 0);
475  break;
476  case GE:
477  res->data = (char *) (r >= 0);
478  break;
479  //case EQUAL_EQUAL:
480  //case NOTEQUAL: /* negation handled by jjEQUAL_REST */
481  // res->data = (char *) (r == 0);
482  // break;
483  }
484  jjEQUAL_REST(res,u,v);
485  return FALSE;
486 }
488 {
489  char* a = (char * )(u->Data());
490  char* b = (char * )(v->Data());
491  int result = strcmp(a,b);
492  switch (iiOp)
493  {
494  case '<':
495  res->data = (char *) (result < 0);
496  break;
497  case '>':
498  res->data = (char *) (result > 0);
499  break;
500  case LE:
501  res->data = (char *) (result <= 0);
502  break;
503  case GE:
504  res->data = (char *) (result >= 0);
505  break;
506  case EQUAL_EQUAL:
507  case NOTEQUAL: /* negation handled by jjEQUAL_REST */
508  res->data = (char *) (result == 0);
509  break;
510  }
511  jjEQUAL_REST(res,u,v);
512  return FALSE;
513 }
514 static BOOLEAN jjOP_REST(leftv res, leftv u, leftv v)
515 {
516  if (u->Next()!=NULL)
517  {
518  u=u->next;
519  res->next = (leftv)omAllocBin(sleftv_bin);
520  return iiExprArith2(res->next,u,iiOp,v);
521  }
522  else if (v->Next()!=NULL)
523  {
524  v=v->next;
525  res->next = (leftv)omAllocBin(sleftv_bin);
526  return iiExprArith2(res->next,u,iiOp,v);
527  }
528  return FALSE;
529 }
530 static BOOLEAN jjPOWER_I(leftv res, leftv u, leftv v)
531 {
532  int b=(int)(long)u->Data();
533  int e=(int)(long)v->Data();
534  int rc = 1;
535  BOOLEAN overflow=FALSE;
536  if (e >= 0)
537  {
538  if (b==0)
539  {
540  rc=(e==0);
541  }
542  else if ((e==0)||(b==1))
543  {
544  rc= 1;
545  }
546  else if (b== -1)
547  {
548  if (e&1) rc= -1;
549  else rc= 1;
550  }
551  else
552  {
553  int oldrc;
554  while ((e--)!=0)
555  {
556  oldrc=rc;
557  rc *= b;
558  if (!overflow)
559  {
560  if(rc/b!=oldrc) overflow=TRUE;
561  }
562  }
563  if (overflow)
564  WarnS("int overflow(^), result may be wrong");
565  }
566  res->data = (char *)((long)rc);
567  if (u!=NULL) return jjOP_REST(res,u,v);
568  return FALSE;
569  }
570  else
571  {
572  WerrorS("exponent must be non-negative");
573  return TRUE;
574  }
575 }
576 static BOOLEAN jjPOWER_BI(leftv res, leftv u, leftv v)
577 {
578  int e=(int)(long)v->Data();
579  number n=(number)u->Data();
580  if (e>=0)
581  {
582  n_Power(n,e,(number*)&res->data,coeffs_BIGINT);
583  }
584  else
585  {
586  WerrorS("exponent must be non-negative");
587  return TRUE;
588  }
589  if (u!=NULL) return jjOP_REST(res,u,v);
590  return FALSE;
591 }
592 static BOOLEAN jjPOWER_N(leftv res, leftv u, leftv v)
593 {
594  int e=(int)(long)v->Data();
595  number n=(number)u->Data();
596  int d=0;
597  if (e<0)
598  {
599  n=nInvers(n);
600  e=-e;
601  d=1;
602  }
603  number r;
604  nPower(n,e,(number*)&r);
605  res->data=(char*)r;
606  if (d) nDelete(&n);
607  if (u!=NULL) return jjOP_REST(res,u,v);
608  return FALSE;
609 }
610 static BOOLEAN jjPOWER_P(leftv res, leftv u, leftv v)
611 {
612  int v_i=(int)(long)v->Data();
613  if (v_i<0)
614  {
615  WerrorS("exponent must be non-negative");
616  return TRUE;
617  }
618  poly u_p=(poly)u->CopyD(POLY_CMD);
619  if ((u_p!=NULL)
620  && ((v_i!=0) &&
621  ((long)pTotaldegree(u_p) > (signed long)currRing->bitmask / (signed long)v_i/2)))
622  {
623  Werror("OVERFLOW in power(d=%ld, e=%d, max=%ld)",
624  pTotaldegree(u_p),v_i,currRing->bitmask/2);
625  pDelete(&u_p);
626  return TRUE;
627  }
628  res->data = (char *)pPower(u_p,v_i);
629  if (u!=NULL) return jjOP_REST(res,u,v);
630  return errorreported; /* pPower may set errorreported via Werror */
631 }
632 static BOOLEAN jjPOWER_ID(leftv res, leftv u, leftv v)
633 {
634  res->data = (char *)id_Power((ideal)(u->Data()),(int)(long)(v->Data()), currRing);
635  if (u!=NULL) return jjOP_REST(res,u,v);
636  return FALSE;
637 }
639 {
640  u=u->next;
641  v=v->next;
642  if (u==NULL)
643  {
644  if (v==NULL) return FALSE; /* u==NULL, v==NULL */
645  if (iiOp=='-') /* u==NULL, v<>NULL, iiOp=='-'*/
646  {
647  do
648  {
649  if (res->next==NULL)
650  res->next = (leftv)omAlloc0Bin(sleftv_bin);
651  leftv tmp_v=v->next;
652  v->next=NULL;
653  BOOLEAN b=iiExprArith1(res->next,v,'-');
654  v->next=tmp_v;
655  if (b)
656  return TRUE;
657  v=tmp_v;
658  res=res->next;
659  } while (v!=NULL);
660  return FALSE;
661  }
662  loop /* u==NULL, v<>NULL, iiOp=='+' */
663  {
664  res->next = (leftv)omAlloc0Bin(sleftv_bin);
665  res=res->next;
666  res->data = v->CopyD();
667  res->rtyp = v->Typ();
668  v=v->next;
669  if (v==NULL) return FALSE;
670  }
671  }
672  if (v!=NULL) /* u<>NULL, v<>NULL */
673  {
674  do
675  {
676  res->next = (leftv)omAlloc0Bin(sleftv_bin);
677  leftv tmp_u=u->next; u->next=NULL;
678  leftv tmp_v=v->next; v->next=NULL;
679  BOOLEAN b=iiExprArith2(res->next,u,iiOp,v);
680  u->next=tmp_u;
681  v->next=tmp_v;
682  if (b)
683  return TRUE;
684  u=tmp_u;
685  v=tmp_v;
686  res=res->next;
687  } while ((u!=NULL) && (v!=NULL));
688  return FALSE;
689  }
690  loop /* u<>NULL, v==NULL */
691  {
692  res->next = (leftv)omAlloc0Bin(sleftv_bin);
693  res=res->next;
694  res->data = u->CopyD();
695  res->rtyp = u->Typ();
696  u=u->next;
697  if (u==NULL) return FALSE;
698  }
699 }
700 static BOOLEAN jjCOLCOL(leftv res, leftv u, leftv v)
701 {
702  switch(u->Typ())
703  {
704  case 0:
705  {
706  int name_err=0;
707  if(isupper(u->name[0]))
708  {
709  const char *c=u->name+1;
710  while((*c!='\0')&&(islower(*c)||(isdigit(*c)))) c++;
711  if (*c!='\0')
712  name_err=1;
713  else
714  {
715  Print("%s of type 'ANY'. Trying load.\n", u->name);
716  if(iiTryLoadLib(u, u->name))
717  {
718  Werror("'%s' no such package", u->name);
719  return TRUE;
720  }
721  syMake(u,u->name,NULL);
722  }
723  }
724  else name_err=1;
725  if(name_err)
726  { Werror("'%s' is an invalid package name",u->name);return TRUE;}
727  // and now, after the loading: use next case !!! no break !!!
728  }
729  case PACKAGE_CMD:
730  {
731  package pa=(package)u->Data();
732  if (u->rtyp==IDHDL) pa=IDPACKAGE((idhdl)u->data);
733  if((!pa->loaded)
734  && (pa->language > LANG_TOP))
735  {
736  Werror("'%s' not loaded", u->name);
737  return TRUE;
738  }
739  if(v->rtyp == IDHDL)
740  {
741  v->name = omStrDup(v->name);
742  }
743  else if (v->rtyp!=0)
744  {
745  WerrorS("reserved name with ::");
746  return TRUE;
747  }
748  v->req_packhdl=pa;
749  syMake(v, v->name, pa);
750  memcpy(res, v, sizeof(sleftv));
751  memset(v, 0, sizeof(sleftv));
752  }
753  break;
754  case DEF_CMD:
755  break;
756  default:
757  WerrorS("<package>::<id> expected");
758  return TRUE;
759  }
760  return FALSE;
761 }
762 static BOOLEAN jjPLUS_I(leftv res, leftv u, leftv v)
763 {
764  unsigned int a=(unsigned int)(unsigned long)u->Data();
765  unsigned int b=(unsigned int)(unsigned long)v->Data();
766  unsigned int c=a+b;
767  res->data = (char *)((long)c);
768  if (((Sy_bit(31)&a)==(Sy_bit(31)&b))&&((Sy_bit(31)&a)!=(Sy_bit(31)&c)))
769  {
770  WarnS("int overflow(+), result may be wrong");
771  }
772  return jjPLUSMINUS_Gen(res,u,v);
773 }
774 static BOOLEAN jjPLUS_BI(leftv res, leftv u, leftv v)
775 {
776  res->data = (char *)(n_Add((number)u->Data(), (number)v->Data(),coeffs_BIGINT));
777  return jjPLUSMINUS_Gen(res,u,v);
778 }
779 static BOOLEAN jjPLUS_N(leftv res, leftv u, leftv v)
780 {
781  res->data = (char *)(nAdd((number)u->Data(), (number)v->Data()));
782  return jjPLUSMINUS_Gen(res,u,v);
783 }
784 static BOOLEAN jjPLUS_P(leftv res, leftv u, leftv v)
785 {
786  res->data = (char *)(pAdd((poly)u->CopyD(POLY_CMD) , (poly)v->CopyD(POLY_CMD)));
787  return jjPLUSMINUS_Gen(res,u,v);
788 }
789 static BOOLEAN jjPLUS_IV(leftv res, leftv u, leftv v)
790 {
791  res->data = (char *)ivAdd((intvec*)(u->Data()), (intvec*)(v->Data()));
792  if (res->data==NULL)
793  {
794  WerrorS("intmat size not compatible");
795  return TRUE;
796  }
797  return jjPLUSMINUS_Gen(res,u,v);
798 }
799 static BOOLEAN jjPLUS_BIM(leftv res, leftv u, leftv v)
800 {
801  res->data = (char *)bimAdd((bigintmat*)(u->Data()), (bigintmat*)(v->Data()));
802  if (res->data==NULL)
803  {
804  WerrorS("bigintmat/cmatrix not compatible");
805  return TRUE;
806  }
807  return jjPLUSMINUS_Gen(res,u,v);
808 }
809 static BOOLEAN jjPLUS_MA(leftv res, leftv u, leftv v)
810 {
811  matrix A=(matrix)u->Data(); matrix B=(matrix)v->Data();
812  res->data = (char *)(mp_Add(A , B, currRing));
813  if (res->data==NULL)
814  {
815  Werror("matrix size not compatible(%dx%d, %dx%d)",
816  MATROWS(A),MATCOLS(A),MATROWS(B),MATCOLS(B));
817  return TRUE;
818  }
819  return jjPLUSMINUS_Gen(res,u,v);
820 }
822 {
823  matrix m=(matrix)u->Data();
825  if (iiOp=='+')
826  res->data = (char *)mp_Add(m , p,currRing);
827  else
828  res->data = (char *)mp_Sub(m , p,currRing);
829  idDelete((ideal *)&p);
830  return jjPLUSMINUS_Gen(res,u,v);
831 }
833 {
834  return jjPLUS_MA_P(res,v,u);
835 }
836 static BOOLEAN jjPLUS_S(leftv res, leftv u, leftv v)
837 {
838  char* a = (char * )(u->Data());
839  char* b = (char * )(v->Data());
840  char* r = (char * )omAlloc(strlen(a) + strlen(b) + 1);
841  strcpy(r,a);
842  strcat(r,b);
843  res->data=r;
844  return jjPLUSMINUS_Gen(res,u,v);
845 }
846 static BOOLEAN jjPLUS_ID(leftv res, leftv u, leftv v)
847 {
848  res->data = (char *)idAdd((ideal)u->Data(),(ideal)v->Data());
849  return jjPLUSMINUS_Gen(res,u,v);
850 }
851 static BOOLEAN jjMINUS_I(leftv res, leftv u, leftv v)
852 {
853  void *ap=u->Data(); void *bp=v->Data();
854  int aa=(int)(long)ap;
855  int bb=(int)(long)bp;
856  int cc=aa-bb;
857  unsigned int a=(unsigned int)(unsigned long)ap;
858  unsigned int b=(unsigned int)(unsigned long)bp;
859  unsigned int c=a-b;
860  if (((Sy_bit(31)&a)!=(Sy_bit(31)&b))&&((Sy_bit(31)&a)!=(Sy_bit(31)&c)))
861  {
862  WarnS("int overflow(-), result may be wrong");
863  }
864  res->data = (char *)((long)cc);
865  return jjPLUSMINUS_Gen(res,u,v);
866 }
867 static BOOLEAN jjMINUS_BI(leftv res, leftv u, leftv v)
868 {
869  res->data = (char *)(n_Sub((number)u->Data(), (number)v->Data(),coeffs_BIGINT));
870  return jjPLUSMINUS_Gen(res,u,v);
871 }
872 static BOOLEAN jjMINUS_N(leftv res, leftv u, leftv v)
873 {
874  res->data = (char *)(nSub((number)u->Data(), (number)v->Data()));
875  return jjPLUSMINUS_Gen(res,u,v);
876 }
877 static BOOLEAN jjMINUS_P(leftv res, leftv u, leftv v)
878 {
879  res->data = (char *)(pSub((poly)u->CopyD(POLY_CMD) , (poly)v->CopyD(POLY_CMD)));
880  return jjPLUSMINUS_Gen(res,u,v);
881 }
882 static BOOLEAN jjMINUS_IV(leftv res, leftv u, leftv v)
883 {
884  res->data = (char *)ivSub((intvec*)(u->Data()), (intvec*)(v->Data()));
885  if (res->data==NULL)
886  {
887  WerrorS("intmat size not compatible");
888  return TRUE;
889  }
890  return jjPLUSMINUS_Gen(res,u,v);
891 }
893 {
894  res->data = (char *)bimSub((bigintmat*)(u->Data()), (bigintmat*)(v->Data()));
895  if (res->data==NULL)
896  {
897  WerrorS("bigintmat/cmatrix not compatible");
898  return TRUE;
899  }
900  return jjPLUSMINUS_Gen(res,u,v);
901 }
902 static BOOLEAN jjMINUS_MA(leftv res, leftv u, leftv v)
903 {
904  matrix A=(matrix)u->Data(); matrix B=(matrix)v->Data();
905  res->data = (char *)(mp_Sub(A , B, currRing));
906  if (res->data==NULL)
907  {
908  Werror("matrix size not compatible(%dx%d, %dx%d)",
909  MATROWS(A),MATCOLS(A),MATROWS(B),MATCOLS(B));
910  return TRUE;
911  }
912  return jjPLUSMINUS_Gen(res,u,v);
913  return FALSE;
914 }
915 static BOOLEAN jjTIMES_I(leftv res, leftv u, leftv v)
916 {
917  int a=(int)(long)u->Data();
918  int b=(int)(long)v->Data();
919  int64 c=(int64)a * (int64)b;
920  if ((c>INT_MAX)||(c<INT_MIN))
921  WarnS("int overflow(*), result may be wrong");
922  res->data = (char *)((long)((int)c));
923  if ((u->Next()!=NULL) || (v->Next()!=NULL))
924  return jjOP_REST(res,u,v);
925  return FALSE;
926 }
927 static BOOLEAN jjTIMES_BI(leftv res, leftv u, leftv v)
928 {
929  res->data = (char *)(n_Mult( (number)u->Data(), (number)v->Data(),coeffs_BIGINT));
930  if ((v->next!=NULL) || (u->next!=NULL))
931  return jjOP_REST(res,u,v);
932  return FALSE;
933 }
934 static BOOLEAN jjTIMES_N(leftv res, leftv u, leftv v)
935 {
936  res->data = (char *)(nMult( (number)u->Data(), (number)v->Data()));
937  number n=(number)res->data;
938  nNormalize(n);
939  res->data=(char *)n;
940  if ((v->next!=NULL) || (u->next!=NULL))
941  return jjOP_REST(res,u,v);
942  return FALSE;
943 }
944 static BOOLEAN jjTIMES_P(leftv res, leftv u, leftv v)
945 {
946  poly a;
947  poly b;
948  if (v->next==NULL)
949  {
950  a=(poly)u->CopyD(POLY_CMD); // works also for VECTOR_CMD
951  if (u->next==NULL)
952  {
953  b=(poly)v->CopyD(POLY_CMD); // works also for VECTOR_CMD
954  if ((a!=NULL) && (b!=NULL)
955  && ((long)pTotaldegree(a)>si_max((long)rVar(currRing),(long)currRing->bitmask/2)-(long)pTotaldegree(b)))
956  {
957  Warn("possible OVERFLOW in mult(d=%ld, d=%ld, max=%ld)",
958  pTotaldegree(a),pTotaldegree(b),currRing->bitmask/2);
959  }
960  res->data = (char *)(pMult( a, b));
961  pNormalize((poly)res->data);
962  return FALSE;
963  }
964  // u->next exists: copy v
965  b=pCopy((poly)v->Data());
966  if ((a!=NULL) && (b!=NULL)
967  && (pTotaldegree(a)+pTotaldegree(b)>si_max((long)rVar(currRing),(long)currRing->bitmask/2)))
968  {
969  Warn("possible OVERFLOW in mult(d=%ld, d=%ld, max=%ld)",
970  pTotaldegree(a),pTotaldegree(b),currRing->bitmask/2);
971  }
972  res->data = (char *)(pMult( a, b));
973  pNormalize((poly)res->data);
974  return jjOP_REST(res,u,v);
975  }
976  // v->next exists: copy u
977  a=pCopy((poly)u->Data());
978  b=(poly)v->CopyD(POLY_CMD); // works also for VECTOR_CMD
979  if ((a!=NULL) && (b!=NULL)
980  && ((unsigned long)(pTotaldegree(a)+pTotaldegree(b))>=currRing->bitmask/2))
981  {
982  pDelete(&a);
983  pDelete(&b);
984  WerrorS("OVERFLOW");
985  return TRUE;
986  }
987  res->data = (char *)(pMult( a, b));
988  pNormalize((poly)res->data);
989  return jjOP_REST(res,u,v);
990 }
991 static BOOLEAN jjTIMES_ID(leftv res, leftv u, leftv v)
992 {
993  res->data = (char *)idMult((ideal)u->Data(),(ideal)v->Data());
994  id_Normalize((ideal)res->data,currRing);
995  if ((v->next!=NULL) || (u->next!=NULL))
996  return jjOP_REST(res,u,v);
997  return FALSE;
998 }
999 static BOOLEAN jjTIMES_IV(leftv res, leftv u, leftv v)
1000 {
1001  res->data = (char *)ivMult((intvec*)(u->Data()), (intvec*)(v->Data()));
1002  if (res->data==NULL)
1003  {
1004  WerrorS("intmat size not compatible");
1005  return TRUE;
1006  }
1007  if ((v->next!=NULL) || (u->next!=NULL))
1008  return jjOP_REST(res,u,v);
1009  return FALSE;
1010 }
1012 {
1013  res->data = (char *)bimMult((bigintmat*)(u->Data()), (bigintmat*)(v->Data()));
1014  if (res->data==NULL)
1015  {
1016  WerrorS("bigintmat/cmatrix not compatible");
1017  return TRUE;
1018  }
1019  if ((v->next!=NULL) || (u->next!=NULL))
1020  return jjOP_REST(res,u,v);
1021  return FALSE;
1022 }
1024 {
1026  if (nMap==NULL) return TRUE;
1027  number n=nMap((number)v->Data(),coeffs_BIGINT,currRing->cf);
1028  poly p=pNSet(n);
1029  ideal I= (ideal)mp_MultP((matrix)u->CopyD(MATRIX_CMD),p,currRing);
1030  res->data = (char *)I;
1031  return FALSE;
1032 }
1034 {
1035  return jjTIMES_MA_BI1(res,v,u);
1036 }
1038 {
1039  poly p=(poly)v->CopyD(POLY_CMD);
1040  int r=pMaxComp(p);/* recompute the rank for the case ideal*vector*/
1041  ideal I= (ideal)mp_MultP((matrix)u->CopyD(MATRIX_CMD),p,currRing);
1042  if (r>0) I->rank=r;
1044  res->data = (char *)I;
1045  return FALSE;
1046 }
1048 {
1049  poly p=(poly)u->CopyD(POLY_CMD);
1050  int r=pMaxComp(p);/* recompute the rank for the case ideal*vector*/
1051  ideal I= (ideal)pMultMp(p,(matrix)v->CopyD(MATRIX_CMD),currRing);
1052  if (r>0) I->rank=r;
1054  res->data = (char *)I;
1055  return FALSE;
1056 }
1058 {
1059  number n=(number)v->CopyD(NUMBER_CMD);
1060  poly p=pNSet(n);
1061  res->data = (char *)mp_MultP((matrix)u->CopyD(MATRIX_CMD),p,currRing);
1062  id_Normalize((ideal)res->data,currRing);
1063  return FALSE;
1064 }
1066 {
1067  return jjTIMES_MA_N1(res,v,u);
1068 }
1070 {
1071  res->data = (char *)mp_MultI((matrix)u->CopyD(MATRIX_CMD),(int)(long)v->Data(),currRing);
1072  id_Normalize((ideal)res->data,currRing);
1073  return FALSE;
1074 }
1076 {
1077  return jjTIMES_MA_I1(res,v,u);
1078 }
1080 {
1081  matrix A=(matrix)u->Data(); matrix B=(matrix)v->Data();
1082  res->data = (char *)mp_Mult(A,B,currRing);
1083  if (res->data==NULL)
1084  {
1085  Werror("matrix size not compatible(%dx%d, %dx%d) in *",
1086  MATROWS(A),MATCOLS(A),MATROWS(B),MATCOLS(B));
1087  return TRUE;
1088  }
1089  id_Normalize((ideal)res->data,currRing);
1090  if ((v->next!=NULL) || (u->next!=NULL))
1091  return jjOP_REST(res,u,v);
1092  return FALSE;
1093 }
1094 static BOOLEAN jjGE_BI(leftv res, leftv u, leftv v)
1095 {
1096  number h=n_Sub((number)u->Data(),(number)v->Data(),coeffs_BIGINT);
1097  res->data = (char *) (n_GreaterZero(h,coeffs_BIGINT)||(n_IsZero(h,coeffs_BIGINT)));
1098  n_Delete(&h,coeffs_BIGINT);
1099  return FALSE;
1100 }
1101 static BOOLEAN jjGE_I(leftv res, leftv u, leftv v)
1102 {
1103  res->data = (char *)(long)((int)((long)u->Data()) >= (int)((long)v->Data()));
1104  return FALSE;
1105 }
1106 static BOOLEAN jjGE_N(leftv res, leftv u, leftv v)
1107 {
1108  res->data = (char *)(long) (nGreater((number)u->Data(),(number)v->Data())
1109  || nEqual((number)u->Data(),(number)v->Data()));
1110  return FALSE;
1111 }
1112 static BOOLEAN jjGT_BI(leftv res, leftv u, leftv v)
1113 {
1114  number h=n_Sub((number)u->Data(),(number)v->Data(),coeffs_BIGINT);
1115  res->data = (char *)(long) (n_GreaterZero(h,coeffs_BIGINT)&&(!n_IsZero(h,coeffs_BIGINT)));
1116  n_Delete(&h,coeffs_BIGINT);
1117  return FALSE;
1118 }
1119 static BOOLEAN jjGT_I(leftv res, leftv u, leftv v)
1120 {
1121  res->data = (char *)(long)((int)((long)u->Data()) > (int)((long)v->Data()));
1122  return FALSE;
1123 }
1124 static BOOLEAN jjGT_N(leftv res, leftv u, leftv v)
1125 {
1126  res->data = (char *)(long)(nGreater((number)u->Data(),(number)v->Data()));
1127  return FALSE;
1128 }
1129 static BOOLEAN jjLE_BI(leftv res, leftv u, leftv v)
1130 {
1131  return jjGE_BI(res,v,u);
1132 }
1133 static BOOLEAN jjLE_I(leftv res, leftv u, leftv v)
1134 {
1135  res->data = (char *)(long)((int)((long)u->Data()) <= (int)((long)v->Data()));
1136  return FALSE;
1137 }
1138 static BOOLEAN jjLE_N(leftv res, leftv u, leftv v)
1139 {
1140  return jjGE_N(res,v,u);
1141 }
1142 static BOOLEAN jjLT_BI(leftv res, leftv u, leftv v)
1143 {
1144  return jjGT_BI(res,v,u);
1145 }
1146 static BOOLEAN jjLT_I(leftv res, leftv u, leftv v)
1147 {
1148  res->data = (char *)(long)((int)((long)u->Data()) < (int)((long)v->Data()));
1149  return FALSE;
1150 }
1151 static BOOLEAN jjLT_N(leftv res, leftv u, leftv v)
1152 {
1153  return jjGT_N(res,v,u);
1154 }
1156 {
1157  if (iiOp=='/') Warn("int division with `/`: use `div` instead in line >>%s<<",my_yylinebuf);
1158  int a= (int)(long)u->Data();
1159  int b= (int)(long)v->Data();
1160  if (b==0)
1161  {
1163  return TRUE;
1164  }
1165  int c=a%b;
1166  int r=0;
1167  switch (iiOp)
1168  {
1169  case '%':
1170  r=c; break;
1171  case '/':
1172  case INTDIV_CMD:
1173  r=((a-c) /b); break;
1174  }
1175  res->data=(void *)((long)r);
1176  return FALSE;
1177 }
1178 static BOOLEAN jjDIV_BI(leftv res, leftv u, leftv v)
1179 {
1180  number q=(number)v->Data();
1181  if (n_IsZero(q,coeffs_BIGINT))
1182  {
1184  return TRUE;
1185  }
1186  q = n_Div((number)u->Data(),q,coeffs_BIGINT);
1188  res->data = (char *)q;
1189  return FALSE;
1190 }
1191 static BOOLEAN jjDIV_N(leftv res, leftv u, leftv v)
1192 {
1193  number q=(number)v->Data();
1194  if (nIsZero(q))
1195  {
1197  return TRUE;
1198  }
1199  q = nDiv((number)u->Data(),q);
1200  nNormalize(q);
1201  res->data = (char *)q;
1202  return FALSE;
1203 }
1204 static BOOLEAN jjDIV_P(leftv res, leftv u, leftv v)
1205 {
1206  poly q=(poly)v->Data();
1207  if (q==NULL)
1208  {
1210  return TRUE;
1211  }
1212  poly p=(poly)(u->Data());
1213  if (p==NULL)
1214  {
1215  res->data=NULL;
1216  return FALSE;
1217  }
1218  if ((pNext(q)!=NULL) && (!rField_is_Ring(currRing)))
1219  { /* This means that q != 0 consists of at least two terms.
1220  Moreover, currRing is over a field. */
1221  if(pGetComp(p)==0)
1222  {
1223  res->data=(void*)(singclap_pdivide(p /*(poly)(u->Data())*/ ,
1224  q /*(poly)(v->Data())*/ ,currRing));
1225  }
1226  else
1227  {
1228  int comps=pMaxComp(p);
1229  ideal I=idInit(comps,1);
1230  p=pCopy(p);
1231  poly h;
1232  int i;
1233  // conversion to a list of polys:
1234  while (p!=NULL)
1235  {
1236  i=pGetComp(p)-1;
1237  h=pNext(p);
1238  pNext(p)=NULL;
1239  pSetComp(p,0);
1240  I->m[i]=pAdd(I->m[i],p);
1241  p=h;
1242  }
1243  // division and conversion to vector:
1244  h=NULL;
1245  p=NULL;
1246  for(i=comps-1;i>=0;i--)
1247  {
1248  if (I->m[i]!=NULL)
1249  {
1250  h=singclap_pdivide(I->m[i],q,currRing);
1251  pSetCompP(h,i+1);
1252  p=pAdd(p,h);
1253  }
1254  }
1255  idDelete(&I);
1256  res->data=(void *)p;
1257  }
1258  }
1259  else
1260  { /* This means that q != 0 consists of just one term,
1261  or that currRing is over a coefficient ring. */
1262 #ifdef HAVE_RINGS
1263  if (!rField_is_Domain(currRing))
1264  {
1265  WerrorS("division only defined over coefficient domains");
1266  return TRUE;
1267  }
1268  if (pNext(q)!=NULL)
1269  {
1270  WerrorS("division over a coefficient domain only implemented for terms");
1271  return TRUE;
1272  }
1273 #endif
1274  res->data = (char *)pDivideM(pCopy(p),pHead(q));
1275  }
1276  pNormalize((poly)res->data);
1277  return FALSE;
1278 }
1279 static BOOLEAN jjDIV_Ma(leftv res, leftv u, leftv v)
1280 {
1281  poly q=(poly)v->Data();
1282  if (q==NULL)
1283  {
1285  return TRUE;
1286  }
1287  matrix m=(matrix)(u->Data());
1288  int r=m->rows();
1289  int c=m->cols();
1290  matrix mm=mpNew(r,c);
1291  unsigned i,j;
1292  for(i=r;i>0;i--)
1293  {
1294  for(j=c;j>0;j--)
1295  {
1296  if (pNext(q)!=NULL)
1297  {
1298  MATELEM(mm,i,j) = singclap_pdivide( MATELEM(m,i,j) ,
1299  q /*(poly)(v->Data())*/, currRing );
1300  }
1301  else
1302  MATELEM(mm,i,j) = pDivideM(pCopy(MATELEM(m,i,j)),pHead(q));
1303  }
1304  }
1305  id_Normalize((ideal)mm,currRing);
1306  res->data=(char *)mm;
1307  return FALSE;
1308 }
1310 {
1311  res->data = (char *)((long)n_Equal((number)u->Data(),(number)v->Data(),coeffs_BIGINT));
1312  jjEQUAL_REST(res,u,v);
1313  return FALSE;
1314 }
1315 static BOOLEAN jjEQUAL_I(leftv res, leftv u, leftv v)
1316 {
1317  res->data = (char *)((int)((long)u->Data()) == (int)((long)v->Data()));
1318  jjEQUAL_REST(res,u,v);
1319  return FALSE;
1320 }
1322 {
1323  res->data = (char *)((long)mp_Equal((matrix)u->Data(),(matrix)v->Data(),currRing));
1324  jjEQUAL_REST(res,u,v);
1325  return FALSE;
1326 }
1327 static BOOLEAN jjEQUAL_R(leftv res, leftv u, leftv v)
1328 {
1329  res->data = (char *)(long)(u->Data()==v->Data());
1330  jjEQUAL_REST(res,u,v);
1331  return FALSE;
1332 }
1333 static BOOLEAN jjEQUAL_N(leftv res, leftv u, leftv v)
1334 {
1335  res->data = (char *)((long)nEqual((number)u->Data(),(number)v->Data()));
1336  jjEQUAL_REST(res,u,v);
1337  return FALSE;
1338 }
1339 static BOOLEAN jjEQUAL_P(leftv res, leftv u, leftv v)
1340 {
1341  poly p=(poly)u->Data();
1342  poly q=(poly)v->Data();
1343  res->data = (char *) ((long)pEqualPolys(p,q));
1344  jjEQUAL_REST(res,u,v);
1345  return FALSE;
1346 }
1347 static void jjEQUAL_REST(leftv res,leftv u,leftv v)
1348 {
1349  if ((res->data) && (u->next!=NULL) && (v->next!=NULL))
1350  {
1351  int save_iiOp=iiOp;
1352  if (iiOp==NOTEQUAL)
1353  iiExprArith2(res,u->next,EQUAL_EQUAL,v->next);
1354  else
1355  iiExprArith2(res,u->next,iiOp,v->next);
1356  iiOp=save_iiOp;
1357  }
1358  if (iiOp==NOTEQUAL) res->data=(char *)(!(long)res->data);
1359 }
1360 static BOOLEAN jjAND_I(leftv res, leftv u, leftv v)
1361 {
1362  res->data = (char *)((long)u->Data() && (long)v->Data());
1363  return FALSE;
1364 }
1365 static BOOLEAN jjOR_I(leftv res, leftv u, leftv v)
1366 {
1367  res->data = (char *)((long)u->Data() || (long)v->Data());
1368  return FALSE;
1369 }
1370 static BOOLEAN jjINDEX_I(leftv res, leftv u, leftv v)
1371 {
1372  res->rtyp=u->rtyp; u->rtyp=0;
1373  res->data=u->data; u->data=NULL;
1374  res->name=u->name; u->name=NULL;
1375  res->e=u->e; u->e=NULL;
1376  if (res->e==NULL) res->e=jjMakeSub(v);
1377  else
1378  {
1379  Subexpr sh=res->e;
1380  while (sh->next != NULL) sh=sh->next;
1381  sh->next=jjMakeSub(v);
1382  }
1383  if (u->next!=NULL)
1384  {
1386  BOOLEAN bo=iiExprArith2(rn,u->next,iiOp,v);
1387  res->next=rn;
1388  return bo;
1389  }
1390  return FALSE;
1391 }
1393 {
1394  if ((u->rtyp!=IDHDL)||(u->e!=NULL))
1395  {
1396  WerrorS("indexed object must have a name");
1397  return TRUE;
1398  }
1399  intvec * iv=(intvec *)v->Data();
1400  leftv p=NULL;
1401  int i;
1402  sleftv t;
1403  memset(&t,0,sizeof(t));
1404  t.rtyp=INT_CMD;
1405  for (i=0;i<iv->length(); i++)
1406  {
1407  t.data=(char *)((long)(*iv)[i]);
1408  if (p==NULL)
1409  {
1410  p=res;
1411  }
1412  else
1413  {
1415  p=p->next;
1416  }
1417  p->rtyp=IDHDL;
1418  p->data=u->data;
1419  p->name=u->name;
1420  p->flag=u->flag;
1421  p->e=jjMakeSub(&t);
1422  }
1423  u->rtyp=0;
1424  u->data=NULL;
1425  u->name=NULL;
1426  return FALSE;
1427 }
1428 static BOOLEAN jjINDEX_P(leftv res, leftv u, leftv v)
1429 {
1430  poly p=(poly)u->Data();
1431  int i=(int)(long)v->Data();
1432  int j=0;
1433  while (p!=NULL)
1434  {
1435  j++;
1436  if (j==i)
1437  {
1438  res->data=(char *)pHead(p);
1439  return FALSE;
1440  }
1441  pIter(p);
1442  }
1443  return FALSE;
1444 }
1446 {
1447  poly p=(poly)u->Data();
1448  poly r=NULL;
1449  intvec *iv=(intvec *)v->CopyD(INTVEC_CMD);
1450  int i;
1451  int sum=0;
1452  for(i=iv->length()-1;i>=0;i--)
1453  sum+=(*iv)[i];
1454  int j=0;
1455  while ((p!=NULL) && (sum>0))
1456  {
1457  j++;
1458  for(i=iv->length()-1;i>=0;i--)
1459  {
1460  if (j==(*iv)[i])
1461  {
1462  r=pAdd(r,pHead(p));
1463  sum-=j;
1464  (*iv)[i]=0;
1465  break;
1466  }
1467  }
1468  pIter(p);
1469  }
1470  delete iv;
1471  res->data=(char *)r;
1472  return FALSE;
1473 }
1474 static BOOLEAN jjINDEX_V(leftv res, leftv u, leftv v)
1475 {
1476  poly p=(poly)u->CopyD(VECTOR_CMD);
1477  poly r=p; // pointer to the beginning of component i
1478  poly o=NULL;
1479  int i=(int)(long)v->Data();
1480  while (p!=NULL)
1481  {
1482  if (pGetComp(p)!=i)
1483  {
1484  if (r==p) r=pNext(p);
1485  if (o!=NULL)
1486  {
1487  if (pNext(o)!=NULL) pLmDelete(&pNext(o));
1488  p=pNext(o);
1489  }
1490  else
1491  pLmDelete(&p);
1492  }
1493  else
1494  {
1495  pSetComp(p, 0);
1496  p_SetmComp(p, currRing);
1497  o=p;
1498  p=pNext(o);
1499  }
1500  }
1501  res->data=(char *)r;
1502  return FALSE;
1503 }
1505 {
1506  poly p=(poly)u->CopyD(VECTOR_CMD);
1507  if (p!=NULL)
1508  {
1509  poly r=pOne();
1510  poly hp=r;
1511  intvec *iv=(intvec *)v->Data();
1512  int i;
1513  loop
1514  {
1515  for(i=0;i<iv->length();i++)
1516  {
1517  if (((int)pGetComp(p))==(*iv)[i])
1518  {
1519  poly h;
1520  pSplit(p,&h);
1521  pNext(hp)=p;
1522  p=h;
1523  pIter(hp);
1524  break;
1525  }
1526  }
1527  if (p==NULL) break;
1528  if (i==iv->length())
1529  {
1530  pLmDelete(&p);
1531  if (p==NULL) break;
1532  }
1533  }
1534  pLmDelete(&r);
1535  res->data=(char *)r;
1536  }
1537  return FALSE;
1538 }
1539 static BOOLEAN jjKLAMMER_rest(leftv res, leftv u, leftv v);
1540 static BOOLEAN jjKLAMMER(leftv res, leftv u, leftv v)
1541 {
1542  if(u->name==NULL) return TRUE;
1543  char * nn = (char *)omAlloc(strlen(u->name) + 14);
1544  sprintf(nn,"%s(%d)",u->name,(int)(long)v->Data());
1545  omFree((ADDRESS)u->name);
1546  u->name=NULL;
1547  char *n=omStrDup(nn);
1548  omFree((ADDRESS)nn);
1549  syMake(res,n);
1550  if (u->next!=NULL) return jjKLAMMER_rest(res,u->next,v);
1551  return FALSE;
1552 }
1554 {
1555  intvec * iv=(intvec *)v->Data();
1556  leftv p=NULL;
1557  int i;
1558  long slen = strlen(u->name) + 14;
1559  char *n = (char*) omAlloc(slen);
1560 
1561  for (i=0;i<iv->length(); i++)
1562  {
1563  if (p==NULL)
1564  {
1565  p=res;
1566  }
1567  else
1568  {
1570  p=p->next;
1571  }
1572  sprintf(n,"%s(%d)",u->name,(*iv)[i]);
1573  syMake(p,omStrDup(n));
1574  }
1575  omFree((ADDRESS)u->name);
1576  u->name = NULL;
1577  omFreeSize(n, slen);
1578  if (u->next!=NULL) return jjKLAMMER_rest(res,u->next,v);
1579  return FALSE;
1580 }
1582 {
1584  memset(tmp,0,sizeof(sleftv));
1585  BOOLEAN b;
1586  if (v->Typ()==INTVEC_CMD)
1587  b=jjKLAMMER_IV(tmp,u,v);
1588  else
1589  b=jjKLAMMER(tmp,u,v);
1590  if (b)
1591  {
1592  omFreeBin(tmp,sleftv_bin);
1593  return TRUE;
1594  }
1595  leftv h=res;
1596  while (h->next!=NULL) h=h->next;
1597  h->next=tmp;
1598  return FALSE;
1599 }
1601 {
1602  void *d;
1603  Subexpr e;
1604  int typ;
1605  BOOLEAN t=FALSE;
1606  idhdl tmp_proc=NULL;
1607  if ((u->rtyp!=IDHDL)||(u->e!=NULL))
1608  {
1609  tmp_proc=(idhdl)omAlloc0(sizeof(idrec));
1610  tmp_proc->id="_auto";
1611  tmp_proc->typ=PROC_CMD;
1612  tmp_proc->data.pinf=(procinfo *)u->Data();
1613  tmp_proc->ref=1;
1614  d=u->data; u->data=(void *)tmp_proc;
1615  e=u->e; u->e=NULL;
1616  t=TRUE;
1617  typ=u->rtyp; u->rtyp=IDHDL;
1618  }
1619  BOOLEAN sl;
1620  if (u->req_packhdl==currPack)
1621  sl = iiMake_proc((idhdl)u->data,NULL,v);
1622  else
1623  sl = iiMake_proc((idhdl)u->data,u->req_packhdl,v);
1624  if (t)
1625  {
1626  u->rtyp=typ;
1627  u->data=d;
1628  u->e=e;
1629  omFreeSize(tmp_proc,sizeof(idrec));
1630  }
1631  if (sl) return TRUE;
1632  memcpy(res,&iiRETURNEXPR,sizeof(sleftv));
1633  iiRETURNEXPR.Init();
1634  return FALSE;
1635 }
1636 static BOOLEAN jjMAP(leftv res, leftv u, leftv v)
1637 {
1638  //Print("try to map %s with %s\n",$3.Name(),$1.Name());
1639  leftv sl=NULL;
1640  if ((v->e==NULL)&&(v->name!=NULL))
1641  {
1642  map m=(map)u->Data();
1643  sl=iiMap(m,v->name);
1644  }
1645  else
1646  {
1647  Werror("%s(<name>) expected",u->Name());
1648  }
1649  if (sl==NULL) return TRUE;
1650  memcpy(res,sl,sizeof(sleftv));
1652  return FALSE;
1653 }
1654 static BOOLEAN jjRING_1(leftv res, leftv u, leftv v)
1655 {
1656  u->next=(leftv)omAlloc(sizeof(sleftv));
1657  memcpy(u->next,v,sizeof(sleftv));
1658  memset(v,0,sizeof(sleftv));
1659  BOOLEAN bo=iiExprArithM(res,u,'[');
1660  u->next=NULL;
1661  return bo;
1662 }
1664 {
1665  intvec *c=(intvec*)u->Data();
1666  intvec* p=(intvec*)v->Data();
1667  int rl=p->length();
1668  number *x=(number *)omAlloc(rl*sizeof(number));
1669  number *q=(number *)omAlloc(rl*sizeof(number));
1670  int i;
1671  for(i=rl-1;i>=0;i--)
1672  {
1673  q[i]=n_Init((*p)[i], coeffs_BIGINT);
1674  x[i]=n_Init((*c)[i], coeffs_BIGINT);
1675  }
1676  CFArray iv(rl);
1677  number n=n_ChineseRemainderSym(x,q,rl,FALSE,iv,coeffs_BIGINT);
1678  for(i=rl-1;i>=0;i--)
1679  {
1680  n_Delete(&(q[i]),coeffs_BIGINT);
1681  n_Delete(&(x[i]),coeffs_BIGINT);
1682  }
1683  omFree(x); omFree(q);
1684  res->data=(char *)n;
1685  return FALSE;
1686 }
1687 #if 0
1688 static BOOLEAN jjCHINREM_P(leftv res, leftv u, leftv v)
1689 {
1690  lists c=(lists)u->CopyD(); // list of poly
1691  intvec* p=(intvec*)v->Data();
1692  int rl=p->length();
1693  poly r=NULL,h, result=NULL;
1694  number *x=(number *)omAlloc(rl*sizeof(number));
1695  number *q=(number *)omAlloc(rl*sizeof(number));
1696  int i;
1697  for(i=rl-1;i>=0;i--)
1698  {
1699  q[i]=nlInit((*p)[i]);
1700  }
1701  loop
1702  {
1703  for(i=rl-1;i>=0;i--)
1704  {
1705  if (c->m[i].Typ()!=POLY_CMD)
1706  {
1707  Werror("poly expected at pos %d",i+1);
1708  for(i=rl-1;i>=0;i--)
1709  {
1710  nlDelete(&(q[i]),currRing);
1711  }
1712  omFree(x); omFree(q); // delete c
1713  return TRUE;
1714  }
1715  h=((poly)c->m[i].Data());
1716  if (r==NULL) r=h;
1717  else if (pLmCmp(r,h)==-1) r=h;
1718  }
1719  if (r==NULL) break;
1720  for(i=rl-1;i>=0;i--)
1721  {
1722  h=((poly)c->m[i].Data());
1723  if (pLmCmp(r,h)==0)
1724  {
1725  x[i]=pGetCoeff(h);
1726  h=pLmFreeAndNext(h);
1727  c->m[i].data=(char*)h;
1728  }
1729  else
1730  x[i]=nlInit(0);
1731  }
1732  number n=n_ChineseRemainder(x,q,rl,currRing->cf);
1733  for(i=rl-1;i>=0;i--)
1734  {
1735  nlDelete(&(x[i]),currRing);
1736  }
1737  h=pHead(r);
1738  pSetCoeff(h,n);
1739  result=pAdd(result,h);
1740  }
1741  for(i=rl-1;i>=0;i--)
1742  {
1743  nlDelete(&(q[i]),currRing);
1744  }
1745  omFree(x); omFree(q);
1746  res->data=(char *)result;
1747  return FALSE;
1748 }
1749 #endif
1750 static BOOLEAN jjALIGN_V(leftv res, leftv u, leftv v)
1751 {
1752  poly p=(poly)u->CopyD();
1753  int s=(int)(long)v->Data();
1754  if (s+p_MinComp(p,currRing)<=0)
1755  { p_Delete(&p,currRing);return TRUE;}
1756  p_Shift(&p,s,currRing);
1757  res->data=p;
1758  return FALSE;
1759 }
1760 static BOOLEAN jjALIGN_M(leftv res, leftv u, leftv v)
1761 {
1762  ideal M=(ideal)u->CopyD();
1763  int s=(int)(long)v->Data();
1764  for(int i=IDELEMS(M)-1; i>=0;i--)
1765  {
1766  if (s+p_MinComp(M->m[i],currRing)<=0)
1767  { id_Delete(&M,currRing);return TRUE;}
1768  }
1769  id_Shift(M,s,currRing);
1770  res->data=M;
1771  return FALSE;
1772 }
1773 static BOOLEAN jjCHINREM_ID(leftv res, leftv u, leftv v);
1774 static BOOLEAN jjCOEF(leftv res, leftv u, leftv v)
1775 {
1776  poly p=(poly)v->Data();
1777  if ((p==NULL)||(pNext(p)!=NULL)) return TRUE;
1778  res->data=(char *)mp_CoeffProc((poly)u->Data(),p /*(poly)v->Data()*/,currRing);
1779  return FALSE;
1780 }
1782 {
1783  int i=pVar((poly)v->Data());
1784  if (i==0)
1785  {
1786  WerrorS("ringvar expected");
1787  return TRUE;
1788  }
1789  res->data=(char *)mp_Coeffs((ideal)u->CopyD(),i,currRing);
1790  return FALSE;
1791 }
1793 {
1794  poly p = pInit();
1795  int i;
1796  for (i=1; i<=currRing->N; i++)
1797  {
1798  pSetExp(p, i, 1);
1799  }
1800  pSetm(p);
1801  res->data = (void*)idCoeffOfKBase((ideal)(u->Data()),
1802  (ideal)(v->Data()), p);
1803  pDelete(&p);
1804  return FALSE;
1805 }
1807 {
1808  res->data=(char *)idDiffOp((ideal)u->Data(),(ideal)v->Data(),FALSE);
1809  return FALSE;
1810 }
1812 {
1813  short *iv=iv2array((intvec *)v->Data(),currRing);
1814  ideal I=(ideal)u->Data();
1815  int d=-1;
1816  int i;
1817  for(i=IDELEMS(I);i>=0;i--) d=si_max(d,(int)p_DegW(I->m[i],iv,currRing));
1818  omFreeSize( (ADDRESS)iv, (rVar(currRing)+1)*sizeof(short) );
1819  res->data = (char *)((long)d);
1820  return FALSE;
1821 }
1822 static BOOLEAN jjDEG_IV(leftv res, leftv u, leftv v)
1823 {
1824  poly p=(poly)u->Data();
1825  if (p!=NULL)
1826  {
1827  short *iv=iv2array((intvec *)v->Data(),currRing);
1828  const long d = p_DegW(p,iv,currRing);
1829  omFreeSize( (ADDRESS)iv, (rVar(currRing)+1)*sizeof(short) );
1830  res->data = (char *)(d);
1831  }
1832  else
1833  res->data=(char *)(long)(-1);
1834  return FALSE;
1835 }
1836 static BOOLEAN jjDIFF_P(leftv res, leftv u, leftv v)
1837 {
1838  int i=pVar((poly)v->Data());
1839  if (i==0)
1840  {
1841  WerrorS("ringvar expected");
1842  return TRUE;
1843  }
1844  res->data=(char *)pDiff((poly)(u->Data()),i);
1845  return FALSE;
1846 }
1847 static BOOLEAN jjDIFF_ID(leftv res, leftv u, leftv v)
1848 {
1849  int i=pVar((poly)v->Data());
1850  if (i==0)
1851  {
1852  WerrorS("ringvar expected");
1853  return TRUE;
1854  }
1855  res->data=(char *)idDiff((matrix)(u->Data()),i);
1856  return FALSE;
1857 }
1859 {
1860  res->data=(char *)idDiffOp((ideal)u->Data(),(ideal)v->Data());
1861  return FALSE;
1862 }
1863 static BOOLEAN jjDIM2(leftv res, leftv v, leftv w)
1864 {
1865  assumeStdFlag(v);
1867  {
1868  Warn("dim(%s,...) may be wrong because the mixed monomial ordering",v->Name());
1869  }
1870 #ifdef HAVE_RINGS
1871  if (rField_is_Ring(currRing))
1872  {
1873  //ring origR = currRing;
1874  //ring tempR = rCopy(origR);
1875  //coeffs new_cf=nInitChar(n_Q,NULL);
1876  //nKillChar(tempR->cf);
1877  //tempR->cf=new_cf;
1878  //rComplete(tempR);
1879  ideal vid = (ideal)v->Data();
1880  int i = idPosConstant(vid);
1881  if ((i != -1) && (n_IsUnit(pGetCoeff(vid->m[i]),currRing->cf)))
1882  { /* ideal v contains unit; dim = -1 */
1883  res->data = (char *)-1;
1884  return FALSE;
1885  }
1886  //rChangeCurrRing(tempR);
1887  //ideal vv = idrCopyR(vid, origR, currRing);
1888  ideal vv = id_Copy(vid, currRing);
1889  //ideal ww = idrCopyR((ideal)w->Data(), origR, currRing);
1890  ideal ww = id_Copy((ideal)w->Data(), currRing);
1891  /* drop degree zero generator from vv (if any) */
1892  if (i != -1) pDelete(&vv->m[i]);
1893  long d = (long)scDimInt(vv, ww);
1894  if (rField_is_Ring_Z(currRing) && (i == -1)) d++;
1895  res->data = (char *)d;
1896  idDelete(&vv); idDelete(&ww);
1897  //rChangeCurrRing(origR);
1898  //rDelete(tempR);
1899  return FALSE;
1900  }
1901 #endif
1902  if(currRing->qideal==NULL)
1903  res->data = (char *)((long)scDimInt((ideal)(v->Data()),(ideal)w->Data()));
1904  else
1905  {
1906  ideal q=idSimpleAdd(currRing->qideal,(ideal)w->Data());
1907  res->data = (char *)((long)scDimInt((ideal)(v->Data()),q));
1908  idDelete(&q);
1909  }
1910  return FALSE;
1911 }
1913 {
1914  ideal vi=(ideal)v->Data();
1915  int vl= IDELEMS(vi);
1916  ideal ui=(ideal)u->Data();
1917  unsigned ul= IDELEMS(ui);
1918  ideal R; matrix U;
1919  ideal m = idLift(vi,ui,&R, FALSE,hasFlag(v,FLAG_STD),TRUE,&U);
1920  if (m==NULL) return TRUE;
1921  // now make sure that all matices have the corect size:
1923  int i;
1924  if (MATCOLS(U) != (int)ul)
1925  {
1926  unsigned mul=si_min(ul,MATCOLS(U));
1927  matrix UU=mpNew(ul,ul);
1928  unsigned j;
1929  for(i=mul;i>0;i--)
1930  {
1931  for(j=mul;j>0;j--)
1932  {
1933  MATELEM(UU,i,j)=MATELEM(U,i,j);
1934  MATELEM(U,i,j)=NULL;
1935  }
1936  }
1937  idDelete((ideal *)&U);
1938  U=UU;
1939  }
1940  // make sure that U is a diagonal matrix of units
1941  for(i=ul;i>0;i--)
1942  {
1943  if(MATELEM(U,i,i)==NULL) MATELEM(U,i,i)=pOne();
1944  }
1946  L->Init(3);
1947  L->m[0].rtyp=MATRIX_CMD; L->m[0].data=(void *)T;
1948  L->m[1].rtyp=u->Typ(); L->m[1].data=(void *)R;
1949  L->m[2].rtyp=MATRIX_CMD; L->m[2].data=(void *)U;
1950  res->data=(char *)L;
1951  return FALSE;
1952 }
1953 static BOOLEAN jjELIMIN(leftv res, leftv u, leftv v)
1954 {
1955  res->data=(char *)idElimination((ideal)u->Data(),(poly)v->Data());
1956  //setFlag(res,FLAG_STD);
1957  return v->next!=NULL; //do not allow next like in eliminate(I,a(1..4))
1958 }
1960 {
1961  poly p=pOne();
1962  intvec *iv=(intvec*)v->Data();
1963  for(int i=iv->length()-1; i>=0; i--)
1964  {
1965  pSetExp(p,(*iv)[i],1);
1966  }
1967  pSetm(p);
1968  res->data=(char *)idElimination((ideal)u->Data(),p);
1969  pLmDelete(&p);
1970  //setFlag(res,FLAG_STD);
1971  return FALSE;
1972 }
1974 {
1975  //Print("exportto %s -> %s\n",v->Name(),u->Name() );
1976  return iiExport(v,0,IDPACKAGE((idhdl)u->data));
1977 }
1979 {
1980  WerrorS((char *)u->Data());
1981  extern int inerror;
1982  inerror=3;
1983  return TRUE;
1984 }
1986 {
1987  number uu=(number)u->Data();number vv=(number)v->Data();
1989  number a,b;
1990  number p0=n_ExtGcd(uu,vv,&a,&b,coeffs_BIGINT);
1991  L->Init(3);
1992  L->m[0].rtyp=BIGINT_CMD; L->m[0].data=(void *)p0;
1993  L->m[1].rtyp=BIGINT_CMD; L->m[1].data=(void *)a;
1994  L->m[2].rtyp=BIGINT_CMD; L->m[2].data=(void *)b;
1995  res->rtyp=LIST_CMD;
1996  res->data=(char *)L;
1997  return FALSE;
1998 }
2000 {
2001  int uu=(int)(long)u->Data();int vv=(int)(long)v->Data();
2002  int p0=ABS(uu),p1=ABS(vv);
2003  int f0 = 1, f1 = 0, g0 = 0, g1 = 1, q, r;
2004 
2005  while ( p1!=0 )
2006  {
2007  q=p0 / p1;
2008  r=p0 % p1;
2009  p0 = p1; p1 = r;
2010  r = g0 - g1 * q;
2011  g0 = g1; g1 = r;
2012  r = f0 - f1 * q;
2013  f0 = f1; f1 = r;
2014  }
2015  int a = f0;
2016  int b = g0;
2017  if ( uu /*(int)(long)u->Data()*/ < 0 ) a=-a;
2018  if ( vv /*(int)(long)v->Data()*/ < 0 ) b=-b;
2020  L->Init(3);
2021  L->m[0].rtyp=INT_CMD; L->m[0].data=(void *)(long)p0;
2022  L->m[1].rtyp=INT_CMD; L->m[1].data=(void *)(long)a;
2023  L->m[2].rtyp=INT_CMD; L->m[2].data=(void *)(long)b;
2024  res->rtyp=LIST_CMD;
2025  res->data=(char *)L;
2026  return FALSE;
2027 }
2029 {
2030  poly r,pa,pb;
2031  BOOLEAN ret=singclap_extgcd((poly)u->Data(),(poly)v->Data(),r,pa,pb,currRing);
2032  if (ret) return TRUE;
2034  L->Init(3);
2035  res->data=(char *)L;
2036  L->m[0].data=(void *)r;
2037  L->m[0].rtyp=POLY_CMD;
2038  L->m[1].data=(void *)pa;
2039  L->m[1].rtyp=POLY_CMD;
2040  L->m[2].data=(void *)pb;
2041  L->m[2].rtyp=POLY_CMD;
2042  return FALSE;
2043 }
2044 extern int singclap_factorize_retry;
2045 static BOOLEAN jjFAC_P2(leftv res, leftv u,leftv dummy)
2046 {
2047  intvec *v=NULL;
2048  int sw=(int)(long)dummy->Data();
2049  int fac_sw=sw;
2050  if ((sw<0)||(sw>2)) fac_sw=1;
2051  singclap_factorize_retry=0;
2052  ideal f=singclap_factorize((poly)(u->CopyD()), &v, fac_sw,currRing);
2053  if (f==NULL)
2054  return TRUE;
2055  switch(sw)
2056  {
2057  case 0:
2058  case 2:
2059  {
2061  l->Init(2);
2062  l->m[0].rtyp=IDEAL_CMD;
2063  l->m[0].data=(void *)f;
2064  l->m[1].rtyp=INTVEC_CMD;
2065  l->m[1].data=(void *)v;
2066  res->data=(void *)l;
2067  res->rtyp=LIST_CMD;
2068  return FALSE;
2069  }
2070  case 1:
2071  res->data=(void *)f;
2072  return FALSE;
2073  case 3:
2074  {
2075  poly p=f->m[0];
2076  int i=IDELEMS(f);
2077  f->m[0]=NULL;
2078  while(i>1)
2079  {
2080  i--;
2081  p=pMult(p,f->m[i]);
2082  f->m[i]=NULL;
2083  }
2084  res->data=(void *)p;
2085  res->rtyp=POLY_CMD;
2086  }
2087  return FALSE;
2088  }
2089  WerrorS("invalid switch");
2090  return TRUE;
2091 }
2093 {
2094  ideal_list p,h;
2095  h=kStdfac((ideal)v->Data(),NULL,testHomog,NULL,(ideal)w->Data());
2096  p=h;
2097  int l=0;
2098  while (p!=NULL) { p=p->next;l++; }
2100  L->Init(l);
2101  l=0;
2102  while(h!=NULL)
2103  {
2104  L->m[l].data=(char *)h->d;
2105  L->m[l].rtyp=IDEAL_CMD;
2106  p=h->next;
2107  omFreeSize(h,sizeof(*h));
2108  h=p;
2109  l++;
2110  }
2111  res->data=(void *)L;
2112  return FALSE;
2113 }
2115 {
2116  if (rField_is_Q(currRing))
2117  {
2118  number uu=(number)u->Data();
2119  number vv=(number)v->Data();
2120  res->data=(char *)n_Farey(uu,vv,currRing->cf);
2121  return FALSE;
2122  }
2123  else return TRUE;
2124 }
2126 {
2127  ideal uu=(ideal)u->Data();
2128  number vv=(number)v->Data();
2129  res->data=(void*)id_Farey(uu,vv,currRing);
2130  return FALSE;
2131 }
2132 static BOOLEAN jjFAREY_LI(leftv res, leftv u, leftv v);
2133 static BOOLEAN jjFETCH(leftv res, leftv u, leftv v)
2134 {
2135  ring r=(ring)u->Data();
2136  idhdl w;
2137  int op=iiOp;
2138  nMapFunc nMap;
2139 
2140  if ((w=r->idroot->get(v->Name(),myynest))!=NULL)
2141  {
2142  int *perm=NULL;
2143  int *par_perm=NULL;
2144  int par_perm_size=0;
2145  BOOLEAN bo;
2146  if ((nMap=n_SetMap(r->cf,currRing->cf))==NULL)
2147  {
2148  // Allow imap/fetch to be make an exception only for:
2149  if ( (rField_is_Q_a(r) && // Q(a..) -> Q(a..) || Q || Zp || Zp(a)
2152  ||
2153  (rField_is_Zp_a(r) && // Zp(a..) -> Zp(a..) || Zp
2154  (rField_is_Zp(currRing, r->cf->ch) ||
2155  rField_is_Zp_a(currRing, r->cf->ch))) )
2156  {
2157  par_perm_size=rPar(r);
2158  }
2159  else
2160  {
2161  goto err_fetch;
2162  }
2163  }
2164  if ((iiOp!=FETCH_CMD) || (r->N!=currRing->N) || (rPar(r)!=rPar(currRing)))
2165  {
2166  perm=(int *)omAlloc0((r->N+1)*sizeof(int));
2167  if (par_perm_size!=0)
2168  par_perm=(int *)omAlloc0(par_perm_size*sizeof(int));
2169  op=IMAP_CMD;
2170  if (iiOp==IMAP_CMD)
2171  {
2172  int r_par=0;
2173  char ** r_par_names=NULL;
2174  if (r->cf->extRing!=NULL)
2175  {
2176  r_par=r->cf->extRing->N;
2177  r_par_names=r->cf->extRing->names;
2178  }
2179  int c_par=0;
2180  char ** c_par_names=NULL;
2181  if (currRing->cf->extRing!=NULL)
2182  {
2183  c_par=currRing->cf->extRing->N;
2184  c_par_names=currRing->cf->extRing->names;
2185  }
2186  maFindPerm(r->names, r->N, r_par_names, r_par,
2187  currRing->names,currRing->N,c_par_names, c_par,
2188  perm,par_perm, currRing->cf->type);
2189  }
2190  else
2191  {
2192  unsigned i;
2193  if (par_perm_size!=0)
2194  for(i=si_min(rPar(r),rPar(currRing));i>0;i--) par_perm[i-1]=-i;
2195  for(i=si_min(r->N,currRing->N);i>0;i--) perm[i]=i;
2196  }
2197  }
2198  if ((iiOp==FETCH_CMD) &&(BVERBOSE(V_IMAP)))
2199  {
2200  unsigned i;
2201  for(i=0;i<(unsigned)si_min(r->N,currRing->N);i++)
2202  {
2203  Print("// var nr %d: %s -> %s\n",i,r->names[i],currRing->names[i]);
2204  }
2205  for(i=0;i<(unsigned)si_min(rPar(r),rPar(currRing));i++) // possibly empty loop
2206  {
2207  Print("// par nr %d: %s -> %s\n",
2208  i,rParameter(r)[i],rParameter(currRing)[i]);
2209  }
2210  }
2211  if (IDTYP(w)==ALIAS_CMD) w=(idhdl)IDDATA(w);
2212  sleftv tmpW;
2213  memset(&tmpW,0,sizeof(sleftv));
2214  tmpW.rtyp=IDTYP(w);
2215  tmpW.data=IDDATA(w);
2216  if ((bo=maApplyFetch(op,NULL,res,&tmpW, r,
2217  perm,par_perm,par_perm_size,nMap)))
2218  {
2219  Werror("cannot map %s of type %s(%d)",v->name, Tok2Cmdname(w->typ),w->typ);
2220  }
2221  if (perm!=NULL)
2222  omFreeSize((ADDRESS)perm,(r->N+1)*sizeof(int));
2223  if (par_perm!=NULL)
2224  omFreeSize((ADDRESS)par_perm,par_perm_size*sizeof(int));
2225  return bo;
2226  }
2227  else
2228  {
2229  Werror("identifier %s not found in %s",v->Fullname(),u->Fullname());
2230  }
2231  return TRUE;
2232 err_fetch:
2233  Werror("no identity map from %s (%s -> %s)",u->Fullname(),
2234  nCoeffString(r->cf),
2235  nCoeffString(currRing->cf));
2236  return TRUE;
2237 }
2238 static BOOLEAN jjFIND2(leftv res, leftv u, leftv v)
2239 {
2240  /*4
2241  * look for the substring what in the string where
2242  * return the position of the first char of what in where
2243  * or 0
2244  */
2245  char *where=(char *)u->Data();
2246  char *what=(char *)v->Data();
2247  char *found = strstr(where,what);
2248  if (found != NULL)
2249  {
2250  res->data=(char *)((found-where)+1);
2251  }
2252  /*else res->data=NULL;*/
2253  return FALSE;
2254 }
2255 static BOOLEAN jjFWALK(leftv res, leftv u, leftv v)
2256 {
2257  res->data=(char *)fractalWalkProc(u,v);
2258  setFlag( res, FLAG_STD );
2259  return FALSE;
2260 }
2261 static BOOLEAN jjGCD_I(leftv res, leftv u, leftv v)
2262 {
2263  int uu=(int)(long)u->Data();int vv=(int)(long)v->Data();
2264  int p0=ABS(uu),p1=ABS(vv);
2265  int r;
2266  while ( p1!=0 )
2267  {
2268  r=p0 % p1;
2269  p0 = p1; p1 = r;
2270  }
2271  res->rtyp=INT_CMD;
2272  res->data=(char *)(long)p0;
2273  return FALSE;
2274 }
2275 static BOOLEAN jjGCD_BI(leftv res, leftv u, leftv v)
2276 {
2277  number n1 = (number) u->Data();
2278  number n2 = (number) v->Data();
2279  res->data = n_Gcd(n1,n2,coeffs_BIGINT);
2280  return FALSE;
2281 }
2282 static BOOLEAN jjGCD_N(leftv res, leftv u, leftv v)
2283 {
2284  number a=(number) u->Data();
2285  number b=(number) v->Data();
2286  if (nIsZero(a))
2287  {
2288  if (nIsZero(b)) res->data=(char *)nInit(1);
2289  else res->data=(char *)nCopy(b);
2290  }
2291  else
2292  {
2293  if (nIsZero(b)) res->data=(char *)nCopy(a);
2294  //else res->data=(char *)n_Gcd(a, b, currRing->cf);
2295  else res->data=(char *)n_SubringGcd(a, b, currRing->cf);
2296  }
2297  return FALSE;
2298 }
2299 static BOOLEAN jjGCD_P(leftv res, leftv u, leftv v)
2300 {
2301  res->data=(void *)singclap_gcd((poly)(u->CopyD(POLY_CMD)),
2302  (poly)(v->CopyD(POLY_CMD)),currRing);
2303  return FALSE;
2304 }
2306 {
2307 #ifdef HAVE_RINGS
2309  {
2310  ring origR = currRing;
2311  ring tempR = rCopy(origR);
2312  coeffs new_cf=nInitChar(n_Q,NULL);
2313  nKillChar(tempR->cf);
2314  tempR->cf=new_cf;
2315  rComplete(tempR);
2316  ideal uid = (ideal)u->Data();
2317  rChangeCurrRing(tempR);
2318  ideal uu = idrCopyR(uid, origR, currRing);
2319  sleftv uuAsLeftv; memset(&uuAsLeftv, 0, sizeof(uuAsLeftv));
2320  uuAsLeftv.rtyp = IDEAL_CMD;
2321  uuAsLeftv.data = uu; uuAsLeftv.next = NULL;
2322  if (hasFlag(u, FLAG_STD)) setFlag(&uuAsLeftv,FLAG_STD);
2323  assumeStdFlag(&uuAsLeftv);
2324  PrintS("// NOTE: computation of Hilbert series etc. is being\n");
2325  PrintS("// performed for generic fibre, that is, over Q\n");
2326  intvec *module_w=(intvec*)atGet(&uuAsLeftv,"isHomog",INTVEC_CMD);
2327  intvec *iv=hFirstSeries(uu,module_w,currRing->qideal);
2328  int returnWithTrue = 1;
2329  switch((int)(long)v->Data())
2330  {
2331  case 1:
2332  res->data=(void *)iv;
2333  returnWithTrue = 0;
2334  case 2:
2335  res->data=(void *)hSecondSeries(iv);
2336  delete iv;
2337  returnWithTrue = 0;
2338  }
2339  if (returnWithTrue)
2340  {
2342  delete iv;
2343  }
2344  idDelete(&uu);
2345  rChangeCurrRing(origR);
2346  rDelete(tempR);
2347  if (returnWithTrue) return TRUE; else return FALSE;
2348  }
2349 #endif
2350  assumeStdFlag(u);
2351  intvec *module_w=(intvec*)atGet(u,"isHomog",INTVEC_CMD);
2352  intvec *iv=hFirstSeries((ideal)u->Data(),module_w,currRing->qideal);
2353  switch((int)(long)v->Data())
2354  {
2355  case 1:
2356  res->data=(void *)iv;
2357  return FALSE;
2358  case 2:
2359  res->data=(void *)hSecondSeries(iv);
2360  delete iv;
2361  return FALSE;
2362  }
2363  delete iv;
2365  return TRUE;
2366 }
2367 static BOOLEAN jjHOMOG_P(leftv res, leftv u, leftv v)
2368 {
2369  int i=pVar((poly)v->Data());
2370  if (i==0)
2371  {
2372  WerrorS("ringvar expected");
2373  return TRUE;
2374  }
2375  poly p=pOne(); pSetExp(p,i,1); pSetm(p);
2376  int d=pWTotaldegree(p);
2377  pLmDelete(p);
2378  if (d==1)
2379  res->data = (char *)p_Homogen((poly)u->Data(), i, currRing);
2380  else
2381  WerrorS("variable must have weight 1");
2382  return (d!=1);
2383 }
2385 {
2386  int i=pVar((poly)v->Data());
2387  if (i==0)
2388  {
2389  WerrorS("ringvar expected");
2390  return TRUE;
2391  }
2392  pFDegProc deg;
2393  if (currRing->pLexOrder && (currRing->order[0]==ringorder_lp))
2394  deg=p_Totaldegree;
2395  else
2396  deg=currRing->pFDeg;
2397  poly p=pOne(); pSetExp(p,i,1); pSetm(p);
2398  int d=deg(p,currRing);
2399  pLmDelete(p);
2400  if (d==1)
2401  res->data = (char *)id_Homogen((ideal)u->Data(), i, currRing);
2402  else
2403  WerrorS("variable must have weight 1");
2404  return (d!=1);
2405 }
2407 {
2408  intvec *w=new intvec(rVar(currRing));
2409  intvec *vw=(intvec*)u->Data();
2410  ideal v_id=(ideal)v->Data();
2411  pFDegProc save_FDeg=currRing->pFDeg;
2412  pLDegProc save_LDeg=currRing->pLDeg;
2413  BOOLEAN save_pLexOrder=currRing->pLexOrder;
2414  currRing->pLexOrder=FALSE;
2415  kHomW=vw;
2416  kModW=w;
2418  res->data=(void *)(long)idHomModule(v_id,currRing->qideal,&w);
2419  currRing->pLexOrder=save_pLexOrder;
2420  kHomW=NULL;
2421  kModW=NULL;
2422  pRestoreDegProcs(currRing,save_FDeg,save_LDeg);
2423  if (w!=NULL) delete w;
2424  return FALSE;
2425 }
2427 {
2428  assumeStdFlag(u);
2429  res->data=(void *)scIndIndset((ideal)(u->Data()),(int)(long)(v->Data()),
2430  currRing->qideal);
2431  return FALSE;
2432 }
2434 {
2435  res->data=(char *)idSect((ideal)u->Data(),(ideal)v->Data());
2437  return FALSE;
2438 }
2440 {
2441  const lists L = (lists)l->Data();
2442  const int n = L->nr; assume (n >= 0);
2443  std::vector<ideal> V(n + 1);
2444 
2445  for(int i = n; i >= 0; i--) V[i] = (ideal)(L->m[i].Data());
2446 
2447  res->data=interpolation(V, (intvec*)v->Data());
2448  setFlag(res,FLAG_STD);
2449  return errorreported;
2450 }
2452 {
2453  extern BOOLEAN jjStdJanetBasis(leftv res, leftv v,int flag);
2454  return jjStdJanetBasis(res,u,(int)(long)v->Data());
2455 }
2456 
2458 {
2459  extern BOOLEAN jjStdJanetBasis(leftv res, leftv v,int flag);
2460  return jjStdJanetBasis(res,v,0);
2461 }
2462 static BOOLEAN jjJET_P(leftv res, leftv u, leftv v)
2463 {
2464  res->data = (char *)pJet((poly)u->CopyD(), (int)(long)v->Data());
2465  return FALSE;
2466 }
2467 static BOOLEAN jjJET_ID(leftv res, leftv u, leftv v)
2468 {
2469  res->data = (char *)id_Jet((ideal)u->Data(),(int)(long)v->Data(),currRing);
2470  return FALSE;
2471 }
2472 static BOOLEAN jjKBASE2(leftv res, leftv u, leftv v)
2473 {
2474  assumeStdFlag(u);
2475  intvec *w_u=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
2476  res->data = (char *)scKBase((int)(long)v->Data(),
2477  (ideal)(u->Data()),currRing->qideal, w_u);
2478  if (w_u!=NULL)
2479  {
2480  atSet(res,omStrDup("isHomog"),ivCopy(w_u),INTVEC_CMD);
2481  }
2482  return FALSE;
2483 }
2484 static BOOLEAN jjPREIMAGE(leftv res, leftv u, leftv v, leftv w);
2485 static BOOLEAN jjKERNEL(leftv res, leftv u, leftv v)
2486 {
2487  return jjPREIMAGE(res,u,v,NULL);
2488 }
2489 static BOOLEAN jjKoszul(leftv res, leftv u, leftv v)
2490 {
2491  return mpKoszul(res, u,v,NULL);
2492 }
2494 {
2495  sleftv h;
2496  memset(&h,0,sizeof(sleftv));
2497  h.rtyp=INT_CMD;
2498  h.data=(void *)(long)IDELEMS((ideal)v->Data());
2499  return mpKoszul(res, u, &h, v);
2500 }
2501 static BOOLEAN jjLIFT(leftv res, leftv u, leftv v)
2502 {
2503  int ul= IDELEMS((ideal)u->Data());
2504  int vl= IDELEMS((ideal)v->Data());
2505  ideal m = idLift((ideal)u->Data(),(ideal)v->Data(),NULL,FALSE,
2506  hasFlag(u,FLAG_STD));
2507  if (m==NULL) return TRUE;
2508  res->data = (char *)id_Module2formatedMatrix(m,ul,vl,currRing);
2509  return FALSE;
2510 }
2511 static BOOLEAN jjLIFTSTD(leftv res, leftv u, leftv v)
2512 {
2513  if ((v->rtyp!=IDHDL)||(v->e!=NULL)) return TRUE;
2514  idhdl h=(idhdl)v->data;
2515  // CopyD for IDEAL_CMD and MODUL_CMD are identical:
2516  res->data = (char *)idLiftStd((ideal)u->Data(),
2517  &(h->data.umatrix),testHomog);
2518  setFlag(res,FLAG_STD); v->flag=0;
2519  return FALSE;
2520 }
2521 static BOOLEAN jjLOAD2(leftv /*res*/, leftv/* LIB */ , leftv v)
2522 {
2523  return jjLOAD((char*)v->Data(),TRUE);
2524 }
2525 static BOOLEAN jjLOAD_E(leftv /*res*/, leftv v, leftv u)
2526 {
2527  char * s=(char *)u->Data();
2528  if(strcmp(s, "with")==0)
2529  return jjLOAD((char*)v->Data(), TRUE);
2530  if (strcmp(s,"try")==0)
2531  return jjLOAD_TRY((char*)v->Data());
2532  WerrorS("invalid second argument");
2533  WerrorS("load(\"libname\" [,option]);");
2534  return TRUE;
2535 }
2536 static BOOLEAN jjMODULO(leftv res, leftv u, leftv v)
2537 {
2538  intvec *w_u=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
2539  tHomog hom=testHomog;
2540  if (w_u!=NULL)
2541  {
2542  w_u=ivCopy(w_u);
2543  hom=isHomog;
2544  }
2545  intvec *w_v=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
2546  if (w_v!=NULL)
2547  {
2548  w_v=ivCopy(w_v);
2549  hom=isHomog;
2550  }
2551  if ((w_u!=NULL) && (w_v==NULL))
2552  w_v=ivCopy(w_u);
2553  if ((w_v!=NULL) && (w_u==NULL))
2554  w_u=ivCopy(w_v);
2555  ideal u_id=(ideal)u->Data();
2556  ideal v_id=(ideal)v->Data();
2557  if (w_u!=NULL)
2558  {
2559  if ((*w_u).compare((w_v))!=0)
2560  {
2561  WarnS("incompatible weights");
2562  delete w_u; w_u=NULL;
2563  hom=testHomog;
2564  }
2565  else
2566  {
2567  if ((!idTestHomModule(u_id,currRing->qideal,w_v))
2568  || (!idTestHomModule(v_id,currRing->qideal,w_v)))
2569  {
2570  WarnS("wrong weights");
2571  delete w_u; w_u=NULL;
2572  hom=testHomog;
2573  }
2574  }
2575  }
2576  res->data = (char *)idModulo(u_id,v_id ,hom,&w_u);
2577  if (w_u!=NULL)
2578  {
2579  atSet(res,omStrDup("isHomog"),w_u,INTVEC_CMD);
2580  }
2581  delete w_v;
2582  //if (TEST_OPT_RETURN_SB) setFlag(res,FLAG_STD);
2583  return FALSE;
2584 }
2585 static BOOLEAN jjMOD_BI(leftv res, leftv u, leftv v)
2586 {
2587  number q=(number)v->Data();
2588  if (n_IsZero(q,coeffs_BIGINT))
2589  {
2591  return TRUE;
2592  }
2593  res->data =(char *) n_IntMod((number)u->Data(),q,coeffs_BIGINT);
2594  return FALSE;
2595 }
2596 static BOOLEAN jjMOD_N(leftv res, leftv u, leftv v)
2597 {
2598  number q=(number)v->Data();
2599  if (nIsZero(q))
2600  {
2602  return TRUE;
2603  }
2604  res->data =(char *) n_IntMod((number)u->Data(),q,currRing->cf);
2605  return FALSE;
2606 }
2607 static BOOLEAN jjMONITOR2(leftv res, leftv u,leftv v);
2609 {
2610  return jjMONITOR2(res,v,NULL);
2611 }
2613 {
2614 #if 0
2615  char *opt=(char *)v->Data();
2616  int mode=0;
2617  while(*opt!='\0')
2618  {
2619  if (*opt=='i') mode |= SI_PROT_I;
2620  else if (*opt=='o') mode |= SI_PROT_O;
2621  opt++;
2622  }
2623  monitor((char *)(u->Data()),mode);
2624 #else
2625  si_link l=(si_link)u->Data();
2626  if (slOpen(l,SI_LINK_WRITE,u)) return TRUE;
2627  if(strcmp(l->m->type,"ASCII")!=0)
2628  {
2629  Werror("ASCII link required, not `%s`",l->m->type);
2630  slClose(l);
2631  return TRUE;
2632  }
2633  SI_LINK_SET_CLOSE_P(l); // febase handles the FILE*
2634  if ( l->name[0]!='\0') // "" is the stop condition
2635  {
2636  const char *opt;
2637  int mode=0;
2638  if (v==NULL) opt=(const char*)"i";
2639  else opt=(const char *)v->Data();
2640  while(*opt!='\0')
2641  {
2642  if (*opt=='i') mode |= SI_PROT_I;
2643  else if (*opt=='o') mode |= SI_PROT_O;
2644  opt++;
2645  }
2646  monitor((FILE *)l->data,mode);
2647  }
2648  else
2649  monitor(NULL,0);
2650  return FALSE;
2651 #endif
2652 }
2653 static BOOLEAN jjMONOM(leftv res, leftv v)
2654 {
2655  intvec *iv=(intvec *)v->Data();
2656  poly p=pOne();
2657  int e;
2658  BOOLEAN err=FALSE;
2659  for(unsigned i=si_min(currRing->N,iv->length()); i>0; i--)
2660  {
2661  e=(*iv)[i-1];
2662  if (e>=0) pSetExp(p,i,e);
2663  else err=TRUE;
2664  }
2665  if (iv->length()==(currRing->N+1))
2666  {
2667  res->rtyp=VECTOR_CMD;
2668  e=(*iv)[currRing->N];
2669  if (e>=0) pSetComp(p,e);
2670  else err=TRUE;
2671  }
2672  pSetm(p);
2673  res->data=(char*)p;
2674  if(err) { pDelete(&p); WerrorS("no negative exponent allowed"); }
2675  return err;
2676 }
2678 {
2679  // u: the name of the new type
2680  // v: the elements
2681  newstruct_desc d=newstructFromString((const char *)v->Data());
2682  if (d!=NULL) newstruct_setup((const char *)u->Data(),d);
2683  return d==NULL;
2684 }
2685 static BOOLEAN jjPARSTR2(leftv res, leftv u, leftv v)
2686 {
2687  idhdl h=(idhdl)u->data;
2688  int i=(int)(long)v->Data();
2689  int p=0;
2690  if ((0<i)
2691  && (rParameter(IDRING(h))!=NULL)
2692  && (i<=(p=rPar(IDRING(h)))))
2693  res->data=omStrDup(rParameter(IDRING(h))[i-1]);
2694  else
2695  {
2696  Werror("par number %d out of range 1..%d",i,p);
2697  return TRUE;
2698  }
2699  return FALSE;
2700 }
2701 #ifdef HAVE_PLURAL
2703 {
2704  if( currRing->qideal != NULL )
2705  {
2706  WerrorS("basering must NOT be a qring!");
2707  return TRUE;
2708  }
2709 
2710  if (iiOp==NCALGEBRA_CMD)
2711  {
2712  return nc_CallPlural(NULL,NULL,(poly)a->Data(),(poly)b->Data(),currRing,false,true,false,currRing);
2713  }
2714  else
2715  {
2716  ring r=rCopy(currRing);
2717  BOOLEAN result=nc_CallPlural(NULL,NULL,(poly)a->Data(),(poly)b->Data(),r,false,true,false,currRing);
2718  res->data=r;
2719  return result;
2720  }
2721 }
2723 {
2724  if( currRing->qideal != NULL )
2725  {
2726  WerrorS("basering must NOT be a qring!");
2727  return TRUE;
2728  }
2729 
2730  if (iiOp==NCALGEBRA_CMD)
2731  {
2732  return nc_CallPlural(NULL,(matrix)b->Data(),(poly)a->Data(),NULL,currRing,false,true,false,currRing);
2733  }
2734  else
2735  {
2736  ring r=rCopy(currRing);
2737  BOOLEAN result=nc_CallPlural(NULL,(matrix)b->Data(),(poly)a->Data(),NULL,r,false,true,false,currRing);
2738  res->data=r;
2739  return result;
2740  }
2741 }
2743 {
2744  if( currRing->qideal != NULL )
2745  {
2746  WerrorS("basering must NOT be a qring!");
2747  return TRUE;
2748  }
2749 
2750  if (iiOp==NCALGEBRA_CMD)
2751  {
2752  return nc_CallPlural((matrix)a->Data(),NULL,NULL,(poly)b->Data(),currRing,false,true,false,currRing);
2753  }
2754  else
2755  {
2756  ring r=rCopy(currRing);
2757  BOOLEAN result=nc_CallPlural((matrix)a->Data(),NULL,NULL,(poly)b->Data(),r,false,true,false,currRing);
2758  res->data=r;
2759  return result;
2760  }
2761 }
2763 {
2764  if( currRing->qideal != NULL )
2765  {
2766  WerrorS("basering must NOT be a qring!");
2767  return TRUE;
2768  }
2769 
2770  if (iiOp==NCALGEBRA_CMD)
2771  {
2772  return nc_CallPlural((matrix)a->Data(),(matrix)b->Data(),NULL,NULL,currRing,false,true,false,currRing);
2773  }
2774  else
2775  {
2776  ring r=rCopy(currRing);
2777  BOOLEAN result=nc_CallPlural((matrix)a->Data(),(matrix)b->Data(),NULL,NULL,r,false,true,false,currRing);
2778  res->data=r;
2779  return result;
2780  }
2781 }
2783 {
2784  res->data=NULL;
2785 
2786  if (rIsPluralRing(currRing))
2787  {
2788  const poly q = (poly)b->Data();
2789 
2790  if( q != NULL )
2791  {
2792  if( (poly)a->Data() != NULL )
2793  {
2794  poly p = (poly)a->CopyD(POLY_CMD); // p = copy!
2795  res->data = nc_p_Bracket_qq(p,q, currRing); // p will be destroyed!
2796  }
2797  }
2798  }
2799  return FALSE;
2800 }
2802 {
2803  /* number, poly, vector, ideal, module, matrix */
2804  ring r = (ring)a->Data();
2805  if (r == currRing)
2806  {
2807  res->data = b->Data();
2808  res->rtyp = b->rtyp;
2809  return FALSE;
2810  }
2811  if (!rIsLikeOpposite(currRing, r))
2812  {
2813  Werror("%s is not an opposite ring to current ring",a->Fullname());
2814  return TRUE;
2815  }
2816  idhdl w;
2817  if( ((w=r->idroot->get(b->Name(),myynest))!=NULL) && (b->e==NULL))
2818  {
2819  int argtype = IDTYP(w);
2820  switch (argtype)
2821  {
2822  case NUMBER_CMD:
2823  {
2824  /* since basefields are equal, we can apply nCopy */
2825  res->data = nCopy((number)IDDATA(w));
2826  res->rtyp = argtype;
2827  break;
2828  }
2829  case POLY_CMD:
2830  case VECTOR_CMD:
2831  {
2832  poly q = (poly)IDDATA(w);
2833  res->data = pOppose(r,q,currRing);
2834  res->rtyp = argtype;
2835  break;
2836  }
2837  case IDEAL_CMD:
2838  case MODUL_CMD:
2839  {
2840  ideal Q = (ideal)IDDATA(w);
2841  res->data = idOppose(r,Q,currRing);
2842  res->rtyp = argtype;
2843  break;
2844  }
2845  case MATRIX_CMD:
2846  {
2847  ring save = currRing;
2848  rChangeCurrRing(r);
2849  matrix m = (matrix)IDDATA(w);
2851  rChangeCurrRing(save);
2852  ideal S = idOppose(r,Q,currRing);
2853  id_Delete(&Q, r);
2854  res->data = id_Module2Matrix(S,currRing);
2855  res->rtyp = argtype;
2856  break;
2857  }
2858  default:
2859  {
2860  WerrorS("unsupported type in oppose");
2861  return TRUE;
2862  }
2863  }
2864  }
2865  else
2866  {
2867  Werror("identifier %s not found in %s",b->Fullname(),a->Fullname());
2868  return TRUE;
2869  }
2870  return FALSE;
2871 }
2872 #endif /* HAVE_PLURAL */
2873 
2874 static BOOLEAN jjQUOT(leftv res, leftv u, leftv v)
2875 {
2876  res->data = (char *)idQuot((ideal)u->Data(),(ideal)v->Data(),
2877  hasFlag(u,FLAG_STD),u->Typ()==v->Typ());
2878  id_DelMultiples((ideal)(res->data),currRing);
2880  return FALSE;
2881 }
2882 static BOOLEAN jjRANDOM(leftv res, leftv u, leftv v)
2883 {
2884  int i=(int)(long)u->Data();
2885  int j=(int)(long)v->Data();
2886  if (j-i <0) {WerrorS("invalid range for random"); return TRUE;}
2887  res->data =(char *)(long)((i > j) ? i : (siRand() % (j-i+1)) + i);
2888  return FALSE;
2889 }
2890 static BOOLEAN jjRANK2(leftv res, leftv u, leftv v)
2891 {
2892  matrix m =(matrix)u->Data();
2893  int isRowEchelon = (int)(long)v->Data();
2894  if (isRowEchelon != 1) isRowEchelon = 0;
2895  int rank = luRank(m, isRowEchelon);
2896  res->data =(char *)(long)rank;
2897  return FALSE;
2898 }
2899 static BOOLEAN jjREAD2(leftv res, leftv u, leftv v)
2900 {
2901  si_link l=(si_link)u->Data();
2902  leftv r=slRead(l,v);
2903  if (r==NULL)
2904  {
2905  const char *s;
2906  if ((l!=NULL)&&(l->name!=NULL)) s=l->name;
2907  else s=sNoName;
2908  Werror("cannot read from `%s`",s);
2909  return TRUE;
2910  }
2911  memcpy(res,r,sizeof(sleftv));
2913  return FALSE;
2914 }
2916 {
2917  ideal vi=(ideal)v->Data();
2918  if (currRing->qideal!=NULL || vi->ncols>1 || rIsPluralRing(currRing))
2919  assumeStdFlag(v);
2920  res->data = (char *)kNF(vi,currRing->qideal,(poly)u->Data());
2921  return FALSE;
2922 }
2924 {
2925  ideal ui=(ideal)u->Data();
2926  ideal vi=(ideal)v->Data();
2927  if (currRing->qideal!=NULL || vi->ncols>1 || rIsPluralRing(currRing))
2928  assumeStdFlag(v);
2929  res->data = (char *)kNF(vi,currRing->qideal,ui);
2930  return FALSE;
2931 }
2932 #if 0
2933 static BOOLEAN jjRES(leftv res, leftv u, leftv v)
2934 {
2935  int maxl=(int)(long)v->Data();
2936  if (maxl<0)
2937  {
2938  WerrorS("length for res must not be negative");
2939  return TRUE;
2940  }
2941  int l=0;
2942  //resolvente r;
2943  syStrategy r;
2944  intvec *weights=NULL;
2945  int wmaxl=maxl;
2946  ideal u_id=(ideal)u->Data();
2947 
2948  maxl--;
2949  if (/*(*/ maxl==-1 /*)*/) /*&& (iiOp!=MRES_CMD)*/
2950  {
2951  maxl = currRing->N-1+2*(iiOp==MRES_CMD);
2952  if (currRing->qideal!=NULL)
2953  {
2954  Warn(
2955  "full resolution in a qring may be infinite, setting max length to %d",
2956  maxl+1);
2957  }
2958  }
2959  weights=(intvec*)atGet(u,"isHomog",INTVEC_CMD);
2960  if (weights!=NULL)
2961  {
2962  if (!idTestHomModule(u_id,currRing->qideal,weights))
2963  {
2964  WarnS("wrong weights given:");weights->show();PrintLn();
2965  weights=NULL;
2966  }
2967  }
2968  intvec *ww=NULL;
2969  int add_row_shift=0;
2970  if (weights!=NULL)
2971  {
2972  ww=ivCopy(weights);
2973  add_row_shift = ww->min_in();
2974  (*ww) -= add_row_shift;
2975  }
2976  else
2977  idHomModule(u_id,currRing->qideal,&ww);
2978  weights=ww;
2979 
2980  if ((iiOp == RES_CMD) || (iiOp == MRES_CMD))
2981  {
2982  r=syResolution(u_id,maxl, ww, iiOp==MRES_CMD);
2983  }
2984  else if (iiOp==SRES_CMD)
2985  // r=sySchreyerResolvente(u_id,maxl+1,&l);
2986  r=sySchreyer(u_id,maxl+1);
2987  else if (iiOp == LRES_CMD)
2988  {
2989  int dummy;
2990  if((currRing->qideal!=NULL)||
2991  (!idHomIdeal (u_id,NULL)))
2992  {
2993  WerrorS
2994  ("`lres` not implemented for inhomogeneous input or qring");
2995  return TRUE;
2996  }
2997  r=syLaScala3(u_id,&dummy);
2998  }
2999  else if (iiOp == KRES_CMD)
3000  {
3001  int dummy;
3002  if((currRing->qideal!=NULL)||
3003  (!idHomIdeal (u_id,NULL)))
3004  {
3005  WerrorS
3006  ("`kres` not implemented for inhomogeneous input or qring");
3007  return TRUE;
3008  }
3009  r=syKosz(u_id,&dummy);
3010  }
3011  else
3012  {
3013  int dummy;
3014  if((currRing->qideal!=NULL)||
3015  (!idHomIdeal (u_id,NULL)))
3016  {
3017  WerrorS
3018  ("`hres` not implemented for inhomogeneous input or qring");
3019  return TRUE;
3020  }
3021  r=syHilb(u_id,&dummy);
3022  }
3023  if (r==NULL) return TRUE;
3024  //res->data=(void *)liMakeResolv(r,l,wmaxl,u->Typ(),weights);
3025  r->list_length=wmaxl;
3026  res->data=(void *)r;
3027  if ((r->weights!=NULL) && (r->weights[0]!=NULL))
3028  {
3029  intvec *w=ivCopy(r->weights[0]);
3030  if (weights!=NULL) (*w) += add_row_shift;
3031  atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
3032  w=NULL;
3033  }
3034  else
3035  {
3036 //#if 0
3037 // need to set weights for ALL components (sres)
3038  if (weights!=NULL)
3039  {
3040  atSet(res,omStrDup("isHomog"),ivCopy(weights),INTVEC_CMD);
3042  (r->weights)[0] = ivCopy(weights);
3043  }
3044 //#endif
3045  }
3046  if (ww!=NULL) { delete ww; ww=NULL; }
3047  return FALSE;
3048 }
3049 #else
3050 static BOOLEAN jjRES(leftv res, leftv u, leftv v)
3051 {
3052  int maxl=(int)(long)v->Data();
3053  if (maxl<0)
3054  {
3055  WerrorS("length for res must not be negative");
3056  return TRUE;
3057  }
3058  syStrategy r;
3059  intvec *weights=NULL;
3060  int wmaxl=maxl;
3061  ideal u_id=(ideal)u->Data();
3062 
3063  maxl--;
3064  if (/*(*/ maxl==-1 /*)*/) /*&& (iiOp!=MRES_CMD)*/
3065  {
3066  maxl = currRing->N-1+2*(iiOp==MRES_CMD);
3067  if (currRing->qideal!=NULL)
3068  {
3069  Warn(
3070  "full resolution in a qring may be infinite, setting max length to %d",
3071  maxl+1);
3072  }
3073  }
3074  weights=(intvec*)atGet(u,"isHomog",INTVEC_CMD);
3075  if (weights!=NULL)
3076  {
3077  if (!idTestHomModule(u_id,currRing->qideal,weights))
3078  {
3079  WarnS("wrong weights given:");weights->show();PrintLn();
3080  weights=NULL;
3081  }
3082  }
3083  intvec *ww=NULL;
3084  int add_row_shift=0;
3085  if (weights!=NULL)
3086  {
3087  ww=ivCopy(weights);
3088  add_row_shift = ww->min_in();
3089  (*ww) -= add_row_shift;
3090  }
3091  if ((iiOp == RES_CMD) || (iiOp == MRES_CMD))
3092  {
3093  r=syResolution(u_id,maxl, ww, iiOp==MRES_CMD);
3094  }
3095  else if (iiOp==SRES_CMD)
3096  // r=sySchreyerResolvente(u_id,maxl+1,&l);
3097  r=sySchreyer(u_id,maxl+1);
3098  else if (iiOp == LRES_CMD)
3099  {
3100  int dummy;
3101  if((currRing->qideal!=NULL)||
3102  (!idHomIdeal (u_id,NULL)))
3103  {
3104  WerrorS
3105  ("`lres` not implemented for inhomogeneous input or qring");
3106  return TRUE;
3107  }
3108  if(currRing->N == 1)
3109  WarnS("the current implementation of `lres` may not work in the case of a single variable");
3110  r=syLaScala3(u_id,&dummy);
3111  }
3112  else if (iiOp == KRES_CMD)
3113  {
3114  int dummy;
3115  if((currRing->qideal!=NULL)||
3116  (!idHomIdeal (u_id,NULL)))
3117  {
3118  WerrorS
3119  ("`kres` not implemented for inhomogeneous input or qring");
3120  return TRUE;
3121  }
3122  r=syKosz(u_id,&dummy);
3123  }
3124  else
3125  {
3126  int dummy;
3127  if((currRing->qideal!=NULL)||
3128  (!idHomIdeal (u_id,NULL)))
3129  {
3130  WerrorS
3131  ("`hres` not implemented for inhomogeneous input or qring");
3132  return TRUE;
3133  }
3134  ideal u_id_copy=idCopy(u_id);
3135  idSkipZeroes(u_id_copy);
3136  r=syHilb(u_id_copy,&dummy);
3137  idDelete(&u_id_copy);
3138  }
3139  if (r==NULL) return TRUE;
3140  //res->data=(void *)liMakeResolv(r,l,wmaxl,u->Typ(),weights);
3141  r->list_length=wmaxl;
3142  res->data=(void *)r;
3143  if ((weights!=NULL) && (ww!=NULL)) { delete ww; ww=NULL; }
3144  if ((r->weights!=NULL) && (r->weights[0]!=NULL))
3145  {
3146  ww=ivCopy(r->weights[0]);
3147  if (weights!=NULL) (*ww) += add_row_shift;
3148  atSet(res,omStrDup("isHomog"),ww,INTVEC_CMD);
3149  }
3150  else
3151  {
3152  if (weights!=NULL)
3153  {
3154  atSet(res,omStrDup("isHomog"),ivCopy(weights),INTVEC_CMD);
3155  }
3156  }
3157 
3158  // test the La Scala case' output
3159  assume( ((iiOp == LRES_CMD) || (iiOp == HRES_CMD)) == (r->syRing != NULL) );
3160  assume( (r->syRing != NULL) == (r->resPairs != NULL) );
3161 
3162  if(iiOp != HRES_CMD)
3163  assume( (r->minres != NULL) || (r->fullres != NULL) ); // is wrong for HRES_CMD...
3164  else
3165  assume( (r->orderedRes != NULL) || (r->res != NULL) ); // analog for hres...
3166 
3167  return FALSE;
3168 }
3169 #endif
3170 static BOOLEAN jjPFAC2(leftv res, leftv u, leftv v)
3171 {
3172  number n1; int i;
3173 
3174  if ((u->Typ() == BIGINT_CMD) ||
3175  ((u->Typ() == NUMBER_CMD) && rField_is_Q(currRing)))
3176  {
3177  n1 = (number)u->CopyD();
3178  }
3179  else if (u->Typ() == INT_CMD)
3180  {
3181  i = (int)(long)u->Data();
3182  n1 = n_Init(i, coeffs_BIGINT);
3183  }
3184  else
3185  {
3186  return TRUE;
3187  }
3188 
3189  i = (int)(long)v->Data();
3190 
3191  lists l = primeFactorisation(n1, i);
3192  n_Delete(&n1, coeffs_BIGINT);
3193  res->data = (char*)l;
3194  return FALSE;
3195 }
3196 static BOOLEAN jjRSUM(leftv res, leftv u, leftv v)
3197 {
3198  ring r;
3199  int i=rSum((ring)u->Data(),(ring)v->Data(),r);
3200  res->data = (char *)r;
3201  return (i==-1);
3202 }
3203 #define SIMPL_LMDIV 32
3204 #define SIMPL_LMEQ 16
3205 #define SIMPL_MULT 8
3206 #define SIMPL_EQU 4
3207 #define SIMPL_NULL 2
3208 #define SIMPL_NORM 1
3210 {
3211  int sw = (int)(long)v->Data();
3212  // CopyD for IDEAL_CMD and MODUL_CMD are identical:
3213  ideal id = (ideal)u->CopyD(IDEAL_CMD);
3214  if (sw & SIMPL_LMDIV)
3215  {
3216  id_DelDiv(id,currRing);
3217  }
3218  if (sw & SIMPL_LMEQ)
3219  {
3221  }
3222  if (sw & SIMPL_MULT)
3223  {
3225  }
3226  else if(sw & SIMPL_EQU)
3227  {
3228  id_DelEquals(id,currRing);
3229  }
3230  if (sw & SIMPL_NULL)
3231  {
3232  idSkipZeroes(id);
3233  }
3234  if (sw & SIMPL_NORM)
3235  {
3236  id_Norm(id,currRing);
3237  }
3238  res->data = (char * )id;
3239  return FALSE;
3240 }
3242 static BOOLEAN jjSQR_FREE2(leftv res, leftv u, leftv dummy)
3243 {
3244  intvec *v=NULL;
3245  int sw=(int)(long)dummy->Data();
3246  int fac_sw=sw;
3247  if (sw<0) fac_sw=1;
3248  singclap_factorize_retry=0;
3249  ideal f=singclap_sqrfree((poly)(u->CopyD()), &v, fac_sw, currRing);
3250  if (f==NULL)
3251  return TRUE;
3252  switch(sw)
3253  {
3254  case 0:
3255  case 2:
3256  {
3258  l->Init(2);
3259  l->m[0].rtyp=IDEAL_CMD;
3260  l->m[0].data=(void *)f;
3261  l->m[1].rtyp=INTVEC_CMD;
3262  l->m[1].data=(void *)v;
3263  res->data=(void *)l;
3264  res->rtyp=LIST_CMD;
3265  return FALSE;
3266  }
3267  case 1:
3268  res->data=(void *)f;
3269  return FALSE;
3270  case 3:
3271  {
3272  poly p=f->m[0];
3273  int i=IDELEMS(f);
3274  f->m[0]=NULL;
3275  while(i>1)
3276  {
3277  i--;
3278  p=pMult(p,f->m[i]);
3279  f->m[i]=NULL;
3280  }
3281  res->data=(void *)p;
3282  res->rtyp=POLY_CMD;
3283  }
3284  return FALSE;
3285  }
3286  WerrorS("invalid switch");
3287  return FALSE;
3288 }
3289 static BOOLEAN jjSTATUS2(leftv res, leftv u, leftv v)
3290 {
3291  res->data = omStrDup(slStatus((si_link) u->Data(), (char *) v->Data()));
3292  return FALSE;
3293 }
3295 {
3296  res->data = (void *)(long)slStatusSsiL((lists) u->Data(), (int)(long) v->Data());
3297  //return (res->data== (void*)(long)-2);
3298  return FALSE;
3299 }
3300 static BOOLEAN jjSIMPL_P(leftv res, leftv u, leftv v)
3301 {
3302  int sw = (int)(long)v->Data();
3303  // CopyD for POLY_CMD and VECTOR_CMD are identical:
3304  poly p = (poly)u->CopyD(POLY_CMD);
3305  if (sw & SIMPL_NORM)
3306  {
3307  pNorm(p);
3308  }
3309  res->data = (char * )p;
3310  return FALSE;
3311 }
3313 {
3314  ideal result;
3315  intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
3316  tHomog hom=testHomog;
3317  ideal u_id=(ideal)(u->Data());
3318  if (w!=NULL)
3319  {
3320  if (!idTestHomModule(u_id,currRing->qideal,w))
3321  {
3322  WarnS("wrong weights:");w->show();PrintLn();
3323  w=NULL;
3324  }
3325  else
3326  {
3327  w=ivCopy(w);
3328  hom=isHomog;
3329  }
3330  }
3331  result=kStd(u_id,currRing->qideal,hom,&w,(intvec *)v->Data());
3332  idSkipZeroes(result);
3333  res->data = (char *)result;
3334  setFlag(res,FLAG_STD);
3335  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
3336  return FALSE;
3337 }
3338 static BOOLEAN jjSTD_1(leftv res, leftv u, leftv v)
3339 {
3340  ideal result;
3341  assumeStdFlag(u);
3342  ideal i1=(ideal)(u->Data());
3343  ideal i0;
3344  int r=v->Typ();
3345  if ((/*v->Typ()*/r==POLY_CMD) ||(r==VECTOR_CMD))
3346  {
3347  i0=idInit(1,i1->rank); // TODO: rank is wrong (if v is a vector!)
3348  i0->m[0]=(poly)v->Data();
3349  int ii0=idElem(i0); /* size of i0 */
3350  i1=idSimpleAdd(i1,i0); //
3351  memset(i0->m,0,sizeof(poly)*IDELEMS(i0));
3352  idDelete(&i0);
3353  intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
3354  tHomog hom=testHomog;
3355 
3356  if (w!=NULL)
3357  {
3358  if (!idTestHomModule(i1,currRing->qideal,w))
3359  {
3360  // no warnung: this is legal, if i in std(i,p)
3361  // is homogeneous, but p not
3362  w=NULL;
3363  }
3364  else
3365  {
3366  w=ivCopy(w);
3367  hom=isHomog;
3368  }
3369  }
3370  BITSET save1;
3371  SI_SAVE_OPT1(save1);
3373  /* ii0 appears to be the position of the first element of il that
3374  does not belong to the old SB ideal */
3375  result=kStd(i1,currRing->qideal,hom,&w,NULL,0,ii0);
3376  SI_RESTORE_OPT1(save1);
3377  idDelete(&i1);
3378  idSkipZeroes(result);
3379  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
3380  res->data = (char *)result;
3381  }
3382  else /*IDEAL/MODULE*/
3383  {
3384  i0=(ideal)v->CopyD();
3385  int ii0=idElem(i0); /* size of i0 */
3386  i1=idSimpleAdd(i1,i0); //
3387  memset(i0->m,0,sizeof(poly)*IDELEMS(i0));
3388  idDelete(&i0);
3389  intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
3390  tHomog hom=testHomog;
3391 
3392  if (w!=NULL)
3393  {
3394  if (!idTestHomModule(i1,currRing->qideal,w))
3395  {
3396  // no warnung: this is legal, if i in std(i,p)
3397  // is homogeneous, but p not
3398  w=NULL;
3399  }
3400  else
3401  {
3402  w=ivCopy(w);
3403  hom=isHomog;
3404  }
3405  }
3406  if (ii0*4 >= 3*IDELEMS(i1)) // MAGIC: add few poly to large SB: 3/4
3407  {
3408  BITSET save1;
3409  SI_SAVE_OPT1(save1);
3411  /* ii0 appears to be the position of the first element of il that
3412  does not belong to the old SB ideal */
3413  result=kStd(i1,currRing->qideal,hom,&w,NULL,0,ii0);
3414  SI_RESTORE_OPT1(save1);
3415  }
3416  else
3417  {
3418  result=kStd(i1,currRing->qideal,hom,&w);
3419  }
3420  idDelete(&i1);
3421  idSkipZeroes(result);
3422  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
3423  res->data = (char *)result;
3424  }
3426  return FALSE;
3427 }
3428 static BOOLEAN jjVARSTR2(leftv res, leftv u, leftv v)
3429 {
3430  idhdl h=(idhdl)u->data;
3431  int i=(int)(long)v->Data();
3432  if ((0<i) && (i<=IDRING(h)->N))
3433  res->data=omStrDup(IDRING(h)->names[i-1]);
3434  else
3435  {
3436  Werror("var number %d out of range 1..%d",i,IDRING(h)->N);
3437  return TRUE;
3438  }
3439  return FALSE;
3440 }
3442 {
3443 // input: u: a list with links of type
3444 // ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch
3445 // v: timeout for select in milliseconds
3446 // or 0 for polling
3447 // returns: ERROR (via Werror): timeout negative
3448 // -1: the read state of all links is eof
3449 // 0: timeout (or polling): none ready
3450 // i>0: (at least) L[i] is ready
3451  lists Lforks = (lists)u->Data();
3452  int t = (int)(long)v->Data();
3453  if(t < 0)
3454  {
3455  WerrorS("negative timeout"); return TRUE;
3456  }
3457  int i = slStatusSsiL(Lforks, t*1000);
3458  if(i == -2) /* error */
3459  {
3460  return TRUE;
3461  }
3462  res->data = (void*)(long)i;
3463  return FALSE;
3464 }
3466 {
3467 // input: u: a list with links of type
3468 // ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch
3469 // v: timeout for select in milliseconds
3470 // or 0 for polling
3471 // returns: ERROR (via Werror): timeout negative
3472 // -1: the read state of all links is eof
3473 // 0: timeout (or polling): none ready
3474 // 1: all links are ready
3475 // (caution: at least one is ready, but some maybe dead)
3476  lists Lforks = (lists)u->CopyD();
3477  int timeout = 1000*(int)(long)v->Data();
3478  if(timeout < 0)
3479  {
3480  WerrorS("negative timeout"); return TRUE;
3481  }
3482  int t = getRTimer()/TIMER_RESOLUTION; // in seconds
3483  int i;
3484  int ret = -1;
3485  for(unsigned nfinished = 0; nfinished < ((unsigned)Lforks->nr)+1; nfinished++)
3486  {
3487  i = slStatusSsiL(Lforks, timeout);
3488  if(i > 0) /* Lforks[i] is ready */
3489  {
3490  ret = 1;
3491  Lforks->m[i-1].CleanUp();
3492  Lforks->m[i-1].rtyp=DEF_CMD;
3493  Lforks->m[i-1].data=NULL;
3494  timeout = si_max(0,timeout - 1000*(getRTimer()/TIMER_RESOLUTION - t));
3495  }
3496  else /* terminate the for loop */
3497  {
3498  if(i == -2) /* error */
3499  {
3500  return TRUE;
3501  }
3502  if(i == 0) /* timeout */
3503  {
3504  ret = 0;
3505  }
3506  break;
3507  }
3508  }
3509  Lforks->Clean();
3510  res->data = (void*)(long)ret;
3511  return FALSE;
3512 }
3513 static BOOLEAN jjWEDGE(leftv res, leftv u, leftv v)
3514 {
3515  res->data = (char *)mp_Wedge((matrix)u->Data(),(int)(long)v->Data(),currRing);
3516  return FALSE;
3517 }
3518 #define jjWRONG2 (proc2)jjWRONG
3519 #define jjWRONG3 (proc3)jjWRONG
3521 {
3522  return TRUE;
3523 }
3524 
3525 /*=================== operations with 1 arg.: static proc =================*/
3526 /* must be ordered: first operations for chars (infix ops),
3527  * then alphabetically */
3528 
3529 static BOOLEAN jjDUMMY(leftv res, leftv u)
3530 {
3531  res->data = (char *)u->CopyD();
3532  return FALSE;
3533 }
3535 {
3536  return FALSE;
3537 }
3538 //static BOOLEAN jjPLUSPLUS(leftv res, leftv u)
3539 //{
3540 // res->data = (char *)((int)(long)u->Data()+1);
3541 // return FALSE;
3542 //}
3543 //static BOOLEAN jjMINUSMINUS(leftv res, leftv u)
3544 //{
3545 // res->data = (char *)((int)(long)u->Data()-1);
3546 // return FALSE;
3547 //}
3549 {
3550  if (IDTYP((idhdl)u->data)==INT_CMD)
3551  {
3552  int i=IDINT((idhdl)u->data);
3553  if (iiOp==PLUSPLUS) i++;
3554  else i--;
3555  IDDATA((idhdl)u->data)=(char *)(long)i;
3556  return FALSE;
3557  }
3558  return TRUE;
3559 }
3561 {
3562  number n=(number)u->CopyD(BIGINT_CMD);
3563  n=n_InpNeg(n,coeffs_BIGINT);
3564  res->data = (char *)n;
3565  return FALSE;
3566 }
3568 {
3569  res->data = (char *)(-(long)u->Data());
3570  return FALSE;
3571 }
3573 {
3574  number n=(number)u->CopyD(NUMBER_CMD);
3575  n=nInpNeg(n);
3576  res->data = (char *)n;
3577  return FALSE;
3578 }
3580 {
3581  res->data = (char *)pNeg((poly)u->CopyD(POLY_CMD));
3582  return FALSE;
3583 }
3585 {
3586  poly m1=pISet(-1);
3587  res->data = (char *)mp_MultP((matrix)u->CopyD(MATRIX_CMD),m1,currRing);
3588  return FALSE;
3589 }
3591 {
3592  intvec *iv=(intvec *)u->CopyD(INTVEC_CMD);
3593  (*iv)*=(-1);
3594  res->data = (char *)iv;
3595  return FALSE;
3596 }
3598 {
3599  bigintmat *bim=(bigintmat *)u->CopyD(BIGINTMAT_CMD);
3600  (*bim)*=(-1);
3601  res->data = (char *)bim;
3602  return FALSE;
3603 }
3604 static BOOLEAN jjPROC1(leftv res, leftv u)
3605 {
3606  return jjPROC(res,u,NULL);
3607 }
3609 {
3610  //matrix m=(matrix)v->Data();
3611  //lists l=mpBareiss(m,FALSE);
3612  intvec *iv;
3613  ideal m;
3614  sm_CallBareiss((ideal)v->Data(),0,0,m,&iv, currRing);
3616  l->Init(2);
3617  l->m[0].rtyp=MODUL_CMD;
3618  l->m[1].rtyp=INTVEC_CMD;
3619  l->m[0].data=(void *)m;
3620  l->m[1].data=(void *)iv;
3621  res->data = (char *)l;
3622  return FALSE;
3623 }
3624 //static BOOLEAN jjBAREISS_IM(leftv res, leftv v)
3625 //{
3626 // intvec *m=(intvec *)v->CopyD(INTMAT_CMD);
3627 // ivTriangMat(m);
3628 // res->data = (char *)m;
3629 // return FALSE;
3630 //}
3632 {
3634  b->hnf();
3635  res->data=(char*)b;
3636  return FALSE;
3637 }
3638 static BOOLEAN jjBI2N(leftv res, leftv u)
3639 {
3640  BOOLEAN bo=FALSE;
3641  number n=(number)u->CopyD();
3643  if (nMap!=NULL)
3644  res->data=nMap(n,coeffs_BIGINT,currRing->cf);
3645  else
3646  {
3647  Werror("cannot convert bigint to cring %s", nCoeffString(currRing->cf));
3648  bo=TRUE;
3649  }
3650  n_Delete(&n,coeffs_BIGINT);
3651  return bo;
3652 }
3653 static BOOLEAN jjBI2IM(leftv res, leftv u)
3654 {
3655  bigintmat *b=(bigintmat*)u->Data();
3656  res->data=(void *)bim2iv(b);
3657  return FALSE;
3658 }
3659 static BOOLEAN jjBI2P(leftv res, leftv u)
3660 {
3661  sleftv tmp;
3662  BOOLEAN bo=jjBI2N(&tmp,u);
3663  if (!bo)
3664  {
3665  number n=(number) tmp.data;
3666  if (nIsZero(n)) { res->data=NULL;nDelete(&n); }
3667  else
3668  {
3669  res->data=(void *)pNSet(n);
3670  }
3671  }
3672  return bo;
3673 }
3675 {
3676  return iiExprArithM(res,u,iiOp);
3677 }
3678 static BOOLEAN jjCHAR(leftv res, leftv v)
3679 {
3680  res->data = (char *)(long)rChar((ring)v->Data());
3681  return FALSE;
3682 }
3683 static BOOLEAN jjCOLS(leftv res, leftv v)
3684 {
3685  res->data = (char *)(long)MATCOLS((matrix)(v->Data()));
3686  return FALSE;
3687 }
3689 {
3690  res->data = (char *)(long)((bigintmat*)(v->Data()))->cols();
3691  return FALSE;
3692 }
3694 {
3695  res->data = (char *)(long)((intvec*)(v->Data()))->cols();
3696  return FALSE;
3697 }
3699 {
3700  // CopyD for POLY_CMD and VECTOR_CMD are identical:
3701  poly p=(poly)v->CopyD(POLY_CMD);
3702  if (p!=NULL) p_Cleardenom(p, currRing);
3703  res->data = (char *)p;
3704  return FALSE;
3705 }
3707 {
3708  res->data = (char *)(long)n_Size((number)v->Data(),coeffs_BIGINT);
3709  return FALSE;
3710 }
3712 {
3713  res->data = (char *)(long)nSize((number)v->Data());
3714  return FALSE;
3715 }
3717 {
3718  lists l=(lists)v->Data();
3719  res->data = (char *)(long)(lSize(l)+1);
3720  return FALSE;
3721 }
3723 {
3724  matrix m=(matrix)v->Data();
3725  res->data = (char *)(long)(MATROWS(m)*MATCOLS(m));
3726  return FALSE;
3727 }
3729 {
3730  res->data = (char *)(long)((intvec*)(v->Data()))->length();
3731  return FALSE;
3732 }
3734 {
3735  ring r=(ring)v->Data();
3736  int elems=-1;
3737  if (rField_is_Zp(r)) elems=r->cf->ch;
3738  else if (rField_is_GF(r)) elems=r->cf->m_nfCharQ;
3739  else if (rField_is_Zp_a(r) && (r->cf->type==n_algExt))
3740  {
3741  extern int ipower ( int b, int n ); /* factory/cf_util */
3742  elems=ipower(r->cf->ch,r->cf->extRing->pFDeg(r->cf->extRing->qideal->m[0],r->cf->extRing));
3743  }
3744  res->data = (char *)(long)elems;
3745  return FALSE;
3746 }
3747 static BOOLEAN jjDEG(leftv res, leftv v)
3748 {
3749  int dummy;
3750  poly p=(poly)v->Data();
3751  if (p!=NULL) res->data = (char *)currRing->pLDeg(p,&dummy,currRing);
3752  else res->data=(char *)-1;
3753  return FALSE;
3754 }
3755 static BOOLEAN jjDEG_M(leftv res, leftv u)
3756 {
3757  ideal I=(ideal)u->Data();
3758  int d=-1;
3759  int dummy;
3760  int i;
3761  for(i=IDELEMS(I)-1;i>=0;i--)
3762  if (I->m[i]!=NULL) d=si_max(d,(int)currRing->pLDeg(I->m[i],&dummy,currRing));
3763  res->data = (char *)(long)d;
3764  return FALSE;
3765 }
3766 static BOOLEAN jjDEGREE(leftv res, leftv v)
3767 {
3768  SPrintStart();
3770  {
3771  ring origR = currRing;
3772  ring tempR = rCopy(origR);
3773  coeffs new_cf=nInitChar(n_Q,NULL);
3774  nKillChar(tempR->cf);
3775  tempR->cf=new_cf;
3776  rComplete(tempR);
3777  ideal vid = (ideal)v->Data();
3778  rChangeCurrRing(tempR);
3779  ideal vv = idrCopyR(vid, origR, currRing);
3780  sleftv vvAsLeftv; memset(&vvAsLeftv, 0, sizeof(vvAsLeftv));
3781  vvAsLeftv.rtyp = IDEAL_CMD;
3782  vvAsLeftv.data = vv; vvAsLeftv.next = NULL;
3783  if (hasFlag(v, FLAG_STD)) setFlag(&vvAsLeftv,FLAG_STD);
3784  assumeStdFlag(&vvAsLeftv);
3785  PrintS("// NOTE: computation of degree is being performed for\n");
3786  PrintS("// generic fibre, that is, over Q\n");
3787  intvec *module_w=(intvec*)atGet(&vvAsLeftv,"isHomog",INTVEC_CMD);
3788  scDegree(vv,module_w,currRing->qideal);
3789  idDelete(&vv);
3790  rChangeCurrRing(origR);
3791  rDelete(tempR);
3792  }
3793  assumeStdFlag(v);
3794  intvec *module_w=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
3795  scDegree((ideal)v->Data(),module_w,currRing->qideal);
3796  char *s=SPrintEnd();
3797  int l=strlen(s)-1;
3798  s[l]='\0';
3799  res->data=(void*)s;
3800  return FALSE;
3801 }
3803 {
3804  if ((v->rtyp==IDHDL)
3805  && ((myynest==IDLEV((idhdl)v->data))||(0==IDLEV((idhdl)v->data))))
3806  {
3807  res->data=(void *)(long)(IDLEV((idhdl)v->data)+1);
3808  }
3809  else if (v->rtyp!=0) res->data=(void *)(-1);
3810  return FALSE;
3811 }
3812 
3813 /// Return the denominator of the input number
3814 /// NOTE: the input number is normalized as a side effect
3816 {
3817  number n = reinterpret_cast<number>(v->Data());
3818  res->data = reinterpret_cast<void*>(n_GetDenom(n, currRing->cf));
3819  return FALSE;
3820 }
3821 
3822 /// Return the numerator of the input number
3823 /// NOTE: the input number is normalized as a side effect
3825 {
3826  number n = reinterpret_cast<number>(v->Data());
3827  res->data = reinterpret_cast<void*>(n_GetNumerator(n, currRing->cf));
3828  return FALSE;
3829 }
3830 
3831 static BOOLEAN jjDET(leftv res, leftv v)
3832 {
3833  matrix m=(matrix)v->Data();
3834  poly p;
3835  if (sm_CheckDet((ideal)m,m->cols(),TRUE, currRing))
3836  {
3838  p=sm_CallDet(I, currRing);
3839  idDelete(&I);
3840  }
3841  else
3842  p=singclap_det(m,currRing);
3843  res ->data = (char *)p;
3844  return FALSE;
3845 }
3846 static BOOLEAN jjDET_BI(leftv res, leftv v)
3847 {
3848  bigintmat * m=(bigintmat*)v->Data();
3849  int i,j;
3850  i=m->rows();j=m->cols();
3851  if(i==j)
3852  res->data = (char *)(long)singclap_det_bi(m,coeffs_BIGINT);
3853  else
3854  {
3855  Werror("det of %d x %d bigintmat",i,j);
3856  return TRUE;
3857  }
3858  return FALSE;
3859 }
3860 #ifdef SINGULAR_4_2
3861 static BOOLEAN jjDET_N2(leftv res, leftv v)
3862 {
3863  bigintmat * m=(bigintmat*)v->Data();
3864  number2 r=(number2)omAlloc0(sizeof(*r));
3865  int i,j;
3866  i=m->rows();j=m->cols();
3867  if(i==j)
3868  {
3869  r->n=m->det();
3870  r->cf=m->basecoeffs();
3871  }
3872  else
3873  {
3874  omFreeSize(r,sizeof(*r));
3875  Werror("det of %d x %d cmatrix",i,j);
3876  return TRUE;
3877  }
3878  res->data=(void*)r;
3879  return FALSE;
3880 }
3881 #endif
3882 static BOOLEAN jjDET_I(leftv res, leftv v)
3883 {
3884  intvec * m=(intvec*)v->Data();
3885  int i,j;
3886  i=m->rows();j=m->cols();
3887  if(i==j)
3888  res->data = (char *)(long)singclap_det_i(m,currRing);
3889  else
3890  {
3891  Werror("det of %d x %d intmat",i,j);
3892  return TRUE;
3893  }
3894  return FALSE;
3895 }
3896 static BOOLEAN jjDET_S(leftv res, leftv v)
3897 {
3898  ideal I=(ideal)v->Data();
3899  poly p;
3900  if (IDELEMS(I)<1) return TRUE;
3901  if (sm_CheckDet(I,IDELEMS(I),FALSE, currRing))
3902  {
3904  p=singclap_det(m,currRing);
3905  idDelete((ideal *)&m);
3906  }
3907  else
3908  p=sm_CallDet(I, currRing);
3909  res->data = (char *)p;
3910  return FALSE;
3911 }
3912 static BOOLEAN jjDIM(leftv res, leftv v)
3913 {
3914  assumeStdFlag(v);
3916  {
3917  Warn("dim(%s) may be wrong because the mixed monomial ordering",v->Name());
3918  }
3919  if (rField_is_Ring(currRing))
3920  {
3921  ideal vid = (ideal)v->Data();
3922  int i = idPosConstant(vid);
3923  if ((i != -1) && (n_IsUnit(pGetCoeff(vid->m[i]),currRing->cf)))
3924  { /* ideal v contains unit; dim = -1 */
3925  res->data = (char *)-1L;
3926  return FALSE;
3927  }
3928  ideal vv = id_Head(vid,currRing);
3929  idSkipZeroes(vv);
3930  int j = idPosConstant(vv);
3931  long d;
3932  if(j == -1)
3933  {
3934  d = (long)scDimInt(vv, currRing->qideal);
3936  d++;
3937  }
3938  else
3939  {
3940  if(n_IsUnit(pGetCoeff(vv->m[j]),currRing->cf))
3941  d = -1;
3942  else
3943  d = (long)scDimInt(vv, currRing->qideal);
3944  }
3945  //Anne's Idea for std(4,2x) = 0 bug
3946  long dcurr = d;
3947  for(unsigned ii=0;ii<(unsigned)IDELEMS(vv);ii++)
3948  {
3949  if(vv->m[ii] != NULL && !n_IsUnit(pGetCoeff(vv->m[ii]),currRing->cf))
3950  {
3951  ideal vc = idCopy(vv);
3952  poly c = pInit();
3953  pSetCoeff0(c,nCopy(pGetCoeff(vv->m[ii])));
3954  idInsertPoly(vc,c);
3955  idSkipZeroes(vc);
3956  for(unsigned jj = 0;jj<(unsigned)IDELEMS(vc)-1;jj++)
3957  {
3958  if((vc->m[jj]!=NULL)
3959  && (n_DivBy(pGetCoeff(vc->m[jj]),pGetCoeff(c),currRing->cf)))
3960  {
3961  pDelete(&vc->m[jj]);
3962  }
3963  }
3964  idSkipZeroes(vc);
3965  j = idPosConstant(vc);
3966  if (j != -1) pDelete(&vc->m[j]);
3967  dcurr = (long)scDimInt(vc, currRing->qideal);
3968  // the following assumes the ground rings to be either zero- or one-dimensional
3969  if((j==-1) && rField_is_Ring_Z(currRing))
3970  {
3971  // should also be activated for other euclidean domains as groundfield
3972  dcurr++;
3973  }
3974  idDelete(&vc);
3975  }
3976  if(dcurr > d)
3977  d = dcurr;
3978  }
3979  res->data = (char *)d;
3980  idDelete(&vv);
3981  return FALSE;
3982  }
3983  res->data = (char *)(long)scDimInt((ideal)(v->Data()),currRing->qideal);
3984  return FALSE;
3985 }
3987 {
3988  si_link l = (si_link)v->Data();
3989  if (slDump(l))
3990  {
3991  const char *s;
3992  if ((l!=NULL)&&(l->name!=NULL)) s=l->name;
3993  else s=sNoName;
3994  Werror("cannot dump to `%s`",s);
3995  return TRUE;
3996  }
3997  else
3998  return FALSE;
3999 }
4000 static BOOLEAN jjE(leftv res, leftv v)
4001 {
4002  res->data = (char *)pOne();
4003  int co=(int)(long)v->Data();
4004  if (co>0)
4005  {
4006  pSetComp((poly)res->data,co);
4007  pSetm((poly)res->data);
4008  }
4009  else WerrorS("argument of gen must be positive");
4010  return (co<=0);
4011 }
4013 {
4014  char * d = (char *)v->Data();
4015  char * s = (char *)omAlloc(strlen(d) + 13);
4016  strcpy( s, (char *)d);
4017  strcat( s, "\n;RETURN();\n");
4018  newBuffer(s,BT_execute);
4019  return yyparse();
4020 }
4021 static BOOLEAN jjFACSTD(leftv res, leftv v)
4022 {
4024  if (currRing->cf->convSingNFactoryN!=NULL) /* conversion to factory*/
4025  {
4026  ideal_list p,h;
4027  h=kStdfac((ideal)v->Data(),NULL,testHomog,NULL);
4028  if (h==NULL)
4029  {
4030  L->Init(1);
4031  L->m[0].data=(char *)idInit(1);
4032  L->m[0].rtyp=IDEAL_CMD;
4033  }
4034  else
4035  {
4036  p=h;
4037  int l=0;
4038  while (p!=NULL) { p=p->next;l++; }
4039  L->Init(l);
4040  l=0;
4041  while(h!=NULL)
4042  {
4043  L->m[l].data=(char *)h->d;
4044  L->m[l].rtyp=IDEAL_CMD;
4045  p=h->next;
4046  omFreeSize(h,sizeof(*h));
4047  h=p;
4048  l++;
4049  }
4050  }
4051  }
4052  else
4053  {
4054  WarnS("no factorization implemented");
4055  L->Init(1);
4056  iiExprArith1(&(L->m[0]),v,STD_CMD);
4057  }
4058  res->data=(void *)L;
4059  return FALSE;
4060 }
4061 static BOOLEAN jjFAC_P(leftv res, leftv u)
4062 {
4063  intvec *v=NULL;
4064  singclap_factorize_retry=0;
4065  ideal f=singclap_factorize((poly)(u->CopyD()), &v, 0,currRing);
4066  if (f==NULL) return TRUE;
4067  ivTest(v);
4069  l->Init(2);
4070  l->m[0].rtyp=IDEAL_CMD;
4071  l->m[0].data=(void *)f;
4072  l->m[1].rtyp=INTVEC_CMD;
4073  l->m[1].data=(void *)v;
4074  res->data=(void *)l;
4075  return FALSE;
4076 }
4078 {
4079  si_link l = (si_link)v->Data();
4080  if (slGetDump(l))
4081  {
4082  const char *s;
4083  if ((l!=NULL)&&(l->name!=NULL)) s=l->name;
4084  else s=sNoName;
4085  Werror("cannot get dump from `%s`",s);
4086  return TRUE;
4087  }
4088  else
4089  return FALSE;
4090 }
4092 {
4093  assumeStdFlag(v);
4094  ideal I=(ideal)v->Data();
4095  res->data=(void *)iiHighCorner(I,0);
4096  return FALSE;
4097 }
4099 {
4100  assumeStdFlag(v);
4101  intvec *w=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
4102  BOOLEAN delete_w=FALSE;
4103  ideal I=(ideal)v->Data();
4104  int i;
4105  poly p=NULL,po=NULL;
4106  int rk=id_RankFreeModule(I,currRing);
4107  if (w==NULL)
4108  {
4109  w = new intvec(rk);
4110  delete_w=TRUE;
4111  }
4112  for(i=rk;i>0;i--)
4113  {
4114  p=iiHighCorner(I,i);
4115  if (p==NULL)
4116  {
4117  WerrorS("module must be zero-dimensional");
4118  if (delete_w) delete w;
4119  return TRUE;
4120  }
4121  if (po==NULL)
4122  {
4123  po=p;
4124  }
4125  else
4126  {
4127  // now po!=NULL, p!=NULL
4128  int d=(currRing->pFDeg(po,currRing)-(*w)[pGetComp(po)-1] - currRing->pFDeg(p,currRing)+(*w)[i-1]);
4129  if (d==0)
4130  d=pLmCmp(po,p);
4131  if (d > 0)
4132  {
4133  pDelete(&p);
4134  }
4135  else // (d < 0)
4136  {
4137  pDelete(&po); po=p;
4138  }
4139  }
4140  }
4141  if (delete_w) delete w;
4142  res->data=(void *)po;
4143  return FALSE;
4144 }
4146 {
4148  {
4149  ring origR = currRing;
4150  ring tempR = rCopy(origR);
4151  coeffs new_cf=nInitChar(n_Q,NULL);
4152  nKillChar(tempR->cf);
4153  tempR->cf=new_cf;
4154  rComplete(tempR);
4155  ideal vid = (ideal)v->Data();
4156  rChangeCurrRing(tempR);
4157  ideal vv = idrCopyR(vid, origR, currRing);
4158  sleftv vvAsLeftv; memset(&vvAsLeftv, 0, sizeof(vvAsLeftv));
4159  vvAsLeftv.rtyp = IDEAL_CMD;
4160  vvAsLeftv.data = vv; vvAsLeftv.next = NULL;
4161  if (hasFlag(v, FLAG_STD)) setFlag(&vvAsLeftv,FLAG_STD);
4162  assumeStdFlag(&vvAsLeftv);
4163  PrintS("// NOTE: computation of Hilbert series etc. is being\n");
4164  PrintS("// performed for generic fibre, that is, over Q\n");
4165  intvec *module_w=(intvec*)atGet(&vvAsLeftv,"isHomog",INTVEC_CMD);
4166  //scHilbertPoly(vv,currRing->qideal);
4167  hLookSeries(vv,module_w,currRing->qideal);
4168  idDelete(&vv);
4169  rChangeCurrRing(origR);
4170  rDelete(tempR);
4171  return FALSE;
4172  }
4173  assumeStdFlag(v);
4174  intvec *module_w=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
4175  //scHilbertPoly((ideal)v->Data(),currRing->qideal);
4176  hLookSeries((ideal)v->Data(),module_w,currRing->qideal);
4177  return FALSE;
4178 }
4180 {
4182  {
4183  PrintS("// NOTE: computation of Hilbert series etc. is being\n");
4184  PrintS("// performed for generic fibre, that is, over Q\n");
4185  }
4186  res->data=(void *)hSecondSeries((intvec *)v->Data());
4187  return FALSE;
4188 }
4189 static BOOLEAN jjHOMOG1(leftv res, leftv v)
4190 {
4191  intvec *w=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
4192  ideal v_id=(ideal)v->Data();
4193  if (w==NULL)
4194  {
4195  res->data=(void *)(long)idHomModule(v_id,currRing->qideal,&w);
4196  if (res->data!=NULL)
4197  {
4198  if (v->rtyp==IDHDL)
4199  {
4200  char *s_isHomog=omStrDup("isHomog");
4201  if (v->e==NULL)
4202  atSet((idhdl)(v->data),s_isHomog,w,INTVEC_CMD);
4203  else
4204  atSet((idhdl)(v->LData()),s_isHomog,w,INTVEC_CMD);
4205  }
4206  else if (w!=NULL) delete w;
4207  } // if res->data==NULL then w==NULL
4208  }
4209  else
4210  {
4211  res->data=(void *)(long)idTestHomModule(v_id,currRing->qideal,w);
4212  if((res->data==NULL) && (v->rtyp==IDHDL))
4213  {
4214  if (v->e==NULL)
4215  atKill((idhdl)(v->data),"isHomog");
4216  else
4217  atKill((idhdl)(v->LData()),"isHomog");
4218  }
4219  }
4220  return FALSE;
4221 }
4223 {
4224  res->data = (char *)idMaxIdeal((int)(long)v->Data());
4225  setFlag(res,FLAG_STD);
4226  return FALSE;
4227 }
4229 {
4230  matrix mat=(matrix)v->CopyD(MATRIX_CMD);
4231  IDELEMS((ideal)mat)=MATCOLS(mat)*MATROWS(mat);
4232  if (IDELEMS((ideal)mat)==0)
4233  {
4234  idDelete((ideal *)&mat);
4235  mat=(matrix)idInit(1,1);
4236  }
4237  else
4238  {
4239  MATROWS(mat)=1;
4240  mat->rank=1;
4241  idTest((ideal)mat);
4242  }
4243  res->data=(char *)mat;
4244  return FALSE;
4245 }
4247 {
4248  map m=(map)v->CopyD(MAP_CMD);
4249  omFree((ADDRESS)m->preimage);
4250  m->preimage=NULL;
4251  ideal I=(ideal)m;
4252  I->rank=1;
4253  res->data=(char *)I;
4254  return FALSE;
4255 }
4257 {
4258  if (currRing!=NULL)
4259  {
4260  ring q=(ring)v->Data();
4261  if (rSamePolyRep(currRing, q))
4262  {
4263  if (q->qideal==NULL)
4264  res->data=(char *)idInit(1,1);
4265  else
4266  res->data=(char *)idCopy(q->qideal);
4267  return FALSE;
4268  }
4269  }
4270  WerrorS("can only get ideal from identical qring");
4271  return TRUE;
4272 }
4273 static BOOLEAN jjIm2Iv(leftv res, leftv v)
4274 {
4275  intvec *iv = (intvec *)v->CopyD(INTMAT_CMD);
4276  iv->makeVector();
4277  res->data = iv;
4278  return FALSE;
4279 }
4280 static BOOLEAN jjIMPART(leftv res, leftv v)
4281 {
4282  res->data = (char *)n_ImPart((number)v->Data(),currRing->cf);
4283  return FALSE;
4284 }
4286 {
4287  assumeStdFlag(v);
4288  res->data=(void *)scIndIntvec((ideal)(v->Data()),currRing->qideal);
4289  return FALSE;
4290 }
4292 {
4293  ideal result=kInterRed((ideal)(v->Data()), currRing->qideal);
4295  Warn("interred: this command is experimental over the integers");
4296  if (TEST_OPT_PROT) { PrintLn(); mflush(); }
4297  res->data = result;
4298  return FALSE;
4299 }
4301 {
4302  res->data = (char *)(long)pVar((poly)v->Data());
4303  return FALSE;
4304 }
4306 {
4307  res->data = (char *)(long)(r_IsRingVar((char *)v->Data(), currRing->names,
4308  currRing->N)+1);
4309  return FALSE;
4310 }
4312 {
4313  res->data = (char *)0;
4314  return FALSE;
4315 }
4317 {
4318  ideal i=idInit(currRing->N,1);
4319  int k;
4320  poly p=(poly)(v->Data());
4321  for (k=currRing->N;k>0;k--)
4322  {
4323  i->m[k-1]=pDiff(p,k);
4324  }
4325  res->data = (char *)i;
4326  return FALSE;
4327 }
4329 {
4330  if (!nCoeff_is_transExt(currRing->cf))
4331  {
4332  WerrorS("differentiation not defined in the coefficient ring");
4333  return TRUE;
4334  }
4335  number n = (number) u->Data();
4336  number k = (number) v->Data();
4337  res->data = ntDiff(n,k,currRing->cf);
4338  return FALSE;
4339 }
4340 /*2
4341  * compute Jacobi matrix of a module/matrix
4342  * Jacobi(M) := ( diff(Mt,var(1))|, ... ,| diff(Mt,var(currRing->N)) ),
4343  * where Mt := transpose(M)
4344  * Note that this is consistent with the current conventions for jacob in Singular,
4345  * whereas M2 computes its transposed.
4346  */
4348 {
4349  ideal id = (ideal)a->Data();
4350  id = id_Transp(id,currRing);
4351  int W = IDELEMS(id);
4352 
4353  ideal result = idInit(W * currRing->N, id->rank);
4354  poly *p = result->m;
4355 
4356  for( int v = 1; v <= currRing->N; v++ )
4357  {
4358  poly* q = id->m;
4359  for( int i = 0; i < W; i++, p++, q++ )
4360  *p = pDiff( *q, v );
4361  }
4362  idDelete(&id);
4363 
4364  res->data = (char *)result;
4365  return FALSE;
4366 }
4367 
4368 
4369 static BOOLEAN jjKBASE(leftv res, leftv v)
4370 {
4371  assumeStdFlag(v);
4372  res->data = (char *)scKBase(-1,(ideal)(v->Data()),currRing->qideal);
4373  return FALSE;
4374 }
4375 static BOOLEAN jjL2R(leftv res, leftv v)
4376 {
4377  res->data=(char *)syConvList((lists)v->Data());
4378  if (res->data != NULL)
4379  return FALSE;
4380  else
4381  return TRUE;
4382 }
4384 {
4385  poly p=(poly)v->Data();
4386  if (p==NULL)
4387  {
4388  res->data=(char *)nInit(0);
4389  }
4390  else
4391  {
4392  res->data=(char *)nCopy(pGetCoeff(p));
4393  }
4394  return FALSE;
4395 }
4397 {
4398  poly p=(poly)v->Data();
4399  int s=currRing->N;
4400  if (v->Typ()==VECTOR_CMD) s++;
4401  intvec *iv=new intvec(s);
4402  if (p!=NULL)
4403  {
4404  for(int i = currRing->N;i;i--)
4405  {
4406  (*iv)[i-1]=pGetExp(p,i);
4407  }
4408  if (s!=currRing->N)
4409  (*iv)[currRing->N]=pGetComp(p);
4410  }
4411  res->data=(char *)iv;
4412  return FALSE;
4413 }
4415 {
4416  poly p=(poly)v->Data();
4417  if (p == NULL)
4418  {
4419  res->data = (char*) NULL;
4420  }
4421  else
4422  {
4423  poly lm = pLmInit(p);
4424  pSetCoeff(lm, nInit(1));
4425  res->data = (char*) lm;
4426  }
4427  return FALSE;
4428 }
4429 static BOOLEAN jjLOAD1(leftv /*res*/, leftv v)
4430 {
4431  return jjLOAD((char*)v->Data(),FALSE);
4432 }
4434 {
4435  ring r=rCompose((lists)v->Data());
4436  if (r==NULL) return TRUE;
4437  res->data=(char *)r;
4438  return FALSE;
4439 }
4440 static BOOLEAN jjPFAC1(leftv res, leftv v)
4441 {
4442  /* call method jjPFAC2 with second argument = 0 (meaning that no
4443  valid bound for the prime factors has been given) */
4444  sleftv tmp;
4445  memset(&tmp, 0, sizeof(tmp));
4446  tmp.rtyp = INT_CMD;
4447  return jjPFAC2(res, v, &tmp);
4448 }
4450 {
4451  /* computes the LU-decomposition of a matrix M;
4452  i.e., M = P * L * U, where
4453  - P is a row permutation matrix,
4454  - L is in lower triangular form,
4455  - U is in upper row echelon form
4456  Then, we also have P * M = L * U.
4457  A list [P, L, U] is returned. */
4458  matrix mat = (const matrix)v->Data();
4459  if (!idIsConstant((ideal)mat))
4460  {
4461  WerrorS("matrix must be constant");
4462  return TRUE;
4463  }
4464  matrix pMat;
4465  matrix lMat;
4466  matrix uMat;
4467 
4468  luDecomp(mat, pMat, lMat, uMat);
4469 
4471  ll->Init(3);
4472  ll->m[0].rtyp=MATRIX_CMD; ll->m[0].data=(void *)pMat;
4473  ll->m[1].rtyp=MATRIX_CMD; ll->m[1].data=(void *)lMat;
4474  ll->m[2].rtyp=MATRIX_CMD; ll->m[2].data=(void *)uMat;
4475  res->data=(char*)ll;
4476 
4477  return FALSE;
4478 }
4479 static BOOLEAN jjMEMORY(leftv res, leftv v)
4480 {
4481  // clean out "_":
4483  memset(&sLastPrinted,0,sizeof(sleftv));
4484  // collect all info:
4485  omUpdateInfo();
4486  switch(((int)(long)v->Data()))
4487  {
4488  case 0:
4489  res->data=(char *)n_Init(om_Info.UsedBytes,coeffs_BIGINT);
4490  break;
4491  case 1:
4492  res->data = (char *)n_Init(om_Info.CurrentBytesSystem,coeffs_BIGINT);
4493  break;
4494  case 2:
4495  res->data = (char *)n_Init(om_Info.MaxBytesSystem,coeffs_BIGINT);
4496  break;
4497  default:
4498  omPrintStats(stdout);
4499  omPrintInfo(stdout);
4500  omPrintBinStats(stdout);
4501  res->data = (char *)0;
4502  res->rtyp = NONE;
4503  }
4504  return FALSE;
4505  res->data = (char *)0;
4506  return FALSE;
4507 }
4508 //static BOOLEAN jjMONITOR1(leftv res, leftv v)
4509 //{
4510 // return jjMONITOR2(res,v,NULL);
4511 //}
4512 static BOOLEAN jjMSTD(leftv res, leftv v)
4513 {
4514  int t=v->Typ();
4515  ideal r,m;
4516  r=kMin_std((ideal)v->Data(),currRing->qideal,testHomog,NULL,m);
4518  l->Init(2);
4519  l->m[0].rtyp=t;
4520  l->m[0].data=(char *)r;
4521  setFlag(&(l->m[0]),FLAG_STD);
4522  l->m[1].rtyp=t;
4523  l->m[1].data=(char *)m;
4524  res->data=(char *)l;
4525  return FALSE;
4526 }
4527 static BOOLEAN jjMULT(leftv res, leftv v)
4528 {
4529  assumeStdFlag(v);
4530  res->data = (char *)(long)scMultInt((ideal)(v->Data()),currRing->qideal);
4531  return FALSE;
4532 }
4534 {
4535  intvec *weights=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
4536 
4537  syStrategy tmp=(syStrategy)v->Data();
4538  tmp = syMinimize(tmp); // enrich itself!
4539 
4540  res->data=(char *)tmp;
4541 
4542  if (weights!=NULL)
4543  atSet(res, omStrDup("isHomog"),ivCopy(weights),INTVEC_CMD);
4544 
4545  return FALSE;
4546 }
4547 static BOOLEAN jjN2BI(leftv res, leftv v)
4548 {
4549  number n,i; i=(number)v->Data();
4551  if (nMap!=NULL)
4552  n=nMap(i,currRing->cf,coeffs_BIGINT);
4553  else goto err;
4554  res->data=(void *)n;
4555  return FALSE;
4556 err:
4557  WerrorS("cannot convert to bigint"); return TRUE;
4558 }
4559 static BOOLEAN jjNAMEOF(leftv res, leftv v)
4560 {
4561  res->data = (char *)v->name;
4562  if (res->data==NULL) res->data=omStrDup("");
4563  v->name=NULL;
4564  return FALSE;
4565 }
4566 static BOOLEAN jjNAMES(leftv res, leftv v)
4567 {
4568  res->data=ipNameList(((ring)v->Data())->idroot);
4569  return FALSE;
4570 }
4572 {
4573  res->data=ipNameListLev((IDROOT),(int)(long)v->Data());
4574  return FALSE;
4575 }
4576 static BOOLEAN jjNOT(leftv res, leftv v)
4577 {
4578  res->data=(char*)(long)((long)v->Data()==0 ? 1 : 0);
4579  return FALSE;
4580 }
4581 static BOOLEAN jjNVARS(leftv res, leftv v)
4582 {
4583  res->data = (char *)(long)(((ring)(v->Data()))->N);
4584  return FALSE;
4585 }
4587 {
4588  si_link l=(si_link)v->Data();
4589  if (iiOp==OPEN_CMD) return slOpen(l, SI_LINK_OPEN,v);
4590  else { slPrepClose(l); return slClose(l);}
4591 }
4592 static BOOLEAN jjORD(leftv res, leftv v)
4593 {
4594  poly p=(poly)v->Data();
4595  res->data=(char *)( p==NULL ? -1 : currRing->pFDeg(p,currRing) );
4596  return FALSE;
4597 }
4598 static BOOLEAN jjPAR1(leftv res, leftv v)
4599 {
4600  int i=(int)(long)v->Data();
4601  int p=0;
4602  p=rPar(currRing);
4603  if ((0<i) && (i<=p))
4604  {
4605  res->data=(char *)n_Param(i,currRing);
4606  }
4607  else
4608  {
4609  Werror("par number %d out of range 1..%d",i,p);
4610  return TRUE;
4611  }
4612  return FALSE;
4613 }
4614 static BOOLEAN jjPARDEG(leftv res, leftv v)
4615 {
4616  number nn=(number)v->Data();
4617  res->data = (char *)(long)n_ParDeg(nn, currRing->cf);
4618  return FALSE;
4619 }
4621 {
4622  if (currRing==NULL)
4623  {
4624  WerrorS("no ring active");
4625  return TRUE;
4626  }
4627  int i=(int)(long)v->Data();
4628  int p=0;
4629  if ((0<i) && (rParameter(currRing)!=NULL) && (i<=(p=rPar(currRing))))
4630  res->data=omStrDup(rParameter(currRing)[i-1]);
4631  else
4632  {
4633  Werror("par number %d out of range 1..%d",i,p);
4634  return TRUE;
4635  }
4636  return FALSE;
4637 }
4638 static BOOLEAN jjP2BI(leftv res, leftv v)
4639 {
4640  poly p=(poly)v->Data();
4641  if (p==NULL) { res->data=(char *)n_Init(0,coeffs_BIGINT); return FALSE; }
4642  if ((pNext(p)!=NULL)|| (!pIsConstant(p)))
4643  {
4644  WerrorS("poly must be constant");
4645  return TRUE;
4646  }
4647  number i=pGetCoeff(p);
4648  number n;
4650  if (nMap!=NULL)
4651  n=nMap(i,currRing->cf,coeffs_BIGINT);
4652  else goto err;
4653  res->data=(void *)n;
4654  return FALSE;
4655 err:
4656  WerrorS("cannot convert to bigint"); return TRUE;
4657 }
4658 static BOOLEAN jjP2I(leftv res, leftv v)
4659 {
4660  poly p=(poly)v->Data();
4661  if (p==NULL) { /*res->data=(char *)0;*/ return FALSE; }
4662  if ((pNext(p)!=NULL)|| (!pIsConstant(p)))
4663  {
4664  WerrorS("poly must be constant");
4665  return TRUE;
4666  }
4667  res->data = (char *)(long)iin_Int(pGetCoeff(p),currRing->cf);
4668  return FALSE;
4669 }
4671 {
4672  map mapping=(map)v->Data();
4673  syMake(res,omStrDup(mapping->preimage));
4674  return FALSE;
4675 }
4676 static BOOLEAN jjPRIME(leftv res, leftv v)
4677 {
4678  int i = IsPrime((int)(long)(v->Data()));
4679  res->data = (char *)(long)(i > 1 ? i : 2);
4680  return FALSE;
4681 }
4682 static BOOLEAN jjPRUNE(leftv res, leftv v)
4683 {
4684  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4685  ideal v_id=(ideal)v->Data();
4686  if (w!=NULL)
4687  {
4688  if (!idTestHomModule(v_id,currRing->qideal,w))
4689  {
4690  WarnS("wrong weights");
4691  w=NULL;
4692  // and continue at the non-homog case below
4693  }
4694  else
4695  {
4696  w=ivCopy(w);
4697  intvec **ww=&w;
4698  res->data = (char *)idMinEmbedding(v_id,FALSE,ww);
4699  atSet(res,omStrDup("isHomog"),*ww,INTVEC_CMD);
4700  return FALSE;
4701  }
4702  }
4703  res->data = (char *)idMinEmbedding(v_id);
4704  return FALSE;
4705 }
4706 static BOOLEAN jjP2N(leftv res, leftv v)
4707 {
4708  number n;
4709  poly p;
4710  if (((p=(poly)v->Data())!=NULL)
4711  && (pIsConstant(p)))
4712  {
4713  n=nCopy(pGetCoeff(p));
4714  }
4715  else
4716  {
4717  n=nInit(0);
4718  }
4719  res->data = (char *)n;
4720  return FALSE;
4721 }
4723 {
4724  char *s= (char *)v->Data();
4725  for(unsigned i=0; i<sArithBase.nCmdUsed; i++)
4726  {
4727  //Print("test %d, >>%s<<, tab:>>%s<<\n",i,s,sArithBase.sCmds[i].name);
4728  if (strcmp(s, sArithBase.sCmds[i].name) == 0)
4729  {
4730  res->data = (char *)1;
4731  return FALSE;
4732  }
4733  }
4734  //res->data = (char *)0;
4735  return FALSE;
4736 }
4737 static BOOLEAN jjRANK1(leftv res, leftv v)
4738 {
4739  matrix m =(matrix)v->Data();
4740  int rank = luRank(m, 0);
4741  res->data =(char *)(long)rank;
4742  return FALSE;
4743 }
4744 static BOOLEAN jjREAD(leftv res, leftv v)
4745 {
4746  return jjREAD2(res,v,NULL);
4747 }
4749 {
4750  res->data = (char *)(long)iiRegularity((lists)v->Data());
4751  return FALSE;
4752 }
4753 static BOOLEAN jjREPART(leftv res, leftv v)
4754 {
4755  res->data = (char *)n_RePart((number)v->Data(),currRing->cf);
4756  return FALSE;
4757 }
4759 {
4760  ring r=(ring)v->Data();
4761  if (r!=NULL)
4762  res->data = (char *)rDecompose((ring)v->Data());
4763  return (r==NULL)||(res->data==NULL);
4764 }
4766 {
4767  coeffs r=(coeffs)v->Data();
4768  if (r!=NULL)
4769  return rDecompose_CF(res,r);
4770  return TRUE;
4771 }
4773 {
4774  ring r=(ring)v->Data();
4775  if (r!=NULL)
4776  res->data = (char *)rDecompose_list_cf((ring)v->Data());
4777  return (r==NULL)||(res->data==NULL);
4778 }
4779 static BOOLEAN jjROWS(leftv res, leftv v)
4780 {
4781  ideal i = (ideal)v->Data();
4782  res->data = (char *)i->rank;
4783  return FALSE;
4784 }
4786 {
4787  res->data = (char *)(long)((bigintmat*)(v->Data()))->rows();
4788  return FALSE;
4789 }
4791 {
4792  res->data = (char *)(long)((intvec*)(v->Data()))->rows();
4793  return FALSE;
4794 }
4795 static BOOLEAN jjRPAR(leftv res, leftv v)
4796 {
4797  res->data = (char *)(long)rPar(((ring)v->Data()));
4798  return FALSE;
4799 }
4801 {
4802 #ifdef HAVE_PLURAL
4803  const bool bIsSCA = rIsSCA(currRing);
4804 #else
4805  const bool bIsSCA = false;
4806 #endif
4807 
4808  if ((currRing->qideal!=NULL) && !bIsSCA)
4809  {
4810  WerrorS("qring not supported by slimgb at the moment");
4811  return TRUE;
4812  }
4814  {
4815  WerrorS("ordering must be global for slimgb");
4816  return TRUE;
4817  }
4818  intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
4819  // tHomog hom=testHomog;
4820  ideal u_id=(ideal)u->Data();
4821  if (w!=NULL)
4822  {
4823  if (!idTestHomModule(u_id,currRing->qideal,w))
4824  {
4825  WarnS("wrong weights");
4826  w=NULL;
4827  }
4828  else
4829  {
4830  w=ivCopy(w);
4831  // hom=isHomog;
4832  }
4833  }
4834 
4835  assume(u_id->rank>=id_RankFreeModule(u_id, currRing));
4836  res->data=(char *)t_rep_gb(currRing,
4837  u_id,u_id->rank);
4838  //res->data=(char *)t_rep_gb(currRing, u_id);
4839 
4841  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
4842  return FALSE;
4843 }
4844 static BOOLEAN jjSBA(leftv res, leftv v)
4845 {
4846  ideal result;
4847  ideal v_id=(ideal)v->Data();
4848  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4849  tHomog hom=testHomog;
4850  if (w!=NULL)
4851  {
4852  if (!idTestHomModule(v_id,currRing->qideal,w))
4853  {
4854  WarnS("wrong weights");
4855  w=NULL;
4856  }
4857  else
4858  {
4859  hom=isHomog;
4860  w=ivCopy(w);
4861  }
4862  }
4863  result=kSba(v_id,currRing->qideal,hom,&w,1,0);
4864  idSkipZeroes(result);
4865  res->data = (char *)result;
4867  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
4868  return FALSE;
4869 }
4870 static BOOLEAN jjSBA_1(leftv res, leftv v, leftv u)
4871 {
4872  ideal result;
4873  ideal v_id=(ideal)v->Data();
4874  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4875  tHomog hom=testHomog;
4876  if (w!=NULL)
4877  {
4878  if (!idTestHomModule(v_id,currRing->qideal,w))
4879  {
4880  WarnS("wrong weights");
4881  w=NULL;
4882  }
4883  else
4884  {
4885  hom=isHomog;
4886  w=ivCopy(w);
4887  }
4888  }
4889  result=kSba(v_id,currRing->qideal,hom,&w,(int)(long)u->Data(),0);
4890  idSkipZeroes(result);
4891  res->data = (char *)result;
4893  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
4894  return FALSE;
4895 }
4896 static BOOLEAN jjSBA_2(leftv res, leftv v, leftv u, leftv t)
4897 {
4898  ideal result;
4899  ideal v_id=(ideal)v->Data();
4900  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4901  tHomog hom=testHomog;
4902  if (w!=NULL)
4903  {
4904  if (!idTestHomModule(v_id,currRing->qideal,w))
4905  {
4906  WarnS("wrong weights");
4907  w=NULL;
4908  }
4909  else
4910  {
4911  hom=isHomog;
4912  w=ivCopy(w);
4913  }
4914  }
4915  result=kSba(v_id,currRing->qideal,hom,&w,(int)(long)u->Data(),(int)(long)t->Data());
4916  idSkipZeroes(result);
4917  res->data = (char *)result;
4919  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
4920  return FALSE;
4921 }
4922 static BOOLEAN jjSTD(leftv res, leftv v)
4923 {
4924  ideal result;
4925  ideal v_id=(ideal)v->Data();
4926  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4927  tHomog hom=testHomog;
4928  if (w!=NULL)
4929  {
4930  if (!idTestHomModule(v_id,currRing->qideal,w))
4931  {
4932  WarnS("wrong weights");
4933  w=NULL;
4934  }
4935  else
4936  {
4937  hom=isHomog;
4938  w=ivCopy(w);
4939  }
4940  }
4941  result=kStd(v_id,currRing->qideal,hom,&w);
4942  idSkipZeroes(result);
4943  res->data = (char *)result;
4945  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
4946  return FALSE;
4947 }
4949 {
4950  res->data = (char *)idSort((ideal)v->Data());
4951  return FALSE;
4952 }
4954 {
4955  singclap_factorize_retry=0;
4956  intvec *v=NULL;
4957  ideal f=singclap_sqrfree((poly)(u->CopyD()), &v, 0, currRing);
4958  if (f==NULL) return TRUE;
4959  ivTest(v);
4961  l->Init(2);
4962  l->m[0].rtyp=IDEAL_CMD;
4963  l->m[0].data=(void *)f;
4964  l->m[1].rtyp=INTVEC_CMD;
4965  l->m[1].data=(void *)v;
4966  res->data=(void *)l;
4967  return FALSE;
4968 }
4969 #if 1
4970 static BOOLEAN jjSYZYGY(leftv res, leftv v)
4971 {
4972  intvec *w=NULL;
4973  res->data = (char *)idSyzygies((ideal)v->Data(),testHomog,&w);
4974  if (w!=NULL) delete w;
4976  return FALSE;
4977 }
4978 #else
4979 // activate, if idSyz handle module weights correctly !
4980 static BOOLEAN jjSYZYGY(leftv res, leftv v)
4981 {
4982  intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD);
4983  ideal v_id=(ideal)v->Data();
4984  tHomog hom=testHomog;
4985  int add_row_shift=0;
4986  if (w!=NULL)
4987  {
4988  w=ivCopy(w);
4989  add_row_shift=w->min_in();
4990  (*w)-=add_row_shift;
4991  if (idTestHomModule(v_id,currRing->qideal,w))
4992  hom=isHomog;
4993  else
4994  {
4995  //WarnS("wrong weights");
4996  delete w; w=NULL;
4997  hom=testHomog;
4998  }
4999  }
5000  res->data = (char *)idSyzygies(v_id,hom,&w);
5001  if (w!=NULL)
5002  {
5003  atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
5004  }
5005  return FALSE;
5006 }
5007 #endif
5009 {
5010  res->data = (char *)(long)ivTrace((intvec*)(v->Data()));
5011  return FALSE;
5012 }
5014 {
5015  res->data = (char *)(((bigintmat*)(v->Data()))->transpose());
5016  return FALSE;
5017 }
5019 {
5020  res->data = (char *)ivTranp((intvec*)(v->Data()));
5021  return FALSE;
5022 }
5023 #ifdef HAVE_PLURAL
5025 {
5026  ring r = (ring)a->Data();
5027  //if (rIsPluralRing(r))
5028  if (r->OrdSgn==1)
5029  {
5030  res->data = rOpposite(r);
5031  }
5032  else
5033  {
5034  WarnS("opposite only for global orderings");
5035  res->data = rCopy(r);
5036  }
5037  return FALSE;
5038 }
5040 {
5041  ring r = (ring)a->Data();
5042  if (rIsPluralRing(r))
5043  {
5044  ring s = rEnvelope(r);
5045  res->data = s;
5046  }
5047  else res->data = rCopy(r);
5048  return FALSE;
5049 }
5051 {
5052  if (rIsPluralRing(currRing)) res->data=(ideal)twostd((ideal)a->Data());
5053  else res->data=(ideal)a->CopyD();
5054  setFlag(res,FLAG_STD);
5055  setFlag(res,FLAG_TWOSTD);
5056  return FALSE;
5057 }
5058 #endif
5059 
5060 static BOOLEAN jjTYPEOF(leftv res, leftv v)
5061 {
5062  int t=(int)(long)v->data;
5063  switch (t)
5064  {
5065  case CRING_CMD:
5066  case INT_CMD:
5067  case POLY_CMD:
5068  case VECTOR_CMD:
5069  case STRING_CMD:
5070  case INTVEC_CMD:
5071  case IDEAL_CMD:
5072  case MATRIX_CMD:
5073  case MODUL_CMD:
5074  case MAP_CMD:
5075  case PROC_CMD:
5076  case RING_CMD:
5077  //case QRING_CMD:
5078  case INTMAT_CMD:
5079  case BIGINTMAT_CMD:
5080  case NUMBER_CMD:
5081  #ifdef SINGULAR_4_2
5082  case CNUMBER_CMD:
5083  #endif
5084  case BIGINT_CMD:
5085  case LIST_CMD:
5086  case PACKAGE_CMD:
5087  case LINK_CMD:
5088  case RESOLUTION_CMD:
5089  res->data=omStrDup(Tok2Cmdname(t)); break;
5090  case DEF_CMD:
5091  case NONE: res->data=omStrDup("none"); break;
5092  default:
5093  {
5094  if (t>MAX_TOK)
5095  res->data=omStrDup(getBlackboxName(t));
5096  else
5097  res->data=omStrDup("?unknown type?");
5098  break;
5099  }
5100  }
5101  return FALSE;
5102 }
5104 {
5105  res->data=(char *)(long)pIsUnivariate((poly)v->Data());
5106  return FALSE;
5107 }
5108 static BOOLEAN jjVAR1(leftv res, leftv v)
5109 {
5110  int i=(int)(long)v->Data();
5111  if ((0<i) && (i<=currRing->N))
5112  {
5113  poly p=pOne();
5114  pSetExp(p,i,1);
5115  pSetm(p);
5116  res->data=(char *)p;
5117  }
5118  else
5119  {
5120  Werror("var number %d out of range 1..%d",i,currRing->N);
5121  return TRUE;
5122  }
5123  return FALSE;
5124 }
5126 {
5127  if (currRing==NULL)
5128  {
5129  WerrorS("no ring active");
5130  return TRUE;
5131  }
5132  int i=(int)(long)v->Data();
5133  if ((0<i) && (i<=currRing->N))
5134  res->data=omStrDup(currRing->names[i-1]);
5135  else
5136  {
5137  Werror("var number %d out of range 1..%d",i,currRing->N);
5138  return TRUE;
5139  }
5140  return FALSE;
5141 }
5142 static BOOLEAN jjVDIM(leftv res, leftv v)
5143 {
5144  assumeStdFlag(v);
5145  res->data = (char *)(long)scMult0Int((ideal)v->Data(),currRing->qideal);
5146  return FALSE;
5147 }
5149 {
5150 // input: u: a list with links of type
5151 // ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch
5152 // returns: -1: the read state of all links is eof
5153 // i>0: (at least) u[i] is ready
5154  lists Lforks = (lists)u->Data();
5155  int i = slStatusSsiL(Lforks, -1);
5156  if(i == -2) /* error */
5157  {
5158  return TRUE;
5159  }
5160  res->data = (void*)(long)i;
5161  return FALSE;
5162 }
5164 {
5165 // input: u: a list with links of type
5166 // ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch
5167 // returns: -1: the read state of all links is eof
5168 // 1: all links are ready
5169 // (caution: at least one is ready, but some maybe dead)
5170  lists Lforks = (lists)u->CopyD();
5171  int i;
5172  int j = -1;
5173  for(int nfinished = 0; nfinished < Lforks->nr+1; nfinished++)
5174  {
5175  i = slStatusSsiL(Lforks, -1);
5176  if(i == -2) /* error */
5177  {
5178  return TRUE;
5179  }
5180  if(i == -1)
5181  {
5182  break;
5183  }
5184  j = 1;
5185  Lforks->m[i-1].CleanUp();
5186  Lforks->m[i-1].rtyp=DEF_CMD;
5187  Lforks->m[i-1].data=NULL;
5188  }
5189  res->data = (void*)(long)j;
5190  Lforks->Clean();
5191  return FALSE;
5192 }
5193 
5194 BOOLEAN jjLOAD(const char *s, BOOLEAN autoexport)
5195 {
5196  char libnamebuf[256];
5197  lib_types LT = type_of_LIB(s, libnamebuf);
5198 
5199 #ifdef HAVE_DYNAMIC_LOADING
5200  extern BOOLEAN load_modules(const char *newlib, char *fullpath, BOOLEAN autoexport);
5201 #endif /* HAVE_DYNAMIC_LOADING */
5202  switch(LT)
5203  {
5204  default:
5205  case LT_NONE:
5206  Werror("%s: unknown type", s);
5207  break;
5208  case LT_NOTFOUND:
5209  Werror("cannot open %s", s);
5210  break;
5211 
5212  case LT_SINGULAR:
5213  {
5214  char *plib = iiConvName(s);
5215  idhdl pl = IDROOT->get(plib,0);
5216  if (pl==NULL)
5217  {
5218  pl = enterid( plib,0, PACKAGE_CMD, &(basePack->idroot), TRUE );
5219  IDPACKAGE(pl)->language = LANG_SINGULAR;
5220  IDPACKAGE(pl)->libname=omStrDup(plib);
5221  }
5222  else if (IDTYP(pl)!=PACKAGE_CMD)
5223  {
5224  Werror("can not create package `%s`",plib);
5225  omFree(plib);
5226  return TRUE;
5227  }
5228  package savepack=currPack;
5229  currPack=IDPACKAGE(pl);
5230  IDPACKAGE(pl)->loaded=TRUE;
5231  char libnamebuf[256];
5232  FILE * fp = feFopen( s, "r", libnamebuf, TRUE );
5233  BOOLEAN bo=iiLoadLIB(fp, libnamebuf, s, pl, autoexport, TRUE);
5234  currPack=savepack;
5235  IDPACKAGE(pl)->loaded=(!bo);
5236  return bo;
5237  }
5238  case LT_BUILTIN:
5239  SModulFunc_t iiGetBuiltinModInit(const char*);
5240  return load_builtin(s,autoexport, iiGetBuiltinModInit(s));
5241  case LT_MACH_O:
5242  case LT_ELF:
5243  case LT_HPUX:
5244 #ifdef HAVE_DYNAMIC_LOADING
5245  return load_modules(s, libnamebuf, autoexport);
5246 #else /* HAVE_DYNAMIC_LOADING */
5247  WerrorS("Dynamic modules are not supported by this version of Singular");
5248  break;
5249 #endif /* HAVE_DYNAMIC_LOADING */
5250  }
5251  return TRUE;
5252 }
5253 static int WerrorS_dummy_cnt=0;
5254 static void WerrorS_dummy(const char *)
5255 {
5256  WerrorS_dummy_cnt++;
5257 }
5258 BOOLEAN jjLOAD_TRY(const char *s)
5259 {
5260  void (*WerrorS_save)(const char *s) = WerrorS_callback;
5262  WerrorS_dummy_cnt=0;
5263  BOOLEAN bo=jjLOAD(s,TRUE);
5264  if (TEST_OPT_PROT && (bo || (WerrorS_dummy_cnt>0)))
5265  Print("loading of >%s< failed\n",s);
5266  WerrorS_callback=WerrorS_save;
5267  errorreported=0;
5268  return FALSE;
5269 }
5270 
5271 static BOOLEAN jjstrlen(leftv res, leftv v)
5272 {
5273  res->data = (char *)strlen((char *)v->Data());
5274  return FALSE;
5275 }
5277 {
5278  res->data = (char *)(long)pLength((poly)v->Data());
5279  return FALSE;
5280 }
5281 static BOOLEAN jjidElem(leftv res, leftv v)
5282 {
5283  res->data = (char *)(long)idElem((ideal)v->Data());
5284  return FALSE;
5285 }
5287 {
5288  res->data = (char *)id_FreeModule((int)(long)v->Data(), currRing);
5289  return FALSE;
5290 }
5292 {
5293  res->data = (char *)id_Vec2Ideal((poly)v->Data(), currRing);
5294  return FALSE;
5295 }
5297 {
5298  res->data = rCharStr((ring)v->Data());
5299  return FALSE;
5300 }
5301 static BOOLEAN jjpHead(leftv res, leftv v)
5302 {
5303  res->data = (char *)pHead((poly)v->Data());
5304  return FALSE;
5305 }
5306 static BOOLEAN jjidHead(leftv res, leftv v)
5307 {
5308  res->data = (char *)id_Head((ideal)v->Data(),currRing);
5309  setFlag(res,FLAG_STD);
5310  return FALSE;
5311 }
5313 {
5314  res->data = (char *)idMinBase((ideal)v->Data());
5315  return FALSE;
5316 }
5317 #if 0 // unused
5318 static BOOLEAN jjsyMinBase(leftv res, leftv v)
5319 {
5320  res->data = (char *)syMinBase((ideal)v->Data());
5321  return FALSE;
5322 }
5323 #endif
5325 {
5326  res->data = (char *)pMaxComp((poly)v->Data());
5327  return FALSE;
5328 }
5330 {
5331  res->data = (char *)mp_Trace((matrix)v->Data(),currRing);
5332  return FALSE;
5333 }
5335 {
5336  res->data = (char *)mp_Transp((matrix)v->Data(),currRing);
5337  return FALSE;
5338 }
5340 {
5341  res->data = rOrdStr((ring)v->Data());
5342  return FALSE;
5343 }
5345 {
5346  res->data = rVarStr((ring)v->Data());
5347  return FALSE;
5348 }
5350 {
5351  res->data = rParStr((ring)v->Data());
5352  return FALSE;
5353 }
5355 {
5356  res->data=(char *)(long)sySize((syStrategy)v->Data());
5357  return FALSE;
5358 }
5359 static BOOLEAN jjDIM_R(leftv res, leftv v)
5360 {
5361  res->data = (char *)(long)syDim((syStrategy)v->Data());
5362  return FALSE;
5363 }
5365 {
5366  res->data = (char *)id_Transp((ideal)v->Data(),currRing);
5367  return FALSE;
5368 }
5369 static BOOLEAN jjnInt(leftv res, leftv u)
5370 {
5371  number n=(number)u->CopyD(); // n_Int may call n_Normalize
5372  res->data=(char *)(long)iin_Int(n,currRing->cf);
5373  n_Delete(&n,currRing->cf);
5374  return FALSE;
5375 }
5376 static BOOLEAN jjnlInt(leftv res, leftv u)
5377 {
5378  number n=(number)u->Data();
5379  res->data=(char *)(long)iin_Int(n,coeffs_BIGINT );
5380  return FALSE;
5381 }
5382 /*=================== operations with 3 args.: static proc =================*/
5383 /* must be ordered: first operations for chars (infix ops),
5384  * then alphabetically */
5386 {
5387  char *s= (char *)u->Data();
5388  int r = (int)(long)v->Data();
5389  int c = (int)(long)w->Data();
5390  int l = strlen(s);
5391 
5392  if ( (r<1) || (r>l) || (c<0) )
5393  {
5394  Werror("wrong range[%d,%d] in string %s",r,c,u->Fullname());
5395  return TRUE;
5396  }
5397  res->data = (char *)omAlloc((long)(c+1));
5398  sprintf((char *)res->data,"%-*.*s",c,c,s+r-1);
5399  return FALSE;
5400 }
5402 {
5403  intvec *iv = (intvec *)u->Data();
5404  int r = (int)(long)v->Data();
5405  int c = (int)(long)w->Data();
5406  if ((r<1)||(r>iv->rows())||(c<1)||(c>iv->cols()))
5407  {
5408  Werror("wrong range[%d,%d] in intmat %s(%d x %d)",
5409  r,c,u->Fullname(),iv->rows(),iv->cols());
5410  return TRUE;
5411  }
5412  res->data=u->data; u->data=NULL;
5413  res->rtyp=u->rtyp; u->rtyp=0;
5414  res->name=u->name; u->name=NULL;
5415  Subexpr e=jjMakeSub(v);
5416  e->next=jjMakeSub(w);
5417  if (u->e==NULL) res->e=e;
5418  else
5419  {
5420  Subexpr h=u->e;
5421  while (h->next!=NULL) h=h->next;
5422  h->next=e;
5423  res->e=u->e;
5424  u->e=NULL;
5425  }
5426  return FALSE;
5427 }
5429 {
5430  bigintmat *bim = (bigintmat *)u->Data();
5431  int r = (int)(long)v->Data();
5432  int c = (int)(long)w->Data();
5433  if ((r<1)||(r>bim->rows())||(c<1)||(c>bim->cols()))
5434  {
5435  Werror("wrong range[%d,%d] in bigintmat %s(%d x %d)",
5436  r,c,u->Fullname(),bim->rows(),bim->cols());
5437  return TRUE;
5438  }
5439  res->data=u->data; u->data=NULL;
5440  res->rtyp=u->rtyp; u->rtyp=0;
5441  res->name=u->name; u->name=NULL;
5442  Subexpr e=jjMakeSub(v);
5443  e->next=jjMakeSub(w);
5444  if (u->e==NULL)
5445  res->e=e;
5446  else
5447  {
5448  Subexpr h=u->e;
5449  while (h->next!=NULL) h=h->next;
5450  h->next=e;
5451  res->e=u->e;
5452  u->e=NULL;
5453  }
5454  return FALSE;
5455 }
5457 {
5458  matrix m= (matrix)u->Data();
5459  int r = (int)(long)v->Data();
5460  int c = (int)(long)w->Data();
5461  //Print("gen. elem %d, %d\n",r,c);
5462  if ((r<1)||(r>MATROWS(m))||(c<1)||(c>MATCOLS(m)))
5463  {
5464  Werror("wrong range[%d,%d] in matrix %s(%d x %d)",r,c,u->Fullname(),
5465  MATROWS(m),MATCOLS(m));
5466  return TRUE;
5467  }
5468  res->data=u->data; u->data=NULL;
5469  res->rtyp=u->rtyp; u->rtyp=0;
5470  res->name=u->name; u->name=NULL;
5471  Subexpr e=jjMakeSub(v);
5472  e->next=jjMakeSub(w);
5473  if (u->e==NULL)
5474  res->e=e;
5475  else
5476  {
5477  Subexpr h=u->e;
5478  while (h->next!=NULL) h=h->next;
5479  h->next=e;
5480  res->e=u->e;
5481  u->e=NULL;
5482  }
5483  return FALSE;
5484 }
5486 {
5487  sleftv t;
5488  sleftv ut;
5489  leftv p=NULL;
5490  intvec *iv=(intvec *)w->Data();
5491  int l;
5492  BOOLEAN nok;
5493 
5494  if ((u->rtyp!=IDHDL)||(u->e!=NULL))
5495  {
5496  WerrorS("cannot build expression lists from unnamed objects");
5497  return TRUE;
5498  }
5499  memcpy(&ut,u,sizeof(ut));
5500  memset(&t,0,sizeof(t));
5501  t.rtyp=INT_CMD;
5502  for (l=0;l< iv->length(); l++)
5503  {
5504  t.data=(char *)(long)((*iv)[l]);
5505  if (p==NULL)
5506  {
5507  p=res;
5508  }
5509  else
5510  {
5512  p=p->next;
5513  }
5514  memcpy(u,&ut,sizeof(ut));
5515  if (u->Typ() == MATRIX_CMD)
5516  nok=jjBRACK_Ma(p,u,v,&t);
5517  else if (u->Typ() == BIGINTMAT_CMD)
5518  nok=jjBRACK_Bim(p,u,v,&t);
5519  else /* INTMAT_CMD */
5520  nok=jjBRACK_Im(p,u,v,&t);
5521  if (nok)
5522  {
5523  while (res->next!=NULL)
5524  {
5525  p=res->next->next;
5526  omFreeBin((ADDRESS)res->next, sleftv_bin);
5527  // res->e aufraeumen !!!!
5528  res->next=p;
5529  }
5530  return TRUE;
5531  }
5532  }
5533  return FALSE;
5534 }
5536 {
5537  sleftv t;
5538  sleftv ut;
5539  leftv p=NULL;
5540  intvec *iv=(intvec *)v->Data();
5541  int l;
5542  BOOLEAN nok;
5543 
5544  if ((u->rtyp!=IDHDL)||(u->e!=NULL))
5545  {
5546  WerrorS("cannot build expression lists from unnamed objects");
5547  return TRUE;
5548  }
5549  memcpy(&ut,u,sizeof(ut));
5550  memset(&t,0,sizeof(t));
5551  t.rtyp=INT_CMD;
5552  for (l=0;l< iv->length(); l++)
5553  {
5554  t.data=(char *)(long)((*iv)[l]);
5555  if (p==NULL)
5556  {
5557  p=res;
5558  }
5559  else
5560  {
5562  p=p->next;
5563  }
5564  memcpy(u,&ut,sizeof(ut));
5565  if (u->Typ() == MATRIX_CMD)
5566  nok=jjBRACK_Ma(p,u,&t,w);
5567  else if (u->Typ() == BIGINTMAT_CMD)
5568  nok=jjBRACK_Bim(p,u,&t,w);
5569  else /* INTMAT_CMD */
5570  nok=jjBRACK_Im(p,u,&t,w);
5571  if (nok)
5572  {
5573  while (res->next!=NULL)
5574  {
5575  p=res->next->next;
5576  omFreeBin((ADDRESS)res->next, sleftv_bin);
5577  // res->e aufraeumen !!
5578  res->next=p;
5579  }
5580  return TRUE;
5581  }
5582  }
5583  return FALSE;
5584 }
5586 {
5587  sleftv t1,t2,ut;
5588  leftv p=NULL;
5589  intvec *vv=(intvec *)v->Data();
5590  intvec *wv=(intvec *)w->Data();
5591  int vl;
5592  int wl;
5593  BOOLEAN nok;
5594 
5595  if ((u->rtyp!=IDHDL)||(u->e!=NULL))
5596  {
5597  WerrorS("cannot build expression lists from unnamed objects");
5598  return TRUE;
5599  }
5600  memcpy(&ut,u,sizeof(ut));
5601  memset(&t1,0,sizeof(sleftv));
5602  memset(&t2,0,sizeof(sleftv));
5603  t1.rtyp=INT_CMD;
5604  t2.rtyp=INT_CMD;
5605  for (vl=0;vl< vv->length(); vl++)
5606  {
5607  t1.data=(char *)(long)((*vv)[vl]);
5608  for (wl=0;wl< wv->length(); wl++)
5609  {
5610  t2.data=(char *)(long)((*wv)[wl]);
5611  if (p==NULL)
5612  {
5613  p=res;
5614  }
5615  else
5616  {
5618  p=p->next;
5619  }
5620  memcpy(u,&ut,sizeof(ut));
5621  if (u->Typ() == MATRIX_CMD)
5622  nok=jjBRACK_Ma(p,u,&t1,&t2);
5623  else if (u->Typ() == BIGINTMAT_CMD)
5624  nok=jjBRACK_Bim(p,u,&t1,&t2);
5625  else /* INTMAT_CMD */
5626  nok=jjBRACK_Im(p,u,&t1,&t2);
5627  if (nok)
5628  {
5629  res->CleanUp();
5630  return TRUE;
5631  }
5632  }
5633  }
5634  return FALSE;
5635 }
5636 static BOOLEAN jjPROC3(leftv res, leftv u, leftv v, leftv w)
5637 {
5639  memcpy(v->next,w,sizeof(sleftv));
5640  memset(w,0,sizeof(sleftv));
5641  return jjPROC(res,u,v);
5642 }
5643 static BOOLEAN jjRING_2(leftv res, leftv u, leftv v, leftv w)
5644 {
5645  u->next=(leftv)omAlloc(sizeof(sleftv));
5646  memcpy(u->next,v,sizeof(sleftv));
5647  memset(v,0,sizeof(sleftv));
5648  u->next->next=(leftv)omAlloc(sizeof(sleftv));
5649  memcpy(u->next->next,w,sizeof(sleftv));
5650  memset(w,0,sizeof(sleftv));
5651  BOOLEAN bo=iiExprArithM(res,u,'[');
5652  u->next=NULL;
5653  return bo;
5654 }
5655 static BOOLEAN jjBAREISS3(leftv res, leftv u, leftv v, leftv w)
5656 {
5657  intvec *iv;
5658  ideal m;
5660  int k=(int)(long)w->Data();
5661  if (k>=0)
5662  {
5663  sm_CallBareiss((ideal)u->Data(),(int)(long)v->Data(),(int)(long)w->Data(),m,&iv, currRing);
5664  l->Init(2);
5665  l->m[0].rtyp=MODUL_CMD;
5666  l->m[1].rtyp=INTVEC_CMD;
5667  l->m[0].data=(void *)m;
5668  l->m[1].data=(void *)iv;
5669  }
5670  else
5671  {
5672  m=sm_CallSolv((ideal)u->Data(), currRing);
5673  l->Init(1);
5674  l->m[0].rtyp=IDEAL_CMD;
5675  l->m[0].data=(void *)m;
5676  }
5677  res->data = (char *)l;
5678  return FALSE;
5679 }
5681 {
5682  if ((w->rtyp!=IDHDL)||(w->e!=NULL))
5683  {
5684  WerrorS("3rd argument must be a name of a matrix");
5685  return TRUE;
5686  }
5687  ideal i=(ideal)u->Data();
5688  int rank=(int)i->rank;
5689  BOOLEAN r=jjCOEFFS_Id(res,u,v);
5690  if (r) return TRUE;
5691  mp_Monomials((matrix)res->data, rank, pVar((poly)v->Data()),(matrix)w->Data(),currRing);
5692  return FALSE;
5693 }
5695 {
5696  res->data=(void*)idCoeffOfKBase((ideal)(u->Data()),
5697  (ideal)(v->Data()),(poly)(w->Data()));
5698  return FALSE;
5699 }
5701 {
5702  if ((w->rtyp!=IDHDL)||(w->e!=NULL))
5703  {
5704  WerrorS("3rd argument must be a name of a matrix");
5705  return TRUE;
5706  }
5707  // CopyD for POLY_CMD and VECTOR_CMD are identical:
5708  poly p=(poly)u->CopyD(POLY_CMD);
5709  ideal i=idInit(1,1);
5710  i->m[0]=p;
5711  sleftv t;
5712  memset(&t,0,sizeof(t));
5713  t.data=(char *)i;
5714  t.rtyp=IDEAL_CMD;
5715  int rank=1;
5716  if (u->Typ()==VECTOR_CMD)
5717  {
5718  i->rank=rank=pMaxComp(p);
5719  t.rtyp=MODUL_CMD;
5720  }
5721  BOOLEAN r=jjCOEFFS_Id(res,&t,v);
5722  t.CleanUp();
5723  if (r) return TRUE;
5724  mp_Monomials((matrix)res->data, rank, pVar((poly)v->Data()),(matrix)w->Data(),currRing);
5725  return FALSE;
5726 }
5728 {
5729  res->data=(char *)idElimination((ideal)u->Data(),(poly)v->Data(),
5730  (intvec *)w->Data());
5731  //setFlag(res,FLAG_STD);
5732  return FALSE;
5733 }
5734 static BOOLEAN jjFIND3(leftv res, leftv u, leftv v, leftv w)
5735 {
5736  /*4
5737  * look for the substring what in the string where
5738  * starting at position n
5739  * return the position of the first char of what in where
5740  * or 0
5741  */
5742  int n=(int)(long)w->Data();
5743  char *where=(char *)u->Data();
5744  char *what=(char *)v->Data();
5745  char *found;
5746  if ((1>n)||(n>(int)strlen(where)))
5747  {
5748  Werror("start position %d out of range",n);
5749  return TRUE;
5750  }
5751  found = strchr(where+n-1,*what);
5752  if (*(what+1)!='\0')
5753  {
5754  while((found !=NULL) && (strncmp(found+1,what+1,strlen(what+1))!=0))
5755  {
5756  found=strchr(found+1,*what);
5757  }
5758  }
5759  if (found != NULL)
5760  {
5761  res->data=(char *)((found-where)+1);
5762  }
5763  return FALSE;
5764 }
5765 static BOOLEAN jjFWALK3(leftv res, leftv u, leftv v, leftv w)
5766 {
5767  if ((int)(long)w->Data()==0)
5768  res->data=(char *)walkProc(u,v);
5769  else
5770  res->data=(char *)fractalWalkProc(u,v);
5771  setFlag( res, FLAG_STD );
5772  return FALSE;
5773 }
5774 static BOOLEAN jjHILBERT3(leftv res, leftv u, leftv v, leftv w)
5775 {
5776  intvec *wdegree=(intvec*)w->Data();
5777  if (wdegree->length()!=currRing->N)
5778  {
5779  Werror("weight vector must have size %d, not %d",
5780  currRing->N,wdegree->length());
5781  return TRUE;
5782  }
5784  {
5785  ring origR = currRing;
5786  ring tempR = rCopy(origR);
5787  coeffs new_cf=nInitChar(n_Q,NULL);
5788  nKillChar(tempR->cf);
5789  tempR->cf=new_cf;
5790  rComplete(tempR);
5791  ideal uid = (ideal)u->Data();
5792  rChangeCurrRing(tempR);
5793  ideal uu = idrCopyR(uid, origR, currRing);
5794  sleftv uuAsLeftv; memset(&uuAsLeftv, 0, sizeof(uuAsLeftv));
5795  uuAsLeftv.rtyp = IDEAL_CMD;
5796  uuAsLeftv.data = uu; uuAsLeftv.next = NULL;
5797  if (hasFlag(u, FLAG_STD)) setFlag(&uuAsLeftv,FLAG_STD);
5798  assumeStdFlag(&uuAsLeftv);
5799  PrintS("// NOTE: computation of Hilbert series etc. is being\n");
5800  PrintS("// performed for generic fibre, that is, over Q\n");
5801  intvec *module_w=(intvec*)atGet(&uuAsLeftv,"isHomog",INTVEC_CMD);
5802  intvec *iv=hFirstSeries(uu,module_w,currRing->qideal,wdegree);
5803  int returnWithTrue = 1;
5804  switch((int)(long)v->Data())
5805  {
5806  case 1:
5807  res->data=(void *)iv;
5808  returnWithTrue = 0;
5809  case 2:
5810  res->data=(void *)hSecondSeries(iv);
5811  delete iv;
5812  returnWithTrue = 0;
5813  }
5814  if (returnWithTrue)
5815  {
5817  delete iv;
5818  }
5819  idDelete(&uu);
5820  rChangeCurrRing(origR);
5821  rDelete(tempR);
5822  if (returnWithTrue) return TRUE; else return FALSE;
5823  }
5824  assumeStdFlag(u);
5825  intvec *module_w=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
5826  intvec *iv=hFirstSeries((ideal)u->Data(),module_w,currRing->qideal,wdegree);
5827  switch((int)(long)v->Data())
5828  {
5829  case 1:
5830  res->data=(void *)iv;
5831  return FALSE;
5832  case 2:
5833  res->data=(void *)hSecondSeries(iv);
5834  delete iv;
5835  return FALSE;
5836  }
5838  delete iv;
5839  return TRUE;
5840 }
5841 static BOOLEAN jjHOMOG_ID_W(leftv res, leftv u, leftv v, leftv /*w*/)
5842 {
5843  PrintS("TODO\n");
5844  int i=pVar((poly)v->Data());
5845  if (i==0)
5846  {
5847  WerrorS("ringvar expected");
5848  return TRUE;
5849  }
5850  poly p=pOne(); pSetExp(p,i,1); pSetm(p);
5851  int d=pWTotaldegree(p);
5852  pLmDelete(p);
5853  if (d==1)
5854  res->data = (char *)id_Homogen((ideal)u->Data(), i, currRing);
5855  else
5856  WerrorS("variable must have weight 1");
5857  return (d!=1);
5858 }
5859 static BOOLEAN jjHOMOG_P_W(leftv res, leftv u, leftv v,leftv /*w*/)
5860 {
5861  PrintS("TODO\n");
5862  int i=pVar((poly)v->Data());
5863  if (i==0)
5864  {
5865  WerrorS("ringvar expected");
5866  return TRUE;
5867  }
5868  poly p=pOne(); pSetExp(p,i,1); pSetm(p);
5869  int d=pWTotaldegree(p);
5870  pLmDelete(p);
5871  if (d==1)
5872  res->data = (char *)p_Homogen((poly)u->Data(), i, currRing);
5873  else
5874  WerrorS("variable must have weight 1");
5875  return (d!=1);
5876 }
5878 {
5879  intvec* im= new intvec((int)(long)v->Data(),(int)(long)w->Data(), 0);
5880  intvec* arg = (intvec*) u->Data();
5881  int i, n = si_min(im->cols()*im->rows(), arg->cols()*arg->rows());
5882 
5883  for (i=0; i<n; i++)
5884  {
5885  (*im)[i] = (*arg)[i];
5886  }
5887 
5888  res->data = (char *)im;
5889  return FALSE;
5890 }
5891 static BOOLEAN jjJET_P_IV(leftv res, leftv u, leftv v, leftv w)
5892 {
5893  short *iw=iv2array((intvec *)w->Data(),currRing);
5894  res->data = (char *)ppJetW((poly)u->Data(),(int)(long)v->Data(),iw);
5895  omFreeSize( (ADDRESS)iw, (rVar(currRing)+1)*sizeof(short) );
5896  return FALSE;
5897 }
5898 static BOOLEAN jjJET_P_P(leftv res, leftv u, leftv v, leftv w)
5899 {
5900  if (!pIsUnit((poly)v->Data()))
5901  {
5902  WerrorS("2nd argument must be a unit");
5903  return TRUE;
5904  }
5905  res->data = (char *)p_Series((int)(long)w->Data(),(poly)u->CopyD(),(poly)v->CopyD(),NULL,currRing);
5906  return FALSE;
5907 }
5909 {
5910  res->data = (char *)id_JetW((ideal)u->Data(),(int)(long)v->Data(),
5911  (intvec *)w->Data(),currRing);
5912  return FALSE;
5913 }
5914 static BOOLEAN jjJET_ID_M(leftv res, leftv u, leftv v, leftv w)
5915 {
5916  if (!mp_IsDiagUnit((matrix)v->Data(), currRing))
5917  {
5918  WerrorS("2nd argument must be a diagonal matrix of units");
5919  return TRUE;
5920  }
5921  res->data = (char *)idSeries((int)(long)w->Data(),(ideal)u->CopyD(),
5922  (matrix)v->CopyD());
5923  return FALSE;
5924 }
5926 {
5927  /* true for fields and Z, false otherwise */
5928  if (rField_is_Ring_PtoM(currRing)) return FALSE;
5929  if (rField_is_Ring_2toM(currRing)) return FALSE;
5930  if (rField_is_Ring_ModN(currRing)) return FALSE;
5931  return TRUE;
5932 }
5934 {
5935  /* Here's the use pattern for the minor command:
5936  minor ( matrix_expression m, int_expression minorSize,
5937  optional ideal_expression IasSB, optional int_expression k,
5938  optional string_expression algorithm,
5939  optional int_expression cachedMinors,
5940  optional int_expression cachedMonomials )
5941  This method here assumes that there are at least two arguments.
5942  - If IasSB is present, it must be a std basis. All minors will be
5943  reduced w.r.t. IasSB.
5944  - If k is absent, all non-zero minors will be computed.
5945  If k is present and k > 0, the first k non-zero minors will be
5946  computed.
5947  If k is present and k < 0, the first |k| minors (some of which
5948  may be zero) will be computed.
5949  If k is present and k = 0, an error is reported.
5950  - If algorithm is absent, all the following arguments must be absent too.
5951  In this case, a heuristic picks the best-suited algorithm (among
5952  Bareiss, Laplace, and Laplace with caching).
5953  If algorithm is present, it must be one of "Bareiss", "bareiss",
5954  "Laplace", "laplace", "Cache", "cache". In the cases "Cache" and
5955  "cache" two more arguments may be given, determining how many entries
5956  the cache may have at most, and how many cached monomials there are at
5957  most. (Cached monomials are counted over all cached polynomials.)
5958  If these two additional arguments are not provided, 200 and 100000
5959  will be used as defaults.
5960  */
5961  matrix m;
5962  leftv u=v->next;
5963  v->next=NULL;
5964  int v_typ=v->Typ();
5965  if (v_typ==MATRIX_CMD)
5966  {
5967  m = (const matrix)v->Data();
5968  }
5969  else
5970  {
5971  if (v_typ==0)
5972  {
5973  Werror("`%s` is undefined",v->Fullname());
5974  return TRUE;
5975  }
5976  // try to convert to MATRIX:
5977  int ii=iiTestConvert(v_typ,MATRIX_CMD);
5978  BOOLEAN bo;
5979  sleftv tmp;
5980  if (ii>0) bo=iiConvert(v_typ,MATRIX_CMD,ii,v,&tmp);
5981  else bo=TRUE;
5982  if (bo)
5983  {
5984  Werror("cannot convert %s to matrix",Tok2Cmdname(v_typ));
5985  return TRUE;
5986  }
5987  m=(matrix)tmp.data;
5988  }
5989  const int mk = (const int)(long)u->Data();
5990  bool noIdeal = true; bool noK = true; bool noAlgorithm = true;
5991  bool noCacheMinors = true; bool noCacheMonomials = true;
5992  ideal IasSB; int k; char* algorithm; int cacheMinors; int cacheMonomials;
5993 
5994  /* here come the different cases of correct argument sets */
5995  if ((u->next != NULL) && (u->next->Typ() == IDEAL_CMD))
5996  {
5997  IasSB = (ideal)u->next->Data();
5998  noIdeal = false;
5999  if ((u->next->next != NULL) && (u->next->next->Typ() == INT_CMD))
6000  {
6001  k = (int)(long)u->next->next->Data();
6002  noK = false;
6003  assume(k != 0);
6004  if ((u->next->next->next != NULL) &&
6005  (u->next->next->next->Typ() == STRING_CMD))
6006  {
6007  algorithm = (char*)u->next->next->next->Data();
6008  noAlgorithm = false;
6009  if ((u->next->next->next->next != NULL) &&
6010  (u->next->next->next->next->Typ() == INT_CMD))
6011  {
6012  cacheMinors = (int)(long)u->next->next->next->next->Data();
6013  noCacheMinors = false;
6014  if ((u->next->next->next->next->next != NULL) &&
6015  (u->next->next->next->next->next->Typ() == INT_CMD))
6016  {
6017  cacheMonomials =
6018  (int)(long)u->next->next->next->next->next->Data();
6019  noCacheMonomials = false;
6020  }
6021  }
6022  }
6023  }
6024  }
6025  else if ((u->next != NULL) && (u->next->Typ() == INT_CMD))
6026  {
6027  k = (int)(long)u->next->Data();
6028  noK = false;
6029  assume(k != 0);
6030  if ((u->next->next != NULL) && (u->next->next->Typ() == STRING_CMD))
6031  {
6032  algorithm = (char*)u->next->next->Data();
6033  noAlgorithm = false;
6034  if ((u->next->next->next != NULL) &&
6035  (u->next->next->next->Typ() == INT_CMD))
6036  {
6037  cacheMinors = (int)(long)u->next->next->next->Data();
6038  noCacheMinors = false;
6039  if ((u->next->next->next->next != NULL) &&
6040  (u->next->next->next->next->Typ() == INT_CMD))
6041  {
6042  cacheMonomials = (int)(long)u->next->next->next->next->Data();
6043  noCacheMonomials = false;
6044  }
6045  }
6046  }
6047  }
6048  else if ((u->next != NULL) && (u->next->Typ() == STRING_CMD))
6049  {
6050  algorithm = (char*)u->next->Data();
6051  noAlgorithm = false;
6052  if ((u->next->next != NULL) && (u->next->next->Typ() == INT_CMD))
6053  {
6054  cacheMinors = (int)(long)u->next->next->Data();
6055  noCacheMinors = false;
6056  if ((u->next->next->next != NULL) &&
6057  (u->next->next->next->Typ() == INT_CMD))
6058  {
6059  cacheMonomials = (int)(long)u->next->next->next->Data();
6060  noCacheMonomials = false;
6061  }
6062  }
6063  }
6064 
6065  /* upper case conversion for the algorithm if present */
6066  if (!noAlgorithm)
6067  {
6068  if (strcmp(algorithm, "bareiss") == 0)
6069  algorithm = (char*)"Bareiss";
6070  if (strcmp(algorithm, "laplace") == 0)
6071  algorithm = (char*)"Laplace";
6072  if (strcmp(algorithm, "cache") == 0)
6073  algorithm = (char*)"Cache";
6074  }
6075 
6076  v->next=u;
6077  /* here come some tests */
6078  if (!noIdeal)
6079  {
6080  assumeStdFlag(u->next);
6081  }
6082  if ((!noK) && (k == 0))
6083  {
6084  WerrorS("Provided number of minors to be computed is zero.");
6085  return TRUE;
6086  }
6087  if ((!noAlgorithm) && (strcmp(algorithm, "Bareiss") != 0)
6088  && (strcmp(algorithm, "Laplace") != 0)
6089  && (strcmp(algorithm, "Cache") != 0))
6090  {
6091  WerrorS("Expected as algorithm one of 'B/bareiss', 'L/laplace', or 'C/cache'.");
6092  return TRUE;
6093  }
6094  if ((!noAlgorithm) && (strcmp(algorithm, "Bareiss") == 0)
6096  {
6097  Werror("Bareiss algorithm not defined over coefficient rings %s",
6098  "with zero divisors.");
6099  return TRUE;
6100  }
6101  res->rtyp=IDEAL_CMD;
6102  if ((mk < 1) || (mk > m->rows()) || (mk > m->cols()))
6103  {
6104  ideal I=idInit(1,1);
6105  if (mk<1) I->m[0]=p_One(currRing);
6106  //Werror("invalid size of minors: %d (matrix is (%d x %d))", mk,
6107  // m->rows(), m->cols());
6108  res->data=(void*)I;
6109  return FALSE;
6110  }
6111  if ((!noAlgorithm) && (strcmp(algorithm, "Cache") == 0)
6112  && (noCacheMinors || noCacheMonomials))
6113  {
6114  cacheMinors = 200;
6115  cacheMonomials = 100000;
6116  }
6117 
6118  /* here come the actual procedure calls */
6119  if (noAlgorithm)
6120  res->data = getMinorIdealHeuristic(m, mk, (noK ? 0 : k),
6121  (noIdeal ? 0 : IasSB), false);
6122  else if (strcmp(algorithm, "Cache") == 0)
6123  res->data = getMinorIdealCache(m, mk, (noK ? 0 : k),
6124  (noIdeal ? 0 : IasSB), 3, cacheMinors,
6125  cacheMonomials, false);
6126  else
6127  res->data = getMinorIdeal(m, mk, (noK ? 0 : k), algorithm,
6128  (noIdeal ? 0 : IasSB), false);
6129  if (v_typ!=MATRIX_CMD) idDelete((ideal *)&m);
6130  return FALSE;
6131 }
6133 {
6134  // u: the name of the new type
6135  // v: the parent type
6136  // w: the elements
6137  newstruct_desc d=newstructChildFromString((const char *)v->Data(),
6138  (const char *)w->Data());
6139  if (d!=NULL) newstruct_setup((const char *)u->Data(),d);
6140  return (d==NULL);
6141 }
6142 static BOOLEAN jjPREIMAGE(leftv res, leftv u, leftv v, leftv w)
6143 {
6144  // handles preimage(r,phi,i) and kernel(r,phi)
6145  idhdl h;
6146  ring rr;
6147  map mapping;
6148  BOOLEAN kernel_cmd= (iiOp==KERNEL_CMD);
6149 
6150  if ((v->name==NULL) || (!kernel_cmd && (w->name==NULL)))
6151  {
6152  WerrorS("2nd/3rd arguments must have names");
6153  return TRUE;
6154  }
6155  rr=(ring)u->Data();
6156  const char *ring_name=u->Name();
6157  if ((h=rr->idroot->get(v->name,myynest))!=NULL)
6158  {
6159  if (h->typ==MAP_CMD)
6160  {
6161  mapping=IDMAP(h);
6162  idhdl preim_ring=IDROOT->get(mapping->preimage,myynest);
6163  if ((preim_ring==NULL)
6164  || (IDRING(preim_ring)!=currRing))
6165  {
6166  Werror("preimage ring `%s` is not the basering",mapping->preimage);
6167  return TRUE;
6168  }
6169  }
6170  else if (h->typ==IDEAL_CMD)
6171  {
6172  mapping=IDMAP(h);
6173  }
6174  else
6175  {
6176  Werror("`%s` is no map nor ideal",IDID(h));
6177  return TRUE;
6178  }
6179  }
6180  else
6181  {
6182  Werror("`%s` is not defined in `%s`",v->name,ring_name);
6183  return TRUE;
6184  }
6185  ideal image;
6186  if (kernel_cmd) image=idInit(1,1);
6187  else
6188  {
6189  if ((h=rr->idroot->get(w->name,myynest))!=NULL)
6190  {
6191  if (h->typ==IDEAL_CMD)
6192  {
6193  image=IDIDEAL(h);
6194  }
6195  else
6196  {
6197  Werror("`%s` is no ideal",IDID(h));
6198  return TRUE;
6199  }
6200  }
6201  else
6202  {
6203  Werror("`%s` is not defined in `%s`",w->name,ring_name);
6204  return TRUE;
6205  }
6206  }
6207  if (((currRing->qideal!=NULL) && (rHasLocalOrMixedOrdering_currRing()))
6208  || ((rr->qideal!=NULL) && (rHasLocalOrMixedOrdering(rr))))
6209  {
6210  WarnS("preimage in local qring may be wrong: use Ring::preimageLoc instead");
6211  }
6212  res->data=(char *)maGetPreimage(rr,mapping,image,currRing);
6213  if (kernel_cmd) idDelete(&image);
6214  return (res->data==NULL/* is of type ideal, should not be NULL*/);
6215 }
6217 {
6218  int di, k;
6219  int i=(int)(long)u->Data();
6220  int r=(int)(long)v->Data();
6221  int c=(int)(long)w->Data();
6222  if ((r<=0) || (c<=0)) return TRUE;
6223  intvec *iv = new intvec(r, c, 0);
6224  if (iv->rows()==0)
6225  {
6226  delete iv;
6227  return TRUE;
6228  }
6229  if (i!=0)
6230  {
6231  if (i<0) i = -i;
6232  di = 2 * i + 1;
6233  for (k=0; k<iv->length(); k++)
6234  {
6235  (*iv)[k] = ((siRand() % di) - i);
6236  }
6237  }
6238  res->data = (char *)iv;
6239  return FALSE;
6240 }
6241 #ifdef SINGULAR_4_2
6242 static BOOLEAN jjRANDOM_CF(leftv res, leftv u, leftv v, leftv w)
6243 // <coeff>, par1, par2 -> number2
6244 {
6245  coeffs cf=(coeffs)u->Data();
6246  if ((cf==NULL) ||(cf->cfRandom==NULL))
6247  {
6248  Werror("no random function defined for coeff %d",cf->type);
6249  return TRUE;
6250  }
6251  else
6252  {
6253  number n= n_Random(siRand,(number)v->Data(),(number)w->Data(),cf);
6254  number2 nn=(number2)omAlloc(sizeof(*nn));
6255  nn->cf=cf;
6256  nn->n=n;
6257  res->data=nn;
6258  return FALSE;
6259  }
6260  return TRUE;
6261 }
6262 #endif
6264  int &ringvar, poly &monomexpr)
6265 {
6266  monomexpr=(poly)w->Data();
6267  poly p=(poly)v->Data();
6268 #if 0
6269  if (pLength(monomexpr)>1)
6270  {
6271  Werror("`%s` substitutes a ringvar only by a term",
6273  return TRUE;
6274  }
6275 #endif
6276  if ((ringvar=pVar(p))==0)
6277  {
6278  if ((p!=NULL) && (currRing->cf->extRing!=NULL))
6279  {
6280  number n = pGetCoeff(p);
6281  ringvar= -n_IsParam(n, currRing);
6282  }
6283  if(ringvar==0)
6284  {
6285  WerrorS("ringvar/par expected");
6286  return TRUE;
6287  }
6288  }
6289  return FALSE;
6290 }
6292 {
6293  int ringvar;
6294  poly monomexpr;
6295  BOOLEAN nok=jjSUBST_Test(v,w,ringvar,monomexpr);
6296  if (nok) return TRUE;
6297  poly p=(poly)u->Data();
6298  if (ringvar>0)
6299  {
6300  if ((monomexpr!=NULL) && (p!=NULL) && (pTotaldegree(p)!=0) &&
6301  ((unsigned long)pTotaldegree(monomexpr) > (currRing->bitmask / (unsigned long)pTotaldegree(p)/2)))
6302  {
6303  Warn("possible OVERFLOW in subst, max exponent is %ld, substituting deg %d by deg %d",currRing->bitmask/2, pTotaldegree(monomexpr), pTotaldegree(p));
6304  //return TRUE;
6305  }
6306  if ((monomexpr==NULL)||(pNext(monomexpr)==NULL))
6307  res->data = pSubst((poly)u->CopyD(res->rtyp),ringvar,monomexpr);
6308  else
6309  res->data= pSubstPoly(p,ringvar,monomexpr);
6310  }
6311  else
6312  {
6313  res->data=pSubstPar(p,-ringvar,monomexpr);
6314  }
6315  return FALSE;
6316 }
6318 {
6319  int ringvar;
6320  poly monomexpr;
6321  BOOLEAN nok=jjSUBST_Test(v,w,ringvar,monomexpr);
6322  if (nok) return TRUE;
6323  ideal id=(ideal)u->Data();
6324  if (ringvar>0)
6325  {
6326  BOOLEAN overflow=FALSE;
6327  if (monomexpr!=NULL)
6328  {
6329  long deg_monexp=pTotaldegree(monomexpr);
6330  for(int i=IDELEMS(id)-1;i>=0;i--)
6331  {
6332  poly p=id->m[i];
6333  if ((p!=NULL) && (pTotaldegree(p)!=0) &&
6334  ((unsigned long)deg_monexp > (currRing->bitmask / (unsigned long)pTotaldegree(p)/2)))
6335  {
6336  overflow=TRUE;
6337  break;
6338  }
6339  }
6340  }
6341  if (overflow)
6342  Warn("possible OVERFLOW in subst, max exponent is %ld",currRing->bitmask/2);
6343  if ((monomexpr==NULL)||(pNext(monomexpr)==NULL))
6344  {
6345  if (res->rtyp==MATRIX_CMD) id=(ideal)mp_Copy((matrix)id,currRing);
6346  else id=id_Copy(id,currRing);
6347  res->data = id_Subst(id, ringvar, monomexpr, currRing);
6348  }
6349  else
6350  res->data = idSubstPoly(id,ringvar,monomexpr);
6351  }
6352  else
6353  {
6354  res->data = idSubstPar(id,-ringvar,monomexpr);
6355  }
6356  return FALSE;
6357 }
6358 // we do not want to have jjSUBST_Id_X inlined:
6359 static BOOLEAN jjSUBST_Id_X(leftv res, leftv u, leftv v,leftv w,
6360  int input_type);
6362 {
6363  return jjSUBST_Id_X(res,u,v,w,INT_CMD);
6364 }
6366 {
6367  return jjSUBST_Id_X(res,u,v,w,NUMBER_CMD);
6368 }
6369 static BOOLEAN jjSUBST_Id_X(leftv res, leftv u, leftv v,leftv w, int input_type)
6370 {
6371  sleftv tmp;
6372  memset(&tmp,0,sizeof(tmp));
6373  // do not check the result, conversion from int/number to poly works always
6374  iiConvert(input_type,POLY_CMD,iiTestConvert(input_type,POLY_CMD),w,&tmp);
6375  BOOLEAN b=jjSUBST_Id(res,u,v,&tmp);
6376  tmp.CleanUp();
6377  return b;
6378 }
6380 {
6381  int mi=(int)(long)v->Data();
6382  int ni=(int)(long)w->Data();
6383  if ((mi<1)||(ni<1))
6384  {
6385  Werror("converting ideal to matrix: dimensions must be positive(%dx%d)",mi,ni);
6386  return TRUE;
6387  }
6388  matrix m=mpNew(mi,ni);
6389  ideal I=(ideal)u->CopyD(IDEAL_CMD);
6390  int i=si_min(IDELEMS(I),mi*ni);
6391  //for(i=i-1;i>=0;i--)
6392  //{
6393  // m->m[i]=I->m[i];
6394  // I->m[i]=NULL;
6395  //}
6396  memcpy(m->m,I->m,i*sizeof(poly));
6397  memset(I->m,0,i*sizeof(poly));
6398  id_Delete(&I,currRing);
6399  res->data = (char *)m;
6400  return FALSE;
6401 }
6403 {
6404  int mi=(int)(long)v->Data();
6405  int ni=(int)(long)w->Data();
6406  if ((mi<1)||(ni<1))
6407  {
6408  Werror("converting module to matrix: dimensions must be positive(%dx%d)",mi,ni);
6409  return TRUE;
6410  }
6411  res->data = (char *)id_Module2formatedMatrix((ideal)u->CopyD(MODUL_CMD),
6412  mi,ni,currRing);
6413  return FALSE;
6414 }
6416 {
6417  int mi=(int)(long)v->Data();
6418  int ni=(int)(long)w->Data();
6419  if ((mi<1)||(ni<1))
6420  {
6421  Werror("converting matrix to matrix: dimensions must be positive(%dx%d)",mi,ni);
6422  return TRUE;
6423  }
6424  matrix m=mpNew(mi,ni);
6425  matrix I=(matrix)u->CopyD(MATRIX_CMD);
6426  int r=si_min(MATROWS(I),mi);
6427  int c=si_min(MATCOLS(I),ni);
6428  int i,j;
6429  for(i=r;i>0;i--)
6430  {
6431  for(j=c;j>0;j--)
6432  {
6433  MATELEM(m,i,j)=MATELEM(I,i,j);
6434  MATELEM(I,i,j)=NULL;
6435  }
6436  }
6437  id_Delete((ideal *)&I,currRing);
6438  res->data = (char *)m;
6439  return FALSE;
6440 }
6441 static BOOLEAN jjLIFT3(leftv res, leftv u, leftv v, leftv w)
6442 {
6443  if (w->rtyp!=IDHDL) return TRUE;
6444  int ul= IDELEMS((ideal)u->Data());
6445  int vl= IDELEMS((ideal)v->Data());
6446  ideal m
6447  = idLift((ideal)u->Data(),(ideal)v->Data(),NULL,FALSE,hasFlag(u,FLAG_STD),
6448  FALSE, (matrix *)(&(IDMATRIX((idhdl)(w->data)))));
6449  if (m==NULL) return TRUE;
6450  res->data = (char *)id_Module2formatedMatrix(m,ul,vl,currRing);
6451  return FALSE;
6452 }
6453 static BOOLEAN jjLIFTSTD3(leftv res, leftv u, leftv v, leftv w)
6454 {
6455  if ((v->rtyp!=IDHDL)||(v->e!=NULL)) return TRUE;
6456  if ((w->rtyp!=IDHDL)||(w->e!=NULL)) return TRUE;
6457  idhdl hv=(idhdl)v->data;
6458  idhdl hw=(idhdl)w->data;
6459  // CopyD for IDEAL_CMD and MODUL_CMD are identical:
6460  res->data = (char *)idLiftStd((ideal)u->Data(),
6461  &(hv->data.umatrix),testHomog,
6462  &(hw->data.uideal));
6463  setFlag(res,FLAG_STD); v->flag=0; w->flag=0;
6464  return FALSE;
6465 }
6467 {
6468  assumeStdFlag(v);
6469  if (!idIsZeroDim((ideal)v->Data()))
6470  {
6471  Werror("`%s` must be 0-dimensional",v->Name());
6472  return TRUE;
6473  }
6474  res->data = (char *)redNF((ideal)v->CopyD(),(poly)u->CopyD(),
6475  (poly)w->CopyD());
6476  return FALSE;
6477 }
6479 {
6480  assumeStdFlag(v);
6481  if (!idIsZeroDim((ideal)v->Data()))
6482  {
6483  Werror("`%s` must be 0-dimensional",v->Name());
6484  return TRUE;
6485  }
6486  res->data = (char *)redNF((ideal)v->CopyD(),(ideal)u->CopyD(),
6487  (matrix)w->CopyD());
6488  return FALSE;
6489 }
6491 {
6492  assumeStdFlag(v);
6493  res->data = (char *)kNF((ideal)v->Data(),currRing->qideal,(poly)u->Data(),
6494  0,(int)(long)w->Data());
6495  return FALSE;
6496 }
6498 {
6499  assumeStdFlag(v);
6500  res->data = (char *)kNF((ideal)v->Data(),currRing->qideal,(ideal)u->Data(),
6501  0,(int)(long)w->Data());
6502  return FALSE;
6503 }
6504 #ifdef OLD_RES
6505 static BOOLEAN jjRES3(leftv res, leftv u, leftv v, leftv w)
6506 {
6507  int maxl=(int)v->Data();
6508  ideal u_id=(ideal)u->Data();
6509  int l=0;
6510  resolvente r;
6511  intvec **weights=NULL;
6512  int wmaxl=maxl;
6513  maxl--;
6514  if ((maxl==-1) && (iiOp!=MRES_CMD))
6515  maxl = currRing->N-1;
6516  if ((iiOp == RES_CMD) || (iiOp == MRES_CMD))
6517  {
6518  intvec * iv=(intvec*)atGet(u,"isHomog",INTVEC_CMD);
6519  if (iv!=NULL)
6520  {
6521  l=1;
6522  if (!idTestHomModule(u_id,currRing->qideal,iv))
6523  {
6524  WarnS("wrong weights");
6525  iv=NULL;
6526  }
6527  else
6528  {
6529  weights = (intvec**)omAlloc0Bin(char_ptr_bin);
6530  weights[0] = ivCopy(iv);
6531  }
6532  }
6533  r=syResolvente(u_id,maxl,&l, &weights, iiOp==MRES_CMD);
6534  }
6535  else
6536  r=sySchreyerResolvente((ideal)u->Data(),maxl+1,&l);
6537  if (r==NULL) return TRUE;
6538  int t3=u->Typ();
6539  iiMakeResolv(r,l,wmaxl,w->name,t3,weights);
6540  return FALSE;
6541 }
6542 #endif
6543 static BOOLEAN jjRING3(leftv res, leftv u, leftv v, leftv w)
6544 {
6545  res->data=(void *)rInit(u,v,w);
6546  return (res->data==NULL);
6547 }
6548 static BOOLEAN jjSTATUS3(leftv res, leftv u, leftv v, leftv w)
6549 {
6550  int yes;
6551  jjSTATUS2(res, u, v);
6552  yes = (strcmp((char *) res->data, (char *) w->Data()) == 0);
6553  omFree((ADDRESS) res->data);
6554  res->data = (void *)(long)yes;
6555  return FALSE;
6556 }
6558 {
6559  intvec *vw=(intvec *)w->Data(); // weights of vars
6560  if (vw->length()!=currRing->N)
6561  {
6562  Werror("%d weights for %d variables",vw->length(),currRing->N);
6563  return TRUE;
6564  }
6565  ideal result;
6566  intvec *ww=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
6567  tHomog hom=testHomog;
6568  ideal u_id=(ideal)(u->Data());
6569  if (ww!=NULL)
6570  {
6571  if (!idTestHomModule(u_id,currRing->qideal,ww))
6572  {
6573  WarnS("wrong weights");
6574  ww=NULL;
6575  }
6576  else
6577  {
6578  ww=ivCopy(ww);
6579  hom=isHomog;
6580  }
6581  }
6582  result=kStd(u_id,
6583  currRing->qideal,
6584  hom,
6585  &ww, // module weights
6586  (intvec *)v->Data(), // hilbert series
6587  0,0, // syzComp, newIdeal
6588  vw); // weights of vars
6589  idSkipZeroes(result);
6590  res->data = (char *)result;
6591  setFlag(res,FLAG_STD);
6592  if (ww!=NULL) atSet(res,omStrDup("isHomog"),ww,INTVEC_CMD);
6593  return FALSE;
6594 }
6595 
6596 /*=================== operations with many arg.: static proc =================*/
6597 /* must be ordered: first operations for chars (infix ops),
6598  * then alphabetically */
6600 {
6601 #ifdef HAVE_SDB
6602  sdb_show_bp();
6603 #endif
6604  return FALSE;
6605 }
6607 {
6608 #ifdef HAVE_SDB
6609  if(v->Typ()==PROC_CMD)
6610  {
6611  int lineno=0;
6612  if((v->next!=NULL) && (v->next->Typ()==INT_CMD))
6613  {
6614  lineno=(int)(long)v->next->Data();
6615  }
6616  return sdb_set_breakpoint(v->Name(),lineno);
6617  }
6618  return TRUE;
6619 #else
6620  return FALSE;
6621 #endif
6622 }
6624 {
6625  return iiExprArith1(res,v,iiOp);
6626 }
6628 {
6629  leftv v=u->next;
6630  u->next=NULL;
6631  BOOLEAN b=iiExprArith2(res,u,iiOp,v, (iiOp > 255));
6632  u->next=v;
6633  return b;
6634 }
6636 {
6637  leftv v = u->next;
6638  leftv w = v->next;
6639  u->next = NULL;
6640  v->next = NULL;
6641  BOOLEAN b = iiExprArith3(res, iiOp, u, v, w);
6642  u->next = v;
6643  v->next = w;
6644  return b;
6645 }
6646 
6648 {
6650  if (iiCheckTypes(v,t))
6651  return TRUE;
6652  idhdl c=(idhdl)v->next->next->data;
6653  if (v->next->next->next->rtyp!=IDHDL) return TRUE;
6654  idhdl m=(idhdl)v->next->next->next->data;
6655  idDelete((ideal *)&(c->data.uideal));
6656  idDelete((ideal *)&(m->data.uideal));
6657  mp_Coef2((poly)v->Data(),(poly)v->next->Data(),
6658  (matrix *)&(c->data.umatrix),(matrix *)&(m->data.umatrix),currRing);
6659  return FALSE;
6660 }
6661 
6663 { // may have 3 or 4 arguments
6664  leftv v1=v;
6665  leftv v2=v1->next;
6666  leftv v3=v2->next;
6667  leftv v4=v3->next;
6668  assumeStdFlag(v2);
6669 
6670  int i1=iiTestConvert(v1->Typ(),MODUL_CMD);
6671  int i2=iiTestConvert(v2->Typ(),MODUL_CMD);
6672 
6673  if((i1==0)||(i2==0)
6674  ||(v3->Typ()!=INT_CMD)||((v4!=NULL)&&(v4->Typ()!=INTVEC_CMD)))
6675  {
6676  WarnS("<module>,<module>,<int>[,<intvec>] expected!");
6677  return TRUE;
6678  }
6679 
6680  sleftv w1,w2;
6681  iiConvert(v1->Typ(),MODUL_CMD,i1,v1,&w1);
6682  iiConvert(v2->Typ(),MODUL_CMD,i2,v2,&w2);
6683  ideal P=(ideal)w1.Data();
6684  ideal Q=(ideal)w2.Data();
6685 
6686  int n=(int)(long)v3->Data();
6687  short *w=NULL;
6688  if(v4!=NULL)
6689  {
6690  w = iv2array((intvec *)v4->Data(),currRing);
6691  short * w0 = w + 1;
6692  int i = currRing->N;
6693  while( (i > 0) && ((*w0) > 0) )
6694  {
6695  w0++;
6696  i--;
6697  }
6698  if(i>0)
6699  WarnS("not all weights are positive!");
6700  }
6701 
6702  matrix T;
6703  ideal R;
6704  idLiftW(P,Q,n,T,R,w);
6705 
6706  w1.CleanUp();
6707  w2.CleanUp();
6708  if(w!=NULL)
6709  omFreeSize( (ADDRESS)w, (rVar(currRing)+1)*sizeof(short) );
6710 
6712  L->Init(2);
6713  L->m[1].rtyp=v1->Typ();
6714  if(v1->Typ()==POLY_CMD||v1->Typ()==VECTOR_CMD)
6715  {
6716  if(v1->Typ()==POLY_CMD)
6717  p_Shift(&R->m[0],-1,currRing);
6718  L->m[1].data=(void *)R->m[0];
6719  R->m[0]=NULL;
6720  idDelete(&R);
6721  }
6722  else if(v1->Typ()==IDEAL_CMD||v1->Typ()==MATRIX_CMD)
6723  L->m[1].data=(void *)id_Module2Matrix(R,currRing);
6724  else
6725  {
6726  L->m[1].rtyp=MODUL_CMD;
6727  L->m[1].data=(void *)R;
6728  }
6729  L->m[0].rtyp=MATRIX_CMD;
6730  L->m[0].data=(char *)T;
6731 
6732  res->data=L;
6733  res->rtyp=LIST_CMD;
6734 
6735  return FALSE;
6736 }
6737 
6738 //BOOLEAN jjDISPATCH(leftv res, leftv v)
6739 //{
6740 // WerrorS("`dispatch`: not implemented");
6741 // return TRUE;
6742 //}
6743 
6744 //static BOOLEAN jjEXPORTTO_M(leftv res, leftv u)
6745 //{
6746 // int l=u->listLength();
6747 // if (l<2) return TRUE;
6748 // BOOLEAN b;
6749 // leftv v=u->next;
6750 // leftv zz=v;
6751 // leftv z=zz;
6752 // u->next=NULL;
6753 // do
6754 // {
6755 // leftv z=z->next;
6756 // b=iiExprArith2(res,u,iiOp,z, (iiOp > 255));
6757 // if (b) break;
6758 // } while (z!=NULL);
6759 // u->next=zz;
6760 // return b;
6761 //}
6763 {
6764  int s=1;
6765  leftv h=v;
6766  if (h!=NULL) s=exprlist_length(h);
6767  ideal id=idInit(s,1);
6768  int rank=1;
6769  int i=0;
6770  poly p;
6771  while (h!=NULL)
6772  {
6773  switch(h->Typ())
6774  {
6775  case POLY_CMD:
6776  {
6777  p=(poly)h->CopyD(POLY_CMD);
6778  break;
6779  }
6780  case INT_CMD:
6781  {
6782  number n=nInit((int)(long)h->Data());
6783  if (!nIsZero(n))
6784  {
6785  p=pNSet(n);
6786  }
6787  else
6788  {
6789  p=NULL;
6790  nDelete(&n);
6791  }
6792  break;
6793  }
6794  case BIGINT_CMD:
6795  {
6796  number b=(number)h->Data();
6798  if (nMap==NULL) return TRUE;
6799  number n=nMap(b,coeffs_BIGINT,currRing->cf);
6800  if (!nIsZero(n))
6801  {
6802  p=pNSet(n);
6803  }
6804  else
6805  {
6806  p=NULL;
6807  nDelete(&n);
6808  }
6809  break;
6810  }
6811  case NUMBER_CMD:
6812  {
6813  number n=(number)h->CopyD(NUMBER_CMD);
6814  if (!nIsZero(n))
6815  {
6816  p=pNSet(n);
6817  }
6818  else
6819  {
6820  p=NULL;
6821  nDelete(&n);
6822  }
6823  break;
6824  }
6825  case VECTOR_CMD:
6826  {
6827  p=(poly)h->CopyD(VECTOR_CMD);
6828  if (iiOp!=MODUL_CMD)
6829  {
6830  idDelete(&id);
6831  pDelete(&p);
6832  return TRUE;
6833  }
6834  rank=si_max(rank,(int)pMaxComp(p));
6835  break;
6836  }
6837  default:
6838  {
6839  idDelete(&id);
6840  return TRUE;
6841  }
6842  }
6843  if ((iiOp==MODUL_CMD)&&(p!=NULL)&&(pGetComp(p)==0))
6844  {
6845  pSetCompP(p,1);
6846  }
6847  id->m[i]=p;
6848  i++;
6849  h=h->next;
6850  }
6851  id->rank=rank;
6852  res->data=(char *)id;
6853  return FALSE;
6854 }
6856 {
6857  ring r=(ring)u->Data();
6858  leftv v=u->next;
6859  leftv perm_var_l=v->next;
6860  leftv perm_par_l=v->next->next;
6861  if ((perm_var_l->Typ()!=INTVEC_CMD)
6862  ||((perm_par_l!=NULL)&&(perm_par_l->Typ()!=INTVEC_CMD))
6863  ||(u->Typ()!=RING_CMD))
6864  {
6865  WerrorS("fetch(<ring>,<name>[,<intvec>[,<intvec>])");
6866  return TRUE;
6867  }
6868  intvec *perm_var_v=(intvec*)perm_var_l->Data();
6869  intvec *perm_par_v=NULL;
6870  if (perm_par_l!=NULL)
6871  perm_par_v=(intvec*)perm_par_l->Data();
6872  idhdl w;
6873  nMapFunc nMap;
6874 
6875  if ((w=r->idroot->get(v->Name(),myynest))!=NULL)
6876  {
6877  int *perm=NULL;
6878  int *par_perm=NULL;
6879  int par_perm_size=0;
6880  BOOLEAN bo;
6881  if ((nMap=n_SetMap(r->cf,currRing->cf))==NULL)
6882  {
6883  // Allow imap/fetch to be make an exception only for:
6884  if ( (rField_is_Q_a(r) && // Q(a..) -> Q(a..) || Q || Zp || Zp(a)
6887  ||
6888  (rField_is_Zp_a(r) && // Zp(a..) -> Zp(a..) || Zp
6889  (rField_is_Zp(currRing, r->cf->ch) ||
6890  rField_is_Zp_a(currRing, r->cf->ch))) )
6891  {
6892  par_perm_size=rPar(r);
6893  }
6894  else
6895  {
6896  goto err_fetch;
6897  }
6898  }
6899  else
6900  par_perm_size=rPar(r);
6901  perm=(int *)omAlloc0((rVar(r)+1)*sizeof(int));
6902  if (par_perm_size!=0)
6903  par_perm=(int *)omAlloc0(par_perm_size*sizeof(int));
6904  int i;
6905  if (perm_par_l==NULL)
6906  {
6907  if (par_perm_size!=0)
6908  for(i=si_min(rPar(r),rPar(currRing))-1;i>=0;i--) par_perm[i]=-(i+1);
6909  }
6910  else
6911  {
6912  if (par_perm_size==0) WarnS("source ring has no parameters");
6913  else
6914  {
6915  for(i=rPar(r)-1;i>=0;i--)
6916  {
6917  if (i<perm_par_v->length()) par_perm[i]=(*perm_par_v)[i];
6918  if ((par_perm[i]<-rPar(currRing))
6919  || (par_perm[i]>rVar(currRing)))
6920  {
6921  Warn("invalid entry for par %d: %d\n",i,par_perm[i]);
6922  par_perm[i]=0;
6923  }
6924  }
6925  }
6926  }
6927  for(i=rVar(r)-1;i>=0;i--)
6928  {
6929  if (i<perm_var_v->length()) perm[i+1]=(*perm_var_v)[i];
6930  if ((perm[i]<-rPar(currRing))
6931  || (perm[i]>rVar(currRing)))
6932  {
6933  Warn("invalid entry for var %d: %d\n",i,perm[i]);
6934  perm[i]=0;
6935  }
6936  }
6937  if (BVERBOSE(V_IMAP))
6938  {
6939  for(i=1;i<=si_min(rVar(r),rVar(currRing));i++)
6940  {
6941  if (perm[i]>0)
6942  Print("// var nr %d: %s -> var %s\n",i,r->names[i-1],currRing->names[perm[i]-1]);
6943  else if (perm[i]<0)
6944  Print("// var nr %d: %s -> par %s\n",i,r->names[i-1],rParameter(currRing)[-perm[i]-1]);
6945  }
6946  for(i=1;i<=si_min(rPar(r),rPar(currRing));i++) // possibly empty loop
6947  {
6948  if (par_perm[i-1]<0)
6949  Print("// par nr %d: %s -> par %s\n",
6950  i,rParameter(r)[i-1],rParameter(currRing)[-par_perm[i-1]-1]);
6951  else if (par_perm[i-1]>0)
6952  Print("// par nr %d: %s -> var %s\n",
6953  i,rParameter(r)[i-1],currRing->names[par_perm[i-1]-1]);
6954  }
6955  }
6956  if (IDTYP(w)==ALIAS_CMD) w=(idhdl)IDDATA(w);
6957  sleftv tmpW;
6958  memset(&tmpW,0,sizeof(sleftv));
6959  tmpW.rtyp=IDTYP(w);
6960  tmpW.data=IDDATA(w);
6961  if ((bo=maApplyFetch(IMAP_CMD,NULL,res,&tmpW, r,
6962  perm,par_perm,par_perm_size,nMap)))
6963  {
6964  Werror("cannot map %s of type %s(%d)",v->name, Tok2Cmdname(w->typ),w->typ);
6965  }
6966  if (perm!=NULL)
6967  omFreeSize((ADDRESS)perm,(rVar(r)+1)*sizeof(int));
6968  if (par_perm!=NULL)
6969  omFreeSize((ADDRESS)par_perm,par_perm_size*sizeof(int));
6970  return bo;
6971  }
6972  else
6973  {
6974  Werror("identifier %s not found in %s",v->Fullname(),u->Fullname());
6975  }
6976  return TRUE;
6977 err_fetch:
6978  Werror("no identity map from %s (%s -> %s)",u->Fullname(),
6979  nCoeffString(r->cf),
6980  nCoeffString(currRing->cf));
6981  return TRUE;
6982 }
6984 {
6985  leftv h=v;
6986  int l=v->listLength();
6987  resolvente r=(resolvente)omAlloc0(l*sizeof(ideal));
6988  BOOLEAN *copied=(BOOLEAN *)omAlloc0(l*sizeof(BOOLEAN));
6989  int t=0;
6990  // try to convert to IDEAL_CMD
6991  while (h!=NULL)
6992  {
6993  if (iiTestConvert(h->Typ(),IDEAL_CMD)!=0)
6994  {
6995  t=IDEAL_CMD;
6996  }
6997  else break;
6998  h=h->next;
6999  }
7000  // if failure, try MODUL_CMD
7001  if (t==0)
7002  {
7003  h=v;
7004  while (h!=NULL)
7005  {
7006  if (iiTestConvert(h->Typ(),MODUL_CMD)!=0)
7007  {
7008  t=MODUL_CMD;
7009  }
7010  else break;
7011  h=h->next;
7012  }
7013  }
7014  // check for success in converting
7015  if (t==0)
7016  {
7017  WerrorS("cannot convert to ideal or module");
7018  return TRUE;
7019  }
7020  // call idMultSect
7021  h=v;
7022  int i=0;
7023  sleftv tmp;
7024  while (h!=NULL)
7025  {
7026  if (h->Typ()==t)
7027  {
7028  r[i]=(ideal)h->Data(); /*no copy*/
7029  h=h->next;
7030  }
7031  else if(iiConvert(h->Typ(),t,iiTestConvert(h->Typ(),t),h,&tmp))
7032  {
7033  omFreeSize((ADDRESS)copied,l*sizeof(BOOLEAN));
7034  omFreeSize((ADDRESS)r,l*sizeof(ideal));
7035  Werror("cannot convert arg. %d to %s",i+1,Tok2Cmdname(t));
7036  return TRUE;
7037  }
7038  else
7039  {
7040  r[i]=(ideal)tmp.Data(); /*now it's a copy*/
7041  copied[i]=TRUE;
7042  h=tmp.next;
7043  }
7044  i++;
7045  }
7046  res->rtyp=t;
7047  res->data=(char *)idMultSect(r,i);
7048  while(i>0)
7049  {
7050  i--;
7051  if (copied[i]) idDelete(&(r[i]));
7052  }
7053  omFreeSize((ADDRESS)copied,l*sizeof(BOOLEAN));
7054  omFreeSize((ADDRESS)r,l*sizeof(ideal));
7055  return FALSE;
7056 }
7058 {
7059  /* computation of the inverse of a quadratic matrix A
7060  using the L-U-decomposition of A;
7061  There are two valid parametrisations:
7062  1) exactly one argument which is just the matrix A,
7063  2) exactly three arguments P, L, U which already
7064  realise the L-U-decomposition of A, that is,
7065  P * A = L * U, and P, L, and U satisfy the
7066  properties decribed in method 'jjLU_DECOMP';
7067  see there;
7068  If A is invertible, the list [1, A^(-1)] is returned,
7069  otherwise the list [0] is returned. Thus, the user may
7070  inspect the first entry of the returned list to see
7071  whether A is invertible. */
7072  matrix iMat; int invertible;
7073  short t1[]={1,MATRIX_CMD};
7074  short t2[]={3,MATRIX_CMD,MATRIX_CMD,MATRIX_CMD};
7075  if (iiCheckTypes(v,t1))
7076  {
7077  matrix aMat = (matrix)v->Data();
7078  int rr = aMat->rows();
7079  int cc = aMat->cols();
7080  if (rr != cc)
7081  {
7082  Werror("given matrix (%d x %d) is not quadratic, hence not invertible", rr, cc);
7083  return TRUE;
7084  }
7085  if (!idIsConstant((ideal)aMat))
7086  {
7087  WerrorS("matrix must be constant");
7088  return TRUE;
7089  }
7090  invertible = luInverse(aMat, iMat);
7091  }
7092  else if (iiCheckTypes(v,t2))
7093  {
7094  matrix pMat = (matrix)v->Data();
7095  matrix lMat = (matrix)v->next->Data();
7096  matrix uMat = (matrix)v->next->next->Data();
7097  int rr = uMat->rows();
7098  int cc = uMat->cols();
7099  if (rr != cc)
7100  {
7101  Werror("third matrix (%d x %d) is not quadratic, hence not invertible",
7102  rr, cc);
7103  return TRUE;
7104  }
7105  if (!idIsConstant((ideal)pMat)
7106  || (!idIsConstant((ideal)lMat))
7107  || (!idIsConstant((ideal)uMat))
7108  )
7109  {
7110  WerrorS("matricesx must be constant");
7111  return TRUE;
7112  }
7113  invertible = luInverseFromLUDecomp(pMat, lMat, uMat, iMat);
7114  }
7115  else
7116  {
7117  Werror("expected either one or three matrices");
7118  return TRUE;
7119  }
7120 
7121  /* build the return structure; a list with either one or two entries */
7123  if (invertible)
7124  {
7125  ll->Init(2);
7126  ll->m[0].rtyp=INT_CMD; ll->m[0].data=(void *)(long)invertible;
7127  ll->m[1].rtyp=MATRIX_CMD; ll->m[1].data=(void *)iMat;
7128  }
7129  else
7130  {
7131  ll->Init(1);
7132  ll->m[0].rtyp=INT_CMD; ll->m[0].data=(void *)(long)invertible;
7133  }
7134 
7135  res->data=(char*)ll;
7136  return FALSE;
7137 }
7139 {
7140  /* for solving a linear equation system A * x = b, via the
7141  given LU-decomposition of the matrix A;
7142  There is one valid parametrisation:
7143  1) exactly four arguments P, L, U, b;
7144  P, L, and U realise the L-U-decomposition of A, that is,
7145  P * A = L * U, and P, L, and U satisfy the
7146  properties decribed in method 'jjLU_DECOMP';
7147  see there;
7148  b is the right-hand side vector of the equation system;
7149  The method will return a list of either 1 entry or three entries:
7150  1) [0] if there is no solution to the system;
7151  2) [1, x, H] if there is at least one solution;
7152  x is any solution of the given linear system,
7153  H is the matrix with column vectors spanning the homogeneous
7154  solution space.
7155  The method produces an error if matrix and vector sizes do not fit. */
7156  short t[]={4,MATRIX_CMD,MATRIX_CMD,MATRIX_CMD,MATRIX_CMD};
7157  if (!iiCheckTypes(v,t))
7158  {
7159  WerrorS("expected exactly three matrices and one vector as input");
7160  return TRUE;
7161  }
7162  matrix pMat = (matrix)v->Data();
7163  matrix lMat = (matrix)v->next->Data();
7164  matrix uMat = (matrix)v->next->next->Data();
7165  matrix bVec = (matrix)v->next->next->next->Data();
7166  matrix xVec; int solvable; matrix homogSolSpace;
7167  if (pMat->rows() != pMat->cols())
7168  {
7169  Werror("first matrix (%d x %d) is not quadratic",
7170  pMat->rows(), pMat->cols());
7171  return TRUE;
7172  }
7173  if (lMat->rows() != lMat->cols())
7174  {
7175  Werror("second matrix (%d x %d) is not quadratic",
7176  lMat->rows(), lMat->cols());
7177  return TRUE;
7178  }
7179  if (lMat->rows() != uMat->rows())
7180  {
7181  Werror("second matrix (%d x %d) and third matrix (%d x %d) do not fit",
7182  lMat->rows(), lMat->cols(), uMat->rows(), uMat->cols());
7183  return TRUE;
7184  }
7185  if (uMat->rows() != bVec->rows())
7186  {
7187  Werror("third matrix (%d x %d) and vector (%d x 1) do not fit",
7188  uMat->rows(), uMat->cols(), bVec->rows());
7189  return TRUE;
7190  }
7191  if (!idIsConstant((ideal)pMat)
7192  ||(!idIsConstant((ideal)lMat))
7193  ||(!idIsConstant((ideal)uMat))
7194  )
7195  {
7196  WerrorS("matrices must be constant");
7197  return TRUE;
7198  }
7199  solvable = luSolveViaLUDecomp(pMat, lMat, uMat, bVec, xVec, homogSolSpace);
7200 
7201  /* build the return structure; a list with either one or three entries */
7203  if (solvable)
7204  {
7205  ll->Init(3);
7206  ll->m[0].rtyp=INT_CMD; ll->m[0].data=(void *)(long)solvable;
7207  ll->m[1].rtyp=MATRIX_CMD; ll->m[1].data=(void *)xVec;
7208  ll->m[2].rtyp=MATRIX_CMD; ll->m[2].data=(void *)homogSolSpace;
7209  }
7210  else
7211  {
7212  ll->Init(1);
7213  ll->m[0].rtyp=INT_CMD; ll->m[0].data=(void *)(long)solvable;
7214  }
7215 
7216  res->data=(char*)ll;
7217  return FALSE;
7218 }
7220 {
7221  int i=0;
7222  leftv h=v;
7223  if (h!=NULL) i=exprlist_length(h);
7224  intvec *iv=new intvec(i);
7225  i=0;
7226  while (h!=NULL)
7227  {
7228  if(h->Typ()==INT_CMD)
7229  {
7230  (*iv)[i]=(int)(long)h->Data();
7231  }
7232  else if (h->Typ()==INTVEC_CMD)
7233  {
7234  intvec *ivv=(intvec*)h->Data();
7235  for(int j=0;j<ivv->length();j++,i++)
7236  {
7237  (*iv)[i]=(*ivv)[j];
7238  }
7239  i--;
7240  }
7241  else
7242  {
7243  delete iv;
7244  return TRUE;
7245  }
7246  i++;
7247  h=h->next;
7248  }
7249  res->data=(char *)iv;
7250  return FALSE;
7251 }
7252 static BOOLEAN jjJET4(leftv res, leftv u)
7253 {
7254  short t1[]={4,POLY_CMD,POLY_CMD,POLY_CMD,INTVEC_CMD};
7255  short t2[]={4,VECTOR_CMD,POLY_CMD,POLY_CMD,INTVEC_CMD};
7256  short t3[]={4,IDEAL_CMD,MATRIX_CMD,INT_CMD,INTVEC_CMD};
7257  short t4[]={4,MODUL_CMD,MATRIX_CMD,INT_CMD,INTVEC_CMD};
7258  leftv u1=u;
7259  leftv u2=u1->next;
7260  leftv u3=u2->next;
7261  leftv u4=u3->next;
7262  if (iiCheckTypes(u,t1)||iiCheckTypes(u,t2))
7263  {
7264  if(!pIsUnit((poly)u2->Data()))
7265  {
7266  WerrorS("2nd argument must be a unit");
7267  return TRUE;
7268  }
7269  res->rtyp=u1->Typ();
7270  res->data=(char*)pSeries((int)(long)u3->Data(),pCopy((poly)u1->Data()),
7271  pCopy((poly)u2->Data()),(intvec*)u4->Data());
7272  return FALSE;
7273  }
7274  else
7275  if (iiCheckTypes(u,t3)||iiCheckTypes(u,t4))
7276  {
7277  if(!mp_IsDiagUnit((matrix)u2->Data(), currRing))
7278  {
7279  WerrorS("2nd argument must be a diagonal matrix of units");
7280  return TRUE;
7281  }
7282  res->rtyp=u1->Typ();
7283  res->data=(char*)idSeries(
7284  (int)(long)u3->Data(),
7285  idCopy((ideal)u1->Data()),
7286  mp_Copy((matrix)u2->Data(), currRing),
7287  (intvec*)u4->Data()
7288  );
7289  return FALSE;
7290  }
7291  else
7292  {
7293  Werror("%s(`poly`,`poly`,`int`,`intvec`) exppected",
7294  Tok2Cmdname(iiOp));
7295  return TRUE;
7296  }
7297 }
7298 #if 0
7299 static BOOLEAN jjBRACKET_PL(leftv res, leftv u)
7300 {
7301  int ut=u->Typ();
7302  leftv v=u->next; u->next=NULL;
7303  leftv w=v->next; v->next=NULL;
7304  if ((ut!=CRING_CMD)&&(ut!=RING_CMD))
7305  {
7306  BOOLEAN bo=TRUE;
7307  if (w==NULL)
7308  {
7309  bo=iiExprArith2(res,u,'[',v);
7310  }
7311  else if (w->next==NULL)
7312  {
7313  bo=iiExprArith3(res,'[',u,v,w);
7314  }
7315  v->next=w;
7316  u->next=v;
7317  return bo;
7318  }
7319  v->next=w;
7320  u->next=v;
7321  #ifdef SINGULAR_4_1
7322  // construct new rings:
7323  while (u!=NULL)
7324  {
7325  Print("name: %s,\n",u->Name());
7326  u=u->next;
7327  }
7328  #else
7329  memset(res,0,sizeof(sleftv));
7330  res->rtyp=NONE;
7331  return TRUE;
7332  #endif
7333 }
7334 #endif
7336 {
7337  if ((yyInRingConstruction)
7338  && ((strcmp(u->Name(),"real")==0) || (strcmp(u->Name(),"complex")==0)))
7339  {
7340  memcpy(res,u,sizeof(sleftv));
7341  memset(u,0,sizeof(sleftv));
7342  return FALSE;
7343  }
7344  leftv v=u->next;
7345  BOOLEAN b;
7346  if(v==NULL) // p()
7347  b=iiExprArith1(res,u,iiOp);
7348  else if ((v->next==NULL) // p(1)
7349  || (u->Typ()!=UNKNOWN)) // p(1,2), p proc or map
7350  {
7351  u->next=NULL;
7352  b=iiExprArith2(res,u,iiOp,v);
7353  u->next=v;
7354  }
7355  else // p(1,2), p undefined
7356  {
7357  if (v->Typ()!=INT_CMD)
7358  {
7359  Werror("`int` expected while building `%s(`",u->name);
7360  return TRUE;
7361  }
7362  int l=u->listLength();
7363  char * nn = (char *)omAlloc(strlen(u->name) + 12*l);
7364  sprintf(nn,"%s(%d",u->name,(int)(long)v->Data());
7365  char *s=nn;
7366  do
7367  {
7368  while (*s!='\0') s++;
7369  v=v->next;
7370  if (v->Typ()!=INT_CMD)
7371  {
7372  Werror("`int` expected while building `%s`",nn);
7373  omFree((ADDRESS)nn);
7374  return TRUE;
7375  }
7376  sprintf(s,",%d",(int)(long)v->Data());
7377  } while (v->next!=NULL);
7378  while (*s!='\0') s++;
7379  nn=strcat(nn,")");
7380  char *n=omStrDup(nn);
7381  omFree((ADDRESS)nn);
7382  syMake(res,n);
7383  b=FALSE;
7384  }
7385  return b;
7386 }
7388 {
7389  int sl=0;
7390  if (v!=NULL) sl = v->listLength();
7391  lists L;
7392  if((sl==1)&&(v->Typ()==RESOLUTION_CMD))
7393  {
7394  int add_row_shift = 0;
7395  intvec *weights=(intvec*)atGet(v,"isHomog",INTVEC_CMD);
7396  if (weights!=NULL) add_row_shift=weights->min_in();
7397  L=syConvRes((syStrategy)v->Data(),FALSE,add_row_shift);
7398  }
7399  else
7400  {
7402  leftv h=NULL;
7403  int i;
7404  int rt;
7405 
7406  L->Init(sl);
7407  for (i=0;i<sl;i++)
7408  {
7409  if (h!=NULL)
7410  { /* e.g. not in the first step:
7411  * h is the pointer to the old sleftv,
7412  * v is the pointer to the next sleftv
7413  * (in this moment) */
7414  h->next=v;
7415  }
7416  h=v;
7417  v=v->next;
7418  h->next=NULL;
7419  rt=h->Typ();
7420  if (rt==0)
7421  {
7422  L->Clean();
7423  Werror("`%s` is undefined",h->Fullname());
7424  return TRUE;
7425  }
7426  if (rt==RING_CMD)
7427  {
7428  L->m[i].rtyp=rt; L->m[i].data=h->Data();
7429  ((ring)L->m[i].data)->ref++;
7430  }
7431  else
7432  L->m[i].Copy(h);
7433  }
7434  }
7435  res->data=(char *)L;
7436  return FALSE;
7437 }
7439 {
7440  res->data=(void *)ipNameList(IDROOT);
7441  return FALSE;
7442 }
7444 {
7445  if(v==NULL)
7446  {
7447  res->data=(char *)showOption();
7448  return FALSE;
7449  }
7450  res->rtyp=NONE;
7451  return setOption(res,v);
7452 }
7454 {
7455  leftv u1=u;
7456  leftv u2=u1->next;
7457  leftv u3=u2->next;
7458  leftv u4=u3->next;
7459  if((u3->Typ()==INT_CMD)&&(u4->Typ()==INTVEC_CMD))
7460  {
7461  int save_d=Kstd1_deg;
7462  Kstd1_deg=(int)(long)u3->Data();
7463  kModW=(intvec *)u4->Data();
7464  BITSET save2;
7465  SI_SAVE_OPT2(save2);
7467  u2->next=NULL;
7468  BOOLEAN r=jjCALL2ARG(res,u);
7469  kModW=NULL;
7470  Kstd1_deg=save_d;
7471  SI_RESTORE_OPT2(save2);
7472  u->next->next=u3;
7473  return r;
7474  }
7475  else
7476  if((u1->Typ()==IDEAL_CMD)&&(u2->Typ()==MATRIX_CMD)&&(u3->Typ()==IDEAL_CMD)&&
7477  (u4->Typ()==INT_CMD))
7478  {
7479  assumeStdFlag(u3);
7480  if(!mp_IsDiagUnit((matrix)u2->Data(), currRing))
7481  {
7482  WerrorS("2nd argument must be a diagonal matrix of units");
7483  return TRUE;
7484  }
7485  res->rtyp=IDEAL_CMD;
7486  res->data=(char*)redNF(
7487  idCopy((ideal)u3->Data()),
7488  idCopy((ideal)u1->Data()),
7489  mp_Copy((matrix)u2->Data(), currRing),
7490  (int)(long)u4->Data()
7491  );
7492  return FALSE;
7493  }
7494  else
7495  if((u1->Typ()==POLY_CMD)&&(u2->Typ()==POLY_CMD)&&(u3->Typ()==IDEAL_CMD)&&
7496  (u4->Typ()==INT_CMD))
7497  {
7498  assumeStdFlag(u3);
7499  if(!pIsUnit((poly)u2->Data()))
7500  {
7501  WerrorS("2nd argument must be a unit");
7502  return TRUE;
7503  }
7504  res->rtyp=POLY_CMD;
7505  res->data=(char*)redNF(idCopy((ideal)u3->Data()),pCopy((poly)u1->Data()),
7506  pCopy((poly)u2->Data()),(int)(long)u4->Data());
7507  return FALSE;
7508  }
7509  else
7510  {
7511  Werror("%s(`poly`,`ideal`,`int`,`intvec`) expected",Tok2Cmdname(iiOp));
7512  Werror("%s(`ideal`,`matrix`,`ideal`,`int`) expected",Tok2Cmdname(iiOp));
7513  Werror("%s(`poly`,`poly`,`ideal`,`int`) expected",Tok2Cmdname(iiOp));
7514  return TRUE;
7515  }
7516 }
7518 {
7519  leftv u1=u;
7520  leftv u2=u1->next;
7521  leftv u3=u2->next;
7522  leftv u4=u3->next;
7523  leftv u5=u4->next;
7524  if((u1->Typ()==IDEAL_CMD)&&(u2->Typ()==MATRIX_CMD)&&(u3->Typ()==IDEAL_CMD)&&
7525  (u4->Typ()==INT_CMD)&&(u5->Typ()==INTVEC_CMD))
7526  {
7527  assumeStdFlag(u3);
7528  if(!mp_IsDiagUnit((matrix)u2->Data(), currRing))
7529  {
7530  WerrorS("2nd argument must be a diagonal matrix of units");
7531  return TRUE;
7532  }
7533  res->rtyp=IDEAL_CMD;
7534  res->data=(char*)redNF(
7535  idCopy((ideal)u3->Data()),
7536  idCopy((ideal)u1->Data()),
7537  mp_Copy((matrix)u2->Data(),currRing),
7538  (int)(long)u4->Data(),
7539  (intvec*)u5->Data()
7540  );
7541  return FALSE;
7542  }
7543  else
7544  if((u1->Typ()==POLY_CMD)&&(u2->Typ()==POLY_CMD)&&(u3->Typ()==IDEAL_CMD)&&
7545  (u4->Typ()==INT_CMD)&&(u5->Typ()==INTVEC_CMD))
7546  {
7547  assumeStdFlag(u3);
7548  if(!pIsUnit((poly)u2->Data()))
7549  {
7550  WerrorS("2nd argument must be a unit");
7551  return TRUE;
7552  }
7553  res->rtyp=POLY_CMD;
7554  res->data=(char*)redNF(idCopy((ideal)u3->Data()),pCopy((poly)u1->Data()),
7555  pCopy((poly)u2->Data()),
7556  (int)(long)u4->Data(),(intvec*)u5->Data());
7557  return FALSE;
7558  }
7559  else
7560  {
7561  Werror("%s(`ideal`,`ideal`,`matrix`,`int`,`intvec`) exppected",
7562  Tok2Cmdname(iiOp));
7563  return TRUE;
7564  }
7565 }
7567 {
7568  unsigned i=1;
7569  unsigned nCount = (sArithBase.nCmdUsed-1)/3;
7570  if((3*nCount)<sArithBase.nCmdUsed) nCount++;
7571  //Print("CMDS: %d/%d\n", sArithBase.nCmdUsed,
7572  // sArithBase.nCmdAllocated);
7573  for(i=0; i<nCount; i++)
7574  {
7575  Print("%-20s",sArithBase.sCmds[i+1].name);
7576  if(i+1+nCount<sArithBase.nCmdUsed)
7577  Print("%-20s",sArithBase.sCmds[i+1+nCount].name);
7578  if(i+1+2*nCount<sArithBase.nCmdUsed)
7579  Print("%-20s",sArithBase.sCmds[i+1+2*nCount].name);
7580  //if ((i%3)==1) PrintLn();
7581  PrintLn();
7582  }
7583  PrintLn();
7585  return FALSE;
7586 }
7588 {
7589  if (v == NULL)
7590  {
7591  res->data = omStrDup("");
7592  return FALSE;
7593  }
7594  int n = v->listLength();
7595  if (n == 1)
7596  {
7597  res->data = v->String();
7598  return FALSE;
7599  }
7600 
7601  char** slist = (char**) omAlloc(n*sizeof(char*));
7602  int i, j;
7603 
7604  for (i=0, j=0; i<n; i++, v = v ->next)
7605  {
7606  slist[i] = v->String();
7607  assume(slist[i] != NULL);
7608  j+=strlen(slist[i]);
7609  }
7610  char* s = (char*) omAlloc((j+1)*sizeof(char));
7611  *s='\0';
7612  for (i=0;i<n;i++)
7613  {
7614  strcat(s, slist[i]);
7615  omFree(slist[i]);
7616  }
7617  omFreeSize(slist, n*sizeof(char*));
7618  res->data = s;
7619  return FALSE;
7620 }
7622 {
7623  do
7624  {
7625  if (v->Typ()!=INT_CMD)
7626  return TRUE;
7627  test_cmd((int)(long)v->Data());
7628  v=v->next;
7629  }
7630  while (v!=NULL);
7631  return FALSE;
7632 }
7633 
7634 #if defined(__alpha) && !defined(linux)
7635 extern "C"
7636 {
7637  void usleep(unsigned long usec);
7638 };
7639 #endif
7641 {
7642  /* compute two factors of h(x,y) modulo x^(d+1) in K[[x]][y],
7643  see a detailed documentation in /kernel/linear_algebra/linearAlgebra.h
7644 
7645  valid argument lists:
7646  - (poly h, int d),
7647  - (poly h, int d, poly f0, poly g0), optional: factors of h(0,y),
7648  - (poly h, int d, int xIndex, int yIndex), optional: indices of vars x & y
7649  in list of ring vars,
7650  - (poly h, int d, poly f0, poly g0, int xIndex, int yIndec),
7651  optional: all 4 optional args
7652  (The defaults are xIndex = 1, yIndex = 2, f0 and g0 polynomials as found
7653  by singclap_factorize and h(0, y)
7654  has exactly two distinct monic factors [possibly with exponent > 1].)
7655  result:
7656  - list with the two factors f and g such that
7657  h(x,y) = f(x,y)*g(x,y) mod x^(d+1) */
7658 
7659  poly h = NULL;
7660  int d = 1;
7661  poly f0 = NULL;
7662  poly g0 = NULL;
7663  int xIndex = 1; /* default index if none provided */
7664  int yIndex = 2; /* default index if none provided */
7665 
7666  leftv u = v; int factorsGiven = 0;
7667  if ((u == NULL) || (u->Typ() != POLY_CMD))
7668  {
7669  WerrorS("expected arguments (poly, int [, poly, poly] [, int, int])");
7670  return TRUE;
7671  }
7672  else h = (poly)u->Data();
7673  u = u->next;
7674  if ((u == NULL) || (u->Typ() != INT_CMD))
7675  {
7676  WerrorS("expected arguments (poly, int [, poly, poly] [, int, int])");
7677  return TRUE;
7678  }
7679  else d = (int)(long)u->Data();
7680  u = u->next;
7681  if ((u != NULL) && (u->Typ() == POLY_CMD))
7682  {
7683  if ((u->next == NULL) || (u->next->Typ() != POLY_CMD))
7684  {
7685  WerrorS("expected arguments (poly, int [, poly, poly] [, int, int])");
7686  return TRUE;
7687  }
7688  else
7689  {
7690  f0 = (poly)u->Data();
7691  g0 = (poly)u->next->Data();
7692  factorsGiven = 1;
7693  u = u->next->next;
7694  }
7695  }
7696  if ((u != NULL) && (u->Typ() == INT_CMD))
7697  {
7698  if ((u->next == NULL) || (u->next->Typ() != INT_CMD))
7699  {
7700  WerrorS("expected arguments (poly, int [, poly, poly] [, int, int])");
7701  return TRUE;
7702  }
7703  else
7704  {
7705  xIndex = (int)(long)u->Data();
7706  yIndex = (int)(long)u->next->Data();
7707  u = u->next->next;
7708  }
7709  }
7710  if (u != NULL)
7711  {
7712  WerrorS("expected arguments (poly, int [, poly, poly] [, int, int])");
7713  return TRUE;
7714  }
7715 
7716  /* checks for provided arguments */
7717  if (pIsConstant(h) || (factorsGiven && (pIsConstant(f0) || pIsConstant(g0))))
7718  {
7719  WerrorS("expected non-constant polynomial argument(s)");
7720  return TRUE;
7721  }
7722  int n = rVar(currRing);
7723  if ((xIndex < 1) || (n < xIndex))
7724  {
7725  Werror("index for variable x (%d) out of range [1..%d]", xIndex, n);
7726  return TRUE;
7727  }
7728  if ((yIndex < 1) || (n < yIndex))
7729  {
7730  Werror("index for variable y (%d) out of range [1..%d]", yIndex, n);
7731  return TRUE;
7732  }
7733  if (xIndex == yIndex)
7734  {
7735  WerrorS("expected distinct indices for variables x and y");
7736  return TRUE;
7737  }
7738 
7739  /* computation of f0 and g0 if missing */
7740  if (factorsGiven == 0)
7741  {
7742  poly h0 = pSubst(pCopy(h), xIndex, NULL);
7743  intvec* v = NULL;
7744  ideal i = singclap_factorize(h0, &v, 0,currRing);
7745 
7746  ivTest(v);
7747 
7748  if (i == NULL) return TRUE;
7749 
7750  idTest(i);
7751 
7752  if ((v->rows() != 3) || ((*v)[0] =! 1) || (!nIsOne(pGetCoeff(i->m[0]))))
7753  {
7754  WerrorS("expected h(0,y) to have exactly two distinct monic factors");
7755  return TRUE;
7756  }
7757  f0 = pPower(pCopy(i->m[1]), (*v)[1]);
7758  g0 = pPower(pCopy(i->m[2]), (*v)[2]);
7759  idDelete(&i);
7760  }
7761 
7762  poly f; poly g;
7763  henselFactors(xIndex, yIndex, h, f0, g0, d, f, g);
7765  L->Init(2);
7766  L->m[0].rtyp = POLY_CMD; L->m[0].data=(void*)f;
7767  L->m[1].rtyp = POLY_CMD; L->m[1].data=(void*)g;
7768  res->rtyp = LIST_CMD;
7769  res->data = (char*)L;
7770  return FALSE;
7771 }
7773 {
7774  if ((v->Typ() != LINK_CMD) ||
7775  (v->next->Typ() != STRING_CMD) ||
7776  (v->next->next->Typ() != STRING_CMD) ||
7777  (v->next->next->next->Typ() != INT_CMD))
7778  return TRUE;
7779  jjSTATUS3(res, v, v->next, v->next->next);
7780 #if defined(HAVE_USLEEP)
7781  if (((long) res->data) == 0L)
7782  {
7783  int i_s = (int)(long) v->next->next->next->Data();
7784  if (i_s > 0)
7785  {
7786  usleep((int)(long) v->next->next->next->Data());
7787  jjSTATUS3(res, v, v->next, v->next->next);
7788  }
7789  }
7790 #elif defined(HAVE_SLEEP)
7791  if (((int) res->data) == 0)
7792  {
7793  int i_s = (int) v->next->next->next->Data();
7794  if (i_s > 0)
7795  {
7796  si_sleep((is - 1)/1000000 + 1);
7797  jjSTATUS3(res, v, v->next, v->next->next);
7798  }
7799  }
7800 #endif
7801  return FALSE;
7802 }
7804 {
7805  leftv v = u->next; // number of args > 0
7806  if (v==NULL) return TRUE;
7807  leftv w = v->next;
7808  if (w==NULL) return TRUE;
7809  leftv rest = w->next;;
7810 
7811  u->next = NULL;
7812  v->next = NULL;
7813  w->next = NULL;
7814  BOOLEAN b = iiExprArith3(res, iiOp, u, v, w);
7815  if ((rest!=NULL) && (!b))
7816  {
7817  sleftv tmp_res;
7818  leftv tmp_next=res->next;
7819  res->next=rest;
7820  memset(&tmp_res,0,sizeof(tmp_res));
7821  b = iiExprArithM(&tmp_res,res,iiOp);
7822  memcpy(res,&tmp_res,sizeof(tmp_res));
7823  res->next=tmp_next;
7824  }
7825  u->next = v;
7826  v->next = w;
7827  // rest was w->next, but is already cleaned
7828  return b;
7829 }
7830 static BOOLEAN jjQRDS(leftv res, leftv INPUT)
7831 {
7832  if ((INPUT->Typ() != MATRIX_CMD) ||
7833  (INPUT->next->Typ() != NUMBER_CMD) ||
7834  (INPUT->next->next->Typ() != NUMBER_CMD) ||
7835  (INPUT->next->next->next->Typ() != NUMBER_CMD))
7836  {
7837  WerrorS("expected (matrix, number, number, number) as arguments");
7838  return TRUE;
7839  }
7840  leftv u = INPUT; leftv v = u->next; leftv w = v->next; leftv x = w->next;
7841  res->data = (char *)qrDoubleShift((matrix)(u->Data()),
7842  (number)(v->Data()),
7843  (number)(w->Data()),
7844  (number)(x->Data()));
7845  return FALSE;
7846 }
7847 static BOOLEAN jjSTD_HILB_WP(leftv res, leftv INPUT)
7848 { ideal result;
7849  leftv u = INPUT; /* an ideal, weighted homogeneous and standard */
7850  leftv v = u->next; /* one additional polynomial or ideal */
7851  leftv h = v->next; /* Hilbert vector */
7852  leftv w = h->next; /* weight vector */
7853  assumeStdFlag(u);
7854  ideal i1=(ideal)(u->Data());
7855  ideal i0;
7856  if (((u->Typ()!=IDEAL_CMD)&&(u->Typ()!=MODUL_CMD))
7857  || (h->Typ()!=INTVEC_CMD)
7858  || (w->Typ()!=INTVEC_CMD))
7859  {
7860  WerrorS("expected `std(`ideal/module`,`poly/vector`,`intvec`,`intvec`)");
7861  return TRUE;
7862  }
7863  intvec *vw=(intvec *)w->Data(); // weights of vars
7864  /* merging std_hilb_w and std_1 */
7865  if (vw->length()!=currRing->N)
7866  {
7867  Werror("%d weights for %d variables",vw->length(),currRing->N);
7868  return TRUE;
7869  }
7870  int r=v->Typ();
7871  BOOLEAN cleanup_i0=FALSE;
7872  if ((r==POLY_CMD) ||(r==VECTOR_CMD))
7873  {
7874  i0=idInit(1,i1->rank);
7875  i0->m[0]=(poly)v->Data();
7876  cleanup_i0=TRUE;
7877  }
7878  else if (r==IDEAL_CMD)/* IDEAL */
7879  {
7880  i0=(ideal)v->Data();
7881  }
7882  else
7883  {
7884  WerrorS("expected `std(`ideal/module`,`poly/vector`,`intvec`,`intvec`)");
7885  return TRUE;
7886  }
7887  int ii0=idElem(i0);
7888  i1 = idSimpleAdd(i1,i0);
7889  if (cleanup_i0)
7890  {
7891  memset(i0->m,0,sizeof(poly)*IDELEMS(i0));
7892  idDelete(&i0);
7893  }
7894  intvec *ww=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
7895  tHomog hom=testHomog;
7896  /* u_id from jjSTD_W is now i1 as in jjSTD_1 */
7897  if (ww!=NULL)
7898  {
7899  if (!idTestHomModule(i1,currRing->qideal,ww))
7900  {
7901  WarnS("wrong weights");
7902  ww=NULL;
7903  }
7904  else
7905  {
7906  ww=ivCopy(ww);
7907  hom=isHomog;
7908  }
7909  }
7910  BITSET save1;
7911  SI_SAVE_OPT1(save1);
7913  result=kStd(i1,
7914  currRing->qideal,
7915  hom,
7916  &ww, // module weights
7917  (intvec *)h->Data(), // hilbert series
7918  0, // syzComp, whatever it is...
7919  IDELEMS(i1)-ii0, // new ideal
7920  vw); // weights of vars
7921  SI_RESTORE_OPT1(save1);
7922  idDelete(&i1);
7923  idSkipZeroes(result);
7924  res->data = (char *)result;
7925  if (!TEST_OPT_DEGBOUND) setFlag(res,FLAG_STD);
7926  if (ww!=NULL) atSet(res,omStrDup("isHomog"),ww,INTVEC_CMD);
7927  return FALSE;
7928 }
7929 
7931 {
7932  //Print("construct ring\n");
7933  if (a->Typ()!=CRING_CMD)
7934  {
7935  WerrorS("expected `cring` [ `id` ... ]");
7936  return TRUE;
7937  }
7938  assume(a->next!=NULL);
7939  leftv names=a->next;
7940  int N=names->listLength();
7941  char **n=(char**)omAlloc0(N*sizeof(char*));
7942  for(int i=0; i<N;i++,names=names->next)
7943  {
7944  n[i]=(char *)names->Name();
7945  }
7946  coeffs cf=(coeffs)a->CopyD();
7947  res->data=rDefault(cf,N,n, ringorder_dp);
7948  omFreeSize(n,N*sizeof(char*));
7949  return FALSE;
7950 }
7951 
7952 static Subexpr jjMakeSub(leftv e)
7953 {
7954  assume( e->Typ()==INT_CMD );
7955  Subexpr r=(Subexpr)omAlloc0Bin(sSubexpr_bin);
7956  r->start =(int)(long)e->Data();
7957  return r;
7958 }
7959 #define D(A) (A)
7960 #define NULL_VAL NULL
7961 #define IPARITH
7962 #include "table.h"
7963 
7964 #include "iparith.inc"
7965 
7966 /*=================== operations with 2 args. ============================*/
7967 /* must be ordered: first operations for chars (infix ops),
7968  * then alphabetically */
7969 
7971  BOOLEAN proccall,
7972  const struct sValCmd2* dA2,
7973  int at, int bt,
7974  const struct sConvertTypes *dConvertTypes)
7975 {
7976  memset(res,0,sizeof(sleftv));
7977  BOOLEAN call_failed=FALSE;
7978 
7979  if (!errorreported)
7980  {
7981  int i=0;
7982  iiOp=op;
7983  while (dA2[i].cmd==op)
7984  {
7985  if ((at==dA2[i].arg1)
7986  && (bt==dA2[i].arg2))
7987  {
7988  res->rtyp=dA2[i].res;
7989  if (currRing!=NULL)
7990  {
7991  if (check_valid(dA2[i].valid_for,op)) break;
7992  }
7993  else
7994  {
7995  if (RingDependend(dA2[i].res))
7996  {
7997  WerrorS("no ring active");
7998  break;
7999  }
8000  }
8001  if (traceit&TRACE_CALL)
8002  Print("call %s(%s,%s)\n",iiTwoOps(op),Tok2Cmdname(at),Tok2Cmdname(bt));
8003  if ((call_failed=dA2[i].p(res,a,b)))
8004  {
8005  break;// leave loop, goto error handling
8006  }
8007  a->CleanUp();
8008  b->CleanUp();
8009  //Print("op: %d,result typ:%d\n",op,res->rtyp);
8010  return FALSE;
8011  }
8012  i++;
8013  }
8014  // implicite type conversion ----------------------------------------------
8015  if (dA2[i].cmd!=op)
8016  {
8017  int ai,bi;
8020  BOOLEAN failed=FALSE;
8021  i=0; /*iiTabIndex(dArithTab2,JJTAB2LEN,op);*/
8022  //Print("op: %c, type: %s %s\n",op,Tok2Cmdname(at),Tok2Cmdname(bt));
8023  while (dA2[i].cmd==op)
8024  {
8025  //Print("test %s %s\n",Tok2Cmdname(dA2[i].arg1),Tok2Cmdname(dA2[i].arg2));
8026  if ((dA2[i].valid_for & NO_CONVERSION)==0)
8027  {
8028  if ((ai=iiTestConvert(at,dA2[i].arg1,dConvertTypes))!=0)
8029  {
8030  if ((bi=iiTestConvert(bt,dA2[i].arg2,dConvertTypes))!=0)
8031  {
8032  res->rtyp=dA2[i].res;
8033  if (currRing!=NULL)
8034  {
8035  if (check_valid(dA2[i].valid_for,op)) break;
8036  }
8037  else
8038  {
8039  if (RingDependend(dA2[i].res))
8040  {
8041  WerrorS("no ring active");
8042  break;
8043  }
8044  }
8045  if (traceit&TRACE_CALL)
8046  Print("call %s(%s,%s)\n",iiTwoOps(op),
8047  Tok2Cmdname(dA2[i].arg1),Tok2Cmdname(dA2[i].arg2));
8048  failed= ((iiConvert(at,dA2[i].arg1,ai,a,an))
8049  || (iiConvert(bt,dA2[i].arg2,bi,b,bn))
8050  || (call_failed=dA2[i].p(res,an,bn)));
8051  // everything done, clean up temp. variables
8052  if (failed)
8053  {
8054  // leave loop, goto error handling
8055  break;
8056  }
8057  else
8058  {
8059  // everything ok, clean up and return
8060  an->CleanUp();
8061  bn->CleanUp();
8064  return FALSE;
8065  }
8066  }
8067  }
8068  }
8069  i++;
8070  }
8071  an->CleanUp();
8072  bn->CleanUp();
8075  }
8076  // error handling ---------------------------------------------------
8077  const char *s=NULL;
8078  if (!errorreported)
8079  {
8080  if ((at==0) && (a->Fullname()!=sNoName))
8081  {
8082  s=a->Fullname();
8083  }
8084  else if ((bt==0) && (b->Fullname()!=sNoName))
8085  {
8086  s=b->Fullname();
8087  }
8088  if (s!=NULL)
8089  Werror("`%s` is not defined",s);
8090  else
8091  {
8092  i=0; /*iiTabIndex(dArithTab2,JJTAB2LEN,op);*/
8093  s = iiTwoOps(op);
8094  if (proccall)
8095  {
8096  Werror("%s(`%s`,`%s`) failed"
8097  ,s,Tok2Cmdname(at),Tok2Cmdname(bt));
8098  }
8099  else
8100  {
8101  Werror("`%s` %s `%s` failed"
8102  ,Tok2Cmdname(at),s,Tok2Cmdname(bt));
8103  }
8104  if ((!call_failed) && BVERBOSE(V_SHOW_USE))
8105  {
8106  while (dA2[i].cmd==op)
8107  {
8108  if(((at==dA2[i].arg1)||(bt==dA2[i].arg2))
8109  && (dA2[i].res!=0)
8110  && (dA2[i].p!=jjWRONG2))
8111  {
8112  if (proccall)
8113  Werror("expected %s(`%s`,`%s`)"
8114  ,s,Tok2Cmdname(dA2[i].arg1),Tok2Cmdname(dA2[i].arg2));
8115  else
8116  Werror("expected `%s` %s `%s`"
8117  ,Tok2Cmdname(dA2[i].arg1),s,Tok2Cmdname(dA2[i].arg2));
8118  }
8119  i++;
8120  }
8121  }
8122  }
8123  }
8124  a->CleanUp();
8125  b->CleanUp();
8126  res->rtyp = UNKNOWN;
8127  }
8128  return TRUE;
8129 }
8131  const struct sValCmd2* dA2,
8132  int at,
8133  const struct sConvertTypes *dConvertTypes)
8134 {
8135  leftv b=a->next;
8136  a->next=NULL;
8137  int bt=b->Typ();
8138  BOOLEAN bo=iiExprArith2TabIntern(res,a,op,b,TRUE,dA2,at,bt,dConvertTypes);
8139  a->next=b;
8140  a->CleanUp(); // to clean up the chain, content already done in iiExprArith2TabIntern
8141  return bo;
8142 }
8143 BOOLEAN iiExprArith2(leftv res, leftv a, int op, leftv b, BOOLEAN proccall)
8144 {
8145  memset(res,0,sizeof(sleftv));
8146 
8147  if (!errorreported)
8148  {
8149 #ifdef SIQ
8150  if (siq>0)
8151  {
8152  //Print("siq:%d\n",siq);
8154  memcpy(&d->arg1,a,sizeof(sleftv));
8155  a->Init();
8156  memcpy(&d->arg2,b,sizeof(sleftv));
8157  b->Init();
8158  d->argc=2;
8159  d->op=op;
8160  res->data=(char *)d;
8161  res->rtyp=COMMAND;
8162  return FALSE;
8163  }
8164 #endif
8165  int at=a->Typ();
8166  int bt=b->Typ();
8167  // handling bb-objects ----------------------------------------------------
8168  if (at>MAX_TOK)
8169  {
8170  blackbox *bb=getBlackboxStuff(at);
8171  if (bb!=NULL)
8172  {
8173  if (!bb->blackbox_Op2(op,res,a,b)) return FALSE;
8174  if (errorreported) return TRUE;
8175  // else: no op defined
8176  }
8177  else return TRUE;
8178  }
8179  else if ((bt>MAX_TOK)&&(op!='('))
8180  {
8181  blackbox *bb=getBlackboxStuff(bt);
8182  if (bb!=NULL)
8183  {
8184  if(!bb->blackbox_Op2(op,res,a,b)) return FALSE;
8185  if (errorreported) return TRUE;
8186  // else: no op defined
8187  }
8188  else return TRUE;
8189  }
8190  int i=iiTabIndex(dArithTab2,JJTAB2LEN,op);
8191  return iiExprArith2TabIntern(res,a,op,b,proccall,dArith2+i,at,bt,dConvertTypes);
8192  }
8193  a->CleanUp();
8194  b->CleanUp();
8195  return TRUE;
8196 }
8197 
8198 /*==================== operations with 1 arg. ===============================*/
8199 /* must be ordered: first operations for chars (infix ops),
8200  * then alphabetically */
8201 
8202 BOOLEAN iiExprArith1Tab(leftv res, leftv a, int op, const struct sValCmd1* dA1, int at, const struct sConvertTypes *dConvertTypes)
8203 {
8204  memset(res,0,sizeof(sleftv));
8205  BOOLEAN call_failed=FALSE;
8206 
8207  if (!errorreported)
8208  {
8209  BOOLEAN failed=FALSE;
8210  iiOp=op;
8211  int i = 0;
8212  while (dA1[i].cmd==op)
8213  {
8214  if (at==dA1[i].arg)
8215  {
8216  if (currRing!=NULL)
8217  {
8218  if (check_valid(dA1[i].valid_for,op)) break;
8219  }
8220  else
8221  {
8222  if (RingDependend(dA1[i].res))
8223  {
8224  WerrorS("no ring active");
8225  break;
8226  }
8227  }
8228  if (traceit&TRACE_CALL)
8229  Print("call %s(%s)\n",iiTwoOps(op),Tok2Cmdname(at));
8230  res->rtyp=dA1[i].res;
8231  if ((call_failed=dA1[i].p(res,a)))
8232  {
8233  break;// leave loop, goto error handling
8234  }
8235  if (a->Next()!=NULL)
8236  {
8238  failed=iiExprArith1(res->next,a->next,op);
8239  }
8240  a->CleanUp();
8241  return failed;
8242  }
8243  i++;
8244  }
8245  // implicite type conversion --------------------------------------------
8246  if (dA1[i].cmd!=op)
8247  {
8249  i=0;
8250  //Print("fuer %c , typ: %s\n",op,Tok2Cmdname(at));
8251  while (dA1[i].cmd==op)
8252  {
8253  int ai;
8254  //Print("test %s\n",Tok2Cmdname(dA1[i].arg));
8255  if ((dA1[i].valid_for & NO_CONVERSION)==0)
8256  {
8257  if ((ai=iiTestConvert(at,dA1[i].arg,dConvertTypes))!=0)
8258  {
8259  if (currRing!=NULL)
8260  {
8261  if (check_valid(dA1[i].valid_for,op)) break;
8262  }
8263  else
8264  {
8265  if (RingDependend(dA1[i].res))
8266  {
8267  WerrorS("no ring active");
8268  break;
8269  }
8270  }
8271  if (traceit&TRACE_CALL)
8272  Print("call %s(%s)\n",iiTwoOps(op),Tok2Cmdname(dA1[i].arg));
8273  res->rtyp=dA1[i].res;
8274  failed= ((iiConvert(at,dA1[i].arg,ai,a,an,dConvertTypes))
8275  || (call_failed=dA1[i].p(res,an)));
8276  // everything done, clean up temp. variables
8277  if (failed)
8278  {
8279  // leave loop, goto error handling
8280  break;
8281  }
8282  else
8283  {
8284  if (an->Next() != NULL)
8285  {
8286  res->next = (leftv)omAllocBin(sleftv_bin);
8287  failed=iiExprArith1(res->next,an->next,op);
8288  }
8289  // everything ok, clean up and return
8290  an->CleanUp();
8292  a->CleanUp();
8293  return failed;
8294  }
8295  }
8296  }
8297  i++;
8298  }
8299  an->CleanUp();
8301  }
8302  // error handling
8303  if (!errorreported)
8304  {
8305  if ((at==0) && (a->Fullname()!=sNoName))
8306  {
8307  Werror("`%s` is not defined",a->Fullname());
8308  }
8309  else
8310  {
8311  i=0;
8312  const char *s = iiTwoOps(op);
8313  Werror("%s(`%s`) failed"
8314  ,s,Tok2Cmdname(at));
8315  if ((!call_failed) && BVERBOSE(V_SHOW_USE))
8316  {
8317  while (dA1[i].cmd==op)
8318  {
8319  if ((dA1[i].res!=0)
8320  && (dA1[i].p!=jjWRONG))
8321  Werror("expected %s(`%s`)"
8322  ,s,Tok2Cmdname(dA1[i].arg));
8323  i++;
8324  }
8325  }
8326  }
8327  }
8328  res->rtyp = UNKNOWN;
8329  }
8330  a->CleanUp();
8331  return TRUE;
8332 }
8334 {
8335  memset(res,0,sizeof(sleftv));
8336 
8337  if (!errorreported)
8338  {
8339 #ifdef SIQ
8340  if (siq>0)
8341  {
8342  //Print("siq:%d\n",siq);
8344  memcpy(&d->arg1,a,sizeof(sleftv));
8345  a->Init();
8346  d->op=op;
8347  d->argc=1;
8348  res->data=(char *)d;
8349  res->rtyp=COMMAND;
8350  return FALSE;
8351  }
8352 #endif
8353  int at=a->Typ();
8354  // handling bb-objects ----------------------------------------------------
8355  if(op>MAX_TOK) // explicit type conversion to bb
8356  {
8357  blackbox *bb=getBlackboxStuff(op);
8358  if (bb!=NULL)
8359  {
8360  res->rtyp=op;
8361  res->data=bb->blackbox_Init(bb);
8362  if(!bb->blackbox_Assign(res,a)) return FALSE;
8363  if (errorreported) return TRUE;
8364  }
8365  else return TRUE;
8366  }
8367  else if (at>MAX_TOK) // argument is of bb-type
8368  {
8369  blackbox *bb=getBlackboxStuff(at);
8370  if (bb!=NULL)
8371  {
8372  if(!bb->blackbox_Op1(op,res,a)) return FALSE;
8373  if (errorreported) return TRUE;
8374  // else: no op defined
8375  }
8376  else return TRUE;
8377  }
8378 
8379  iiOp=op;
8380  int i=iiTabIndex(dArithTab1,JJTAB1LEN,op);
8381  return iiExprArith1Tab(res,a,op, dArith1+i,at,dConvertTypes);
8382  }
8383  a->CleanUp();
8384  return TRUE;
8385 }
8386 
8387 /*=================== operations with 3 args. ============================*/
8388 /* must be ordered: first operations for chars (infix ops),
8389  * then alphabetically */
8390 
8392  const struct sValCmd3* dA3, int at, int bt, int ct,
8393  const struct sConvertTypes *dConvertTypes)
8394 {
8395  memset(res,0,sizeof(sleftv));
8396  BOOLEAN call_failed=FALSE;
8397 
8398  assume(dA3[0].cmd==op);
8399 
8400  if (!errorreported)
8401  {
8402  int i=0;
8403  iiOp=op;
8404  while (dA3[i].cmd==op)
8405  {
8406  if ((at==dA3[i].arg1)
8407  && (bt==dA3[i].arg2)
8408  && (ct==dA3[i].arg3))
8409  {
8410  res->rtyp=dA3[i].res;
8411  if (currRing!=NULL)
8412  {
8413  if (check_valid(dA3[i].valid_for,op)) break;
8414  }
8415  if (traceit&TRACE_CALL)
8416  Print("call %s(%s,%s,%s)\n",
8417  iiTwoOps(op),Tok2Cmdname(at),Tok2Cmdname(bt),Tok2Cmdname(ct));
8418  if ((call_failed=dA3[i].p(res,a,b,c)))
8419  {
8420  break;// leave loop, goto error handling
8421  }
8422  a->CleanUp();
8423  b->CleanUp();
8424  c->CleanUp();
8425  return FALSE;
8426  }
8427  i++;
8428  }
8429  // implicite type conversion ----------------------------------------------
8430  if (dA3[i].cmd!=op)
8431  {
8432  int ai,bi,ci;
8436  BOOLEAN failed=FALSE;
8437  i=0;
8438  //while ((dA3[i].cmd!=op)&&(dA3[i].cmd!=0)) i++;
8439  while (dA3[i].cmd==op)
8440  {
8441  if ((dA3[i].valid_for & NO_CONVERSION)==0)
8442  {
8443  if ((ai=iiTestConvert(at,dA3[i].arg1,dConvertTypes))!=0)
8444  {
8445  if ((bi=iiTestConvert(bt,dA3[i].arg2,dConvertTypes))!=0)
8446  {
8447  if ((ci=iiTestConvert(ct,dA3[i].arg3,dConvertTypes))!=0)
8448  {
8449  res->rtyp=dA3[i].res;
8450  if (currRing!=NULL)
8451  {
8452  if (check_valid(dA3[i].valid_for,op)) break;
8453  }
8454  if (traceit&TRACE_CALL)
8455  Print("call %s(%s,%s,%s)\n",
8456  iiTwoOps(op),Tok2Cmdname(dA3[i].arg1),
8457  Tok2Cmdname(dA3[i].arg2),Tok2Cmdname(dA3[i].arg3));
8458  failed= ((iiConvert(at,dA3[i].arg1,ai,a,an,dConvertTypes))
8459  || (iiConvert(bt,dA3[i].arg2,bi,b,bn,dConvertTypes))
8460  || (iiConvert(ct,dA3[i].arg3,ci,c,cn,dConvertTypes))
8461  || (call_failed=dA3[i].p(res,an,bn,cn)));
8462  // everything done, clean up temp. variables
8463  if (failed)
8464  {
8465  // leave loop, goto error handling
8466  break;
8467  }
8468  else
8469  {
8470  // everything ok, clean up and return
8471  an->CleanUp();
8472  bn->CleanUp();
8473  cn->CleanUp();
8477  //Print("op: %d,result typ:%d\n",op,res->rtyp);
8478  a->CleanUp();
8479  b->CleanUp();
8480  c->CleanUp();
8481  return FALSE;
8482  }
8483  }
8484  }
8485  }
8486  }
8487  i++;
8488  }
8489  an->CleanUp();
8490  bn->CleanUp();
8491  cn->CleanUp();
8495  }
8496  // error handling ---------------------------------------------------
8497  if (!errorreported)
8498  {
8499  const char *s=NULL;
8500  if ((at==0) && (a->Fullname()!=sNoName))
8501  {
8502  s=a->Fullname();
8503  }
8504  else if ((bt==0) && (b->Fullname()!=sNoName))
8505  {
8506  s=b->Fullname();
8507  }
8508  else if ((ct==0) && (c->Fullname()!=sNoName))
8509  {
8510  s=c->Fullname();
8511  }
8512  if (s!=NULL)
8513  Werror("`%s` is not defined",s);
8514  else
8515  {
8516  i=0;
8517  //while ((dA3[i].cmd!=op)&&(dA3[i].cmd!=0)) i++;
8518  const char *s = iiTwoOps(op);
8519  Werror("%s(`%s`,`%s`,`%s`) failed"
8520  ,s,Tok2Cmdname(at),Tok2Cmdname(bt),Tok2Cmdname(ct));
8521  if ((!call_failed) && BVERBOSE(V_SHOW_USE))
8522  {
8523  while (dA3[i].cmd==op)
8524  {
8525  if(((at==dA3[i].arg1)
8526  ||(bt==dA3[i].arg2)
8527  ||(ct==dA3[i].arg3))
8528  && (dA3[i].res!=0))
8529  {
8530  Werror("expected %s(`%s`,`%s`,`%s`)"
8531  ,s,Tok2Cmdname(dA3[i].arg1)
8532  ,Tok2Cmdname(dA3[i].arg2)
8533  ,Tok2Cmdname(dA3[i].arg3));
8534  }
8535  i++;
8536  }
8537  }
8538  }
8539  }
8540  res->rtyp = UNKNOWN;
8541  }
8542  a->CleanUp();
8543  b->CleanUp();
8544  c->CleanUp();
8545  //Print("op: %d,result typ:%d\n",op,res->rtyp);
8546  return TRUE;
8547 }
8549 {
8550  memset(res,0,sizeof(sleftv));
8551 
8552  if (!errorreported)
8553  {
8554 #ifdef SIQ
8555  if (siq>0)
8556  {
8557  //Print("siq:%d\n",siq);
8559  memcpy(&d->arg1,a,sizeof(sleftv));
8560  a->Init();
8561  memcpy(&d->arg2,b,sizeof(sleftv));
8562  b->Init();
8563  memcpy(&d->arg3,c,sizeof(sleftv));
8564  c->Init();
8565  d->op=op;
8566  d->argc=3;
8567  res->data=(char *)d;
8568  res->rtyp=COMMAND;
8569  return FALSE;
8570  }
8571 #endif
8572  int at=a->Typ();
8573  // handling bb-objects ----------------------------------------------
8574  if (at>MAX_TOK)
8575  {
8576  blackbox *bb=getBlackboxStuff(at);
8577  if (bb!=NULL)
8578  {
8579  if(!bb->blackbox_Op3(op,res,a,b,c)) return FALSE;
8580  if (errorreported) return TRUE;
8581  // else: no op defined
8582  }
8583  else return TRUE;
8584  if (errorreported) return TRUE;
8585  }
8586  int bt=b->Typ();
8587  int ct=c->Typ();
8588 
8589  iiOp=op;
8590  int i=0;
8591  while ((dArith3[i].cmd!=op)&&(dArith3[i].cmd!=0)) i++;
8592  return iiExprArith3TabIntern(res,op,a,b,c,dArith3+i,at,bt,ct,dConvertTypes);
8593  }
8594  a->CleanUp();
8595  b->CleanUp();
8596  c->CleanUp();
8597  //Print("op: %d,result typ:%d\n",op,res->rtyp);
8598  return TRUE;
8599 }
8601  const struct sValCmd3* dA3,
8602  int at,
8603  const struct sConvertTypes *dConvertTypes)
8604 {
8605  leftv b=a->next;
8606  a->next=NULL;
8607  int bt=b->Typ();
8608  leftv c=b->next;
8609  b->next=NULL;
8610  int ct=c->Typ();
8611  BOOLEAN bo=iiExprArith3TabIntern(res,op,a,b,c,dA3,at,bt,ct,dConvertTypes);
8612  b->next=c;
8613  a->next=b;
8614  a->CleanUp(); // to cleanup the chain, content already done
8615  return bo;
8616 }
8617 /*==================== operations with many arg. ===============================*/
8618 /* must be ordered: first operations for chars (infix ops),
8619  * then alphabetically */
8620 
8621 #if 0 // unused
8622 static BOOLEAN jjANY2LIST(leftv res, leftv v, int cnt)
8623 {
8624  // cnt = 0: all
8625  // cnt = 1: only first one
8626  leftv next;
8627  BOOLEAN failed = TRUE;
8628  if(v==NULL) return failed;
8629  res->rtyp = LIST_CMD;
8630  if(cnt) v->next = NULL;
8631  next = v->next; // saving next-pointer
8632  failed = jjLIST_PL(res, v);
8633  v->next = next; // writeback next-pointer
8634  return failed;
8635 }
8636 #endif
8637 
8639 {
8640  memset(res,0,sizeof(sleftv));
8641 
8642  if (!errorreported)
8643  {
8644 #ifdef SIQ
8645  if (siq>0)
8646  {
8647  //Print("siq:%d\n",siq);
8649  d->op=op;
8650  res->data=(char *)d;
8651  if (a!=NULL)
8652  {
8653  d->argc=a->listLength();
8654  // else : d->argc=0;
8655  memcpy(&d->arg1,a,sizeof(sleftv));
8656  switch(d->argc)
8657  {
8658  case 3:
8659  memcpy(&d->arg3,a->next->next,sizeof(sleftv));
8660  a->next->next->Init();
8661  /* no break */
8662  case 2:
8663  memcpy(&d->arg2,a->next,sizeof(sleftv));
8664  a->next->Init();
8665  a->next->next=d->arg2.next;
8666  d->arg2.next=NULL;
8667  /* no break */
8668  case 1:
8669  a->Init();
8670  a->next=d->arg1.next;
8671  d->arg1.next=NULL;
8672  }
8673  if (d->argc>3) a->next=NULL;
8674  a->name=NULL;
8675  a->rtyp=0;
8676  a->data=NULL;
8677  a->e=NULL;
8678  a->attribute=NULL;
8679  a->CleanUp();
8680  }
8681  res->rtyp=COMMAND;
8682  return FALSE;
8683  }
8684 #endif
8685  if ((a!=NULL) && (a->Typ()>MAX_TOK))
8686  {
8687  blackbox *bb=getBlackboxStuff(a->Typ());
8688  if (bb!=NULL)
8689  {
8690  if(!bb->blackbox_OpM(op,res,a)) return FALSE;
8691  if (errorreported) return TRUE;
8692  // else: no op defined
8693  }
8694  else return TRUE;
8695  }
8696  int args=0;
8697  if (a!=NULL) args=a->listLength();
8698 
8699  iiOp=op;
8700  int i=0;
8701  while ((dArithM[i].cmd!=op)&&(dArithM[i].cmd!=0)) i++;
8702  while (dArithM[i].cmd==op)
8703  {
8704  if ((args==dArithM[i].number_of_args)
8705  || (dArithM[i].number_of_args==-1)
8706  || ((dArithM[i].number_of_args==-2)&&(args>0)))
8707  {
8708  res->rtyp=dArithM[i].res;
8709  if (currRing!=NULL)
8710  {
8711  if (check_valid(dArithM[i].valid_for,op)) break;
8712  }
8713  if (traceit&TRACE_CALL)
8714  Print("call %s(... (%d args))\n", iiTwoOps(op),args);
8715  if (dArithM[i].p(res,a))
8716  {
8717  break;// leave loop, goto error handling
8718  }
8719  if (a!=NULL) a->CleanUp();
8720  //Print("op: %d,result typ:%d\n",op,res->rtyp);
8721  return FALSE;
8722  }
8723  i++;
8724  }
8725  // error handling
8726  if (!errorreported)
8727  {
8728  if ((args>0) && (a->rtyp==0) && (a->Name()!=sNoName))
8729  {
8730  Werror("`%s` is not defined",a->Fullname());
8731  }
8732  else
8733  {
8734  const char *s = iiTwoOps(op);
8735  Werror("%s(...) failed",s);
8736  }
8737  }
8738  res->rtyp = UNKNOWN;
8739  }
8740  if (a!=NULL) a->CleanUp();
8741  //Print("op: %d,result typ:%d\n",op,res->rtyp);
8742  return TRUE;
8743 }
8744 
8745 /*=================== general utilities ============================*/
8746 int IsCmd(const char *n, int & tok)
8747 {
8748  int i;
8749  int an=1;
8750  int en=sArithBase.nLastIdentifier;
8751 
8752  loop
8753  //for(an=0; an<sArithBase.nCmdUsed; )
8754  {
8755  if(an>=en-1)
8756  {
8757  if (strcmp(n, sArithBase.sCmds[an].name) == 0)
8758  {
8759  i=an;
8760  break;
8761  }
8762  else if ((an!=en) && (strcmp(n, sArithBase.sCmds[en].name) == 0))
8763  {
8764  i=en;
8765  break;
8766  }
8767  else
8768  {
8769  // -- blackbox extensions:
8770  // return 0;
8771  return blackboxIsCmd(n,tok);
8772  }
8773  }
8774  i=(an+en)/2;
8775  if (*n < *(sArithBase.sCmds[i].name))
8776  {
8777  en=i-1;
8778  }
8779  else if (*n > *(sArithBase.sCmds[i].name))
8780  {
8781  an=i+1;
8782  }
8783  else
8784  {
8785  int v=strcmp(n,sArithBase.sCmds[i].name);
8786  if(v<0)
8787  {
8788  en=i-1;
8789  }
8790  else if(v>0)
8791  {
8792  an=i+1;
8793  }
8794  else /*v==0*/
8795  {
8796  break;
8797  }
8798  }
8799  }
8800  lastreserved=sArithBase.sCmds[i].name;
8801  tok=sArithBase.sCmds[i].tokval;
8802  if(sArithBase.sCmds[i].alias==2)
8803  {
8804  Warn("outdated identifier `%s` used - please change your code",
8805  sArithBase.sCmds[i].name);
8806  sArithBase.sCmds[i].alias=1;
8807  }
8808  #if 0
8809  if (currRingHdl==NULL)
8810  {
8811  #ifdef SIQ
8812  if (siq<=0)
8813  {
8814  #endif
8815  if ((tok>=BEGIN_RING) && (tok<=END_RING))
8816  {
8817  WerrorS("no ring active");
8818  return 0;
8819  }
8820  #ifdef SIQ
8821  }
8822  #endif
8823  }
8824  #endif
8825  if (!expected_parms)
8826  {
8827  switch (tok)
8828  {
8829  case IDEAL_CMD:
8830  case INT_CMD:
8831  case INTVEC_CMD:
8832  case MAP_CMD:
8833  case MATRIX_CMD:
8834  case MODUL_CMD:
8835  case POLY_CMD:
8836  case PROC_CMD:
8837  case RING_CMD:
8838  case STRING_CMD:
8839  cmdtok = tok;
8840  break;
8841  }
8842  }
8843  return sArithBase.sCmds[i].toktype;
8844 }
8845 static int iiTabIndex(const jjValCmdTab dArithTab, const int len, const int op)
8846 {
8847  // user defined types are not in the pre-computed table:
8848  if (op>MAX_TOK) return 0;
8849 
8850  int a=0;
8851  int e=len;
8852  int p=len/2;
8853  do
8854  {
8855  if (op==dArithTab[p].cmd) return dArithTab[p].start;
8856  if (op<dArithTab[p].cmd) e=p-1;
8857  else a = p+1;
8858  p=a+(e-a)/2;
8859  }
8860  while ( a <= e);
8861 
8862  // catch missing a cmd:
8863  // may be missing as a op for blackbox, if the first operand is "undef" instead of bb
8864  // Print("op %d (%c) unknown",op,op);
8865  return 0;
8866 }
8867 
8868 const char * Tok2Cmdname(int tok)
8869 {
8870  if (tok <= 0)
8871  {
8872  return sArithBase.sCmds[0].name;
8873  }
8874  if (tok==ANY_TYPE) return "any_type";
8875  if (tok==COMMAND) return "command";
8876  if (tok==NONE) return "nothing";
8877  //if (tok==IFBREAK) return "if_break";
8878  //if (tok==VECTOR_FROM_POLYS) return "vector_from_polys";
8879  //if (tok==ORDER_VECTOR) return "ordering";
8880  //if (tok==REF_VAR) return "ref";
8881  //if (tok==OBJECT) return "object";
8882  //if (tok==PRINT_EXPR) return "print_expr";
8883  if (tok==IDHDL) return "identifier";
8884  if (tok>MAX_TOK) return getBlackboxName(tok);
8885  unsigned i;
8886  for(i=0; i<sArithBase.nCmdUsed; i++)
8887  //while (sArithBase.sCmds[i].tokval!=0)
8888  {
8889  if ((sArithBase.sCmds[i].tokval == tok)&&
8890  (sArithBase.sCmds[i].alias==0))
8891  {
8892  return sArithBase.sCmds[i].name;
8893  }
8894  }
8895  // try gain for alias/old names:
8896  for(i=0; i<sArithBase.nCmdUsed; i++)
8897  {
8898  if (sArithBase.sCmds[i].tokval == tok)
8899  {
8900  return sArithBase.sCmds[i].name;
8901  }
8902  }
8903  return sArithBase.sCmds[0].name;
8904 }
8905 
8906 
8907 /*---------------------------------------------------------------------*/
8908 /**
8909  * @brief compares to entry of cmdsname-list
8910 
8911  @param[in] a
8912  @param[in] b
8913 
8914  @return <ReturnValue>
8915 **/
8916 /*---------------------------------------------------------------------*/
8917 static int _gentable_sort_cmds( const void *a, const void *b )
8918 {
8919  cmdnames *pCmdL = (cmdnames*)a;
8920  cmdnames *pCmdR = (cmdnames*)b;
8921 
8922  if(a==NULL || b==NULL) return 0;
8923 
8924  /* empty entries goes to the end of the list for later reuse */
8925  if(pCmdL->name==NULL) return 1;
8926  if(pCmdR->name==NULL) return -1;
8927 
8928  /* $INVALID$ must come first */
8929  if(strcmp(pCmdL->name, "$INVALID$")==0) return -1;
8930  if(strcmp(pCmdR->name, "$INVALID$")==0) return 1;
8931 
8932  /* tokval=-1 are reserved names at the end */
8933  if (pCmdL->tokval==-1)
8934  {
8935  if (pCmdR->tokval==-1)
8936  return strcmp(pCmdL->name, pCmdR->name);
8937  /* pCmdL->tokval==-1, pCmdL goes at the end */
8938  return 1;
8939  }
8940  /* pCmdR->tokval==-1, pCmdR goes at the end */
8941  if(pCmdR->tokval==-1) return -1;
8942 
8943  return strcmp(pCmdL->name, pCmdR->name);
8944 }
8945 
8946 /*---------------------------------------------------------------------*/
8947 /**
8948  * @brief initialisation of arithmetic structured data
8949 
8950  @retval 0 on success
8951 
8952 **/
8953 /*---------------------------------------------------------------------*/
8955 {
8956  //printf("iiInitArithmetic()\n");
8957  memset(&sArithBase, 0, sizeof(sArithBase));
8958  iiInitCmdName();
8959  /* fix last-identifier */
8960 #if 0
8961  /* we expect that gentable allready did every thing */
8962  for(sArithBase.nLastIdentifier=sArithBase.nCmdUsed-1;
8963  sArithBase.nLastIdentifier>0; sArithBase.nLastIdentifier--) {
8964  if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
8965  }
8966 #endif
8967  //Print("L=%d\n", sArithBase.nLastIdentifier);
8968 
8969  //iiArithAddCmd(szName, nAlias, nTokval, nToktype);
8970  //iiArithAddCmd("mygcd", 1, GCD_CMD, CMD_2);
8971 
8972  //iiArithAddCmd("Top", 0,-1,0);
8973 
8974 
8975  //for(i=0; i<sArithBase.nCmdUsed; i++) {
8976  // printf("CMD[%03d] %s, %d, %d, %d\n", i,
8977  // sArithBase.sCmds[i].name,
8978  // sArithBase.sCmds[i].alias,
8979  // sArithBase.sCmds[i].tokval,
8980  // sArithBase.sCmds[i].toktype);
8981  //}
8982  //iiArithRemoveCmd("Top");
8983  //iiArithAddCmd("mygcd", 2, GCD_CMD, CMD_2);
8984  //iiArithRemoveCmd("mygcd");
8985  //iiArithAddCmd("kkk", 1, 1234, CMD_1);
8986  return 0;
8987 }
8988 
8989 int iiArithFindCmd(const char *szName)
8990 {
8991  int an=0;
8992  int i = 0,v = 0;
8993  int en=sArithBase.nLastIdentifier;
8994 
8995  loop
8996  //for(an=0; an<sArithBase.nCmdUsed; )
8997  {
8998  if(an>=en-1)
8999  {
9000  if (strcmp(szName, sArithBase.sCmds[an].name) == 0)
9001  {
9002  //Print("RET-an=%d %s\n", an, sArithBase.sCmds[an].name);
9003  return an;
9004  }
9005  else if (strcmp(szName, sArithBase.sCmds[en].name) == 0)
9006  {
9007  //Print("RET-en=%d %s\n", en, sArithBase.sCmds[en].name);
9008  return en;
9009  }
9010  else
9011  {
9012  //Print("RET- 1\n");
9013  return -1;
9014  }
9015  }
9016  i=(an+en)/2;
9017  if (*szName < *(sArithBase.sCmds[i].name))
9018  {
9019  en=i-1;
9020  }
9021  else if (*szName > *(sArithBase.sCmds[i].name))
9022  {
9023  an=i+1;
9024  }
9025  else
9026  {
9027  v=strcmp(szName,sArithBase.sCmds[i].name);
9028  if(v<0)
9029  {
9030  en=i-1;
9031  }
9032  else if(v>0)
9033  {
9034  an=i+1;
9035  }
9036  else /*v==0*/
9037  {
9038  //Print("RET-i=%d %s\n", i, sArithBase.sCmds[i].name);
9039  return i;
9040  }
9041  }
9042  }
9043  //if(i>=0 && i<sArithBase.nCmdUsed)
9044  // return i;
9045  //PrintS("RET-2\n");
9046  return -2;
9047 }
9048 
9049 char *iiArithGetCmd( int nPos )
9050 {
9051  if(nPos<0) return NULL;
9052  if(nPos<(int)sArithBase.nCmdUsed)
9053  return sArithBase.sCmds[nPos].name;
9054  return NULL;
9055 }
9056 
9057 int iiArithRemoveCmd(const char *szName)
9058 {
9059  int nIndex;
9060  if(szName==NULL) return -1;
9061 
9062  nIndex = iiArithFindCmd(szName);
9063  if(nIndex<0 || nIndex>=(int)sArithBase.nCmdUsed)
9064  {
9065  Print("'%s' not found (%d)\n", szName, nIndex);
9066  return -1;
9067  }
9068  omFree(sArithBase.sCmds[nIndex].name);
9069  sArithBase.sCmds[nIndex].name=NULL;
9070  qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames),
9071  (&_gentable_sort_cmds));
9072  sArithBase.nCmdUsed--;
9073 
9074  /* fix last-identifier */
9075  for(sArithBase.nLastIdentifier=sArithBase.nCmdUsed-1;
9076  sArithBase.nLastIdentifier>0; sArithBase.nLastIdentifier--)
9077  {
9078  if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
9079  }
9080  //Print("L=%d\n", sArithBase.nLastIdentifier);
9081  return 0;
9082 }
9083 
9085  const char *szName,
9086  short nAlias,
9087  short nTokval,
9088  short nToktype,
9089  short nPos
9090  )
9091 {
9092  //printf("AddCmd(%s, %d, %d, %d, %d)\n", szName, nAlias,
9093  // nTokval, nToktype, nPos);
9094  if(nPos>=0)
9095  {
9096  // no checks: we rely on a correct generated code in iparith.inc
9097  assume((unsigned)nPos < sArithBase.nCmdAllocated);
9098  assume(szName!=NULL);
9099  sArithBase.sCmds[nPos].name = omStrDup(szName);
9100  sArithBase.sCmds[nPos].alias = nAlias;
9101  sArithBase.sCmds[nPos].tokval = nTokval;
9102  sArithBase.sCmds[nPos].toktype = nToktype;
9103  sArithBase.nCmdUsed++;
9104  //if(nTokval>0) sArithBase.nLastIdentifier++;
9105  }
9106  else
9107  {
9108  if(szName==NULL) return -1;
9109  int nIndex = iiArithFindCmd(szName);
9110  if(nIndex>=0)
9111  {
9112  Print("'%s' already exists at %d\n", szName, nIndex);
9113  return -1;
9114  }
9115 
9116  if(sArithBase.nCmdUsed>=sArithBase.nCmdAllocated)
9117  {
9118  /* needs to create new slots */
9119  unsigned long nSize = (sArithBase.nCmdAllocated+1)*sizeof(cmdnames);
9120  sArithBase.sCmds = (cmdnames *)omRealloc(sArithBase.sCmds, nSize);
9121  if(sArithBase.sCmds==NULL) return -1;
9122  sArithBase.nCmdAllocated++;
9123  }
9124  /* still free slots available */
9125  sArithBase.sCmds[sArithBase.nCmdUsed].name = omStrDup(szName);
9126  sArithBase.sCmds[sArithBase.nCmdUsed].alias = nAlias;
9127  sArithBase.sCmds[sArithBase.nCmdUsed].tokval = nTokval;
9128  sArithBase.sCmds[sArithBase.nCmdUsed].toktype = nToktype;
9129  sArithBase.nCmdUsed++;
9130 
9131  qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames),
9132  (&_gentable_sort_cmds));
9133  for(sArithBase.nLastIdentifier=sArithBase.nCmdUsed-1;
9134  sArithBase.nLastIdentifier>0; sArithBase.nLastIdentifier--)
9135  {
9136  if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
9137  }
9138  //Print("L=%d\n", sArithBase.nLastIdentifier);
9139  }
9140  return 0;
9141 }
9142 
9143 static BOOLEAN check_valid(const int p, const int op)
9144 {
9145  #ifdef HAVE_PLURAL
9146  if (rIsPluralRing(currRing))
9147  {
9148  if ((p & PLURAL_MASK)==0 /*NO_PLURAL*/)
9149  {
9150  WerrorS("not implemented for non-commutative rings");
9151  return TRUE;
9152  }
9153  else if ((p & PLURAL_MASK)==2 /*, COMM_PLURAL */)
9154  {
9155  Warn("assume commutative subalgebra for cmd `%s`",Tok2Cmdname(op));
9156  return FALSE;
9157  }
9158  /* else, ALLOW_PLURAL */
9159  }
9160  #endif
9161  if (rField_is_Ring(currRing))
9162  {
9163  if ((p & RING_MASK)==0 /*NO_RING*/)
9164  {
9165  WerrorS("not implemented for rings with rings as coeffients");
9166  return TRUE;
9167  }
9168  /* else ALLOW_RING */
9169  else if (((p & ZERODIVISOR_MASK)==NO_ZERODIVISOR)
9170  &&(!rField_is_Domain(currRing)))
9171  {
9172  WerrorS("domain required as coeffients");
9173  return TRUE;
9174  }
9175  /* else ALLOW_ZERODIVISOR */
9176  else if(((p & WARN_RING)==WARN_RING)&&(myynest==0))
9177  {
9178  WarnS("considering the image in Q[...]");
9179  }
9180  }
9181  return FALSE;
9182 }
9183 // --------------------------------------------------------------------
9185 {
9186  coeffs cf;
9187  lists c=(lists)u->CopyD(); // list of ideal or bigint/int
9188  int rl=c->nr+1;
9189  int return_type=c->m[0].Typ();
9190  if ((return_type!=IDEAL_CMD)
9191  && (return_type!=MODUL_CMD)
9192  && (return_type!=MATRIX_CMD)
9193  && (return_type!=POLY_CMD))
9194  {
9195  if((return_type==BIGINT_CMD)
9196  ||(return_type==INT_CMD))
9197  return_type=BIGINT_CMD;
9198  else if (return_type==LIST_CMD)
9199  {
9200  // create a tmp list of the correct size
9201  lists res_l=(lists)omAllocBin(slists_bin);
9202  res_l->Init(rl /*c->nr+1*/);
9203  BOOLEAN bo=FALSE;
9204  int tab_pos=iiTabIndex(dArithTab2,JJTAB2LEN,CHINREM_CMD);
9205  for (unsigned i=0;i<=(unsigned)c->nr;i++)
9206  {
9207  sleftv tmp;
9208  tmp.Copy(v);
9209  bo=iiExprArith2TabIntern(&res_l->m[i],&c->m[i],CHINREM_CMD,&tmp,TRUE,dArith2+tab_pos,c->m[i].rtyp,tmp.rtyp,dConvertTypes);
9210  if (bo) { Werror("chinrem failed for list entry %d",i+1); break;}
9211  }
9212  c->Clean();
9213  res->data=res_l;
9214  res->rtyp=LIST_CMD;
9215  return bo;
9216  }
9217  else
9218  {
9219  c->Clean();
9220  WerrorS("poly/ideal/module/matrix/list expected");
9221  return TRUE;
9222  }
9223  }
9224  if (return_type==BIGINT_CMD)
9225  cf=coeffs_BIGINT;
9226  else
9227  {
9228  cf=currRing->cf;
9229  if (nCoeff_is_Extension(cf) && (cf->extRing!=NULL))
9230  cf=cf->extRing->cf;
9231  }
9232  lists pl=NULL;
9233  intvec *p=NULL;
9234  if (v->Typ()==LIST_CMD) pl=(lists)v->Data();
9235  else p=(intvec*)v->Data();
9236  ideal result;
9237  ideal *x=(ideal *)omAlloc(rl*sizeof(ideal));
9238  number *xx=NULL;
9239  nMapFunc nMap=n_SetMap(coeffs_BIGINT,cf);
9240  int i;
9241  if (return_type!=BIGINT_CMD)
9242  {
9243  for(i=rl-1;i>=0;i--)
9244  {
9245  if (c->m[i].Typ()!=return_type)
9246  {
9247  Werror("%s expected at pos %d",Tok2Cmdname(return_type),i+1);
9248  omFree(x); // delete c
9249  return TRUE;
9250  }
9251  if (return_type==POLY_CMD)
9252  {
9253  x[i]=idInit(1,1);
9254  x[i]->m[0]=(poly)c->m[i].CopyD();
9255  }
9256  else
9257  {
9258  x[i]=(ideal)c->m[i].CopyD();
9259  }
9260  //c->m[i].Init();
9261  }
9262  }
9263  else
9264  {
9265  if (nMap==NULL)
9266  {
9267  Werror("not implemented: map bigint -> %s", nCoeffString(cf));
9268  return TRUE;
9269  }
9270  xx=(number *)omAlloc(rl*sizeof(number));
9271  for(i=rl-1;i>=0;i--)
9272  {
9273  if (c->m[i].Typ()==INT_CMD)
9274  {
9275  xx[i]=n_Init(((int)(long)c->m[i].Data()),cf);
9276  }
9277  else if (c->m[i].Typ()==BIGINT_CMD)
9278  {
9279  xx[i]=nMap((number)c->m[i].Data(),coeffs_BIGINT,cf);
9280  }
9281  else
9282  {
9283  Werror("bigint expected at pos %d",i+1);
9284  omFree(x); // delete c
9285  omFree(xx); // delete c
9286  return TRUE;
9287  }
9288  }
9289  }
9290  number *q=(number *)omAlloc(rl*sizeof(number));
9291  if (p!=NULL)
9292  {
9293  for(i=rl-1;i>=0;i--)
9294  {
9295  q[i]=n_Init((*p)[i], cf);
9296  }
9297  }
9298  else
9299  {
9300  for(i=rl-1;i>=0;i--)
9301  {
9302  if (pl->m[i].Typ()==INT_CMD)
9303  {
9304  q[i]=n_Init((int)(long)pl->m[i].Data(),cf);
9305  }
9306  else if (pl->m[i].Typ()==BIGINT_CMD)
9307  {
9308  q[i]=nMap((number)(pl->m[i].Data()),coeffs_BIGINT,cf);
9309  }
9310  else
9311  {
9312  Werror("bigint expected at pos %d",i+1);
9313  for(i++;i<rl;i++)
9314  {
9315  n_Delete(&(q[i]),cf);
9316  }
9317  omFree(x); // delete c
9318  omFree(q); // delete pl
9319  if (xx!=NULL) omFree(xx); // delete c
9320  return TRUE;
9321  }
9322  }
9323  }
9324  if (return_type==BIGINT_CMD)
9325  {
9326  CFArray i_v(rl);
9327  number n=n_ChineseRemainderSym(xx,q,rl,TRUE,i_v,coeffs_BIGINT);
9328  res->data=(char *)n;
9329  }
9330  else
9331  {
9332  result=id_ChineseRemainder(x,q,rl,currRing); // deletes also x
9333  c->Clean();
9334  if ((return_type==POLY_CMD) &&(result!=NULL))
9335  {
9336  res->data=(char *)result->m[0];
9337  result->m[0]=NULL;
9338  idDelete(&result);
9339  }
9340  else
9341  res->data=(char *)result;
9342  }
9343  for(i=rl-1;i>=0;i--)
9344  {
9345  n_Delete(&(q[i]),cf);
9346  }
9347  omFree(q);
9348  res->rtyp=return_type;
9349  return result==NULL;
9350 }
9352 {
9353  lists c=(lists)u->CopyD();
9354  lists res_l=(lists)omAllocBin(slists_bin);
9355  res_l->Init(c->nr+1);
9356  BOOLEAN bo=FALSE;
9357  int tab_pos=iiTabIndex(dArithTab2,JJTAB2LEN,FAREY_CMD);
9358  for (unsigned i=0;i<=(unsigned)c->nr;i++)
9359  {
9360  sleftv tmp;
9361  tmp.Copy(v);
9362  bo=iiExprArith2TabIntern(&res_l->m[i],&c->m[i],FAREY_CMD,&tmp,TRUE,dArith2+tab_pos,c->m[i].rtyp,tmp.rtyp,dConvertTypes);
9363  if (bo) { Werror("farey failed for list entry %d",i+1); break;}
9364  }
9365  c->Clean();
9366  res->data=res_l;
9367  return bo;
9368 }
9369 // --------------------------------------------------------------------
9370 static int jjCOMPARE_ALL(const void * aa, const void * bb)
9371 {
9372  leftv a=(leftv)aa;
9373  int at=a->Typ();
9374  leftv b=(leftv)bb;
9375  int bt=b->Typ();;
9376  if (at < bt) return -1;
9377  if (at > bt) return 1;
9378  int tab_pos=iiTabIndex(dArithTab2,JJTAB2LEN,'<');
9379  sleftv tmp;
9380  memset(&tmp,0,sizeof(sleftv));
9381  iiOp='<';
9382  BOOLEAN bo=iiExprArith2TabIntern(&tmp,a,'<',b,FALSE,dArith2+tab_pos,at,bt,dConvertTypes);
9383  if (bo)
9384  {
9385  Werror(" no `<` for %s",Tok2Cmdname(at));
9386  unsigned long ad=(unsigned long)a->Data();
9387  unsigned long bd=(unsigned long)b->Data();
9388  if (ad<bd) return -1;
9389  else if (ad==bd) return 0;
9390  else return 1;
9391  }
9392  else if (tmp.data==NULL) /* not < */
9393  {
9394  iiOp=EQUAL_EQUAL;
9395  tab_pos=iiTabIndex(dArithTab2,JJTAB2LEN,EQUAL_EQUAL);
9396  bo=iiExprArith2TabIntern(&tmp,a,EQUAL_EQUAL,b,FALSE,dArith2+tab_pos,at,bt,dConvertTypes);
9397  if (bo)
9398  {
9399  Werror(" no `==` for %s",Tok2Cmdname(at));
9400  unsigned long ad=(unsigned long)a->Data();
9401  unsigned long bd=(unsigned long)b->Data();
9402  if (ad<bd) return -1;
9403  else if (ad==bd) return 0;
9404  else return 1;
9405  }
9406  else if (tmp.data==NULL) /* not <,== */ return 1;
9407  else return 0;
9408  }
9409  else return -1;
9410 }
9412 {
9413  lists l=(lists)arg->Data();
9414  if (l->nr>0)
9415  {
9416  qsort(l->m,l->nr+1,sizeof(sleftv),jjCOMPARE_ALL);
9417  }
9418  return FALSE;
9419 }
9421 {
9422  lists l=(lists)arg->Data();
9423  if (l->nr>0)
9424  {
9425  qsort(l->m,l->nr+1,sizeof(sleftv),jjCOMPARE_ALL);
9426  int i, j, len;
9427  len=l->nr;
9428  i=0;
9429  while(i<len)
9430  {
9431  if(jjCOMPARE_ALL(&(l->m[i]),&(l->m[i+1]))==0)
9432  {
9433  l->m[i].CleanUp();
9434  for(j=i; j<len;j++) l->m[j]=l->m[j+1];
9435  memset(&(l->m[len]),0,sizeof(sleftv));
9436  l->m[len].rtyp=DEF_CMD;
9437  len--;
9438  }
9439  else
9440  i++;
9441  }
9442  //Print("new len:%d\n",len);
9443  }
9444  return FALSE;
9445 }
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:750
static BOOLEAN jjINTMAT3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5877
#define idPosConstant(I)
index of generator with leading term in ground ring (if any); otherwise -1
Definition: ideals.h:37
int compare(const intvec *o) const
Definition: intvec.cc:207
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of &#39;a&#39; and &#39;b&#39;, i.e., a-b
Definition: coeffs.h:673
int iiInitArithmetic()
initialisation of arithmetic structured data
Definition: iparith.cc:8954
int & rows()
Definition: matpol.h:24
matrix idDiff(matrix i, int k)
Definition: ideals.cc:1903
static BOOLEAN jjBREAK0(leftv, leftv)
Definition: iparith.cc:6599
static BOOLEAN jjPLUS_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:762
static BOOLEAN jjE(leftv res, leftv v)
Definition: iparith.cc:4000
static BOOLEAN jjPAR1(leftv res, leftv v)
Definition: iparith.cc:4598
#define pSubst(p, n, e)
Definition: polys.h:348
static BOOLEAN jjRANK2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2890
static BOOLEAN jjIDEAL_PL(leftv res, leftv v)
Definition: iparith.cc:6762
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:3426
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
ideal singclap_sqrfree(poly f, intvec **v, int with_exps, const ring r)
Definition: clapsing.cc:1155
static void jjEQUAL_REST(leftv res, leftv u, leftv v)
Definition: iparith.cc:1347
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:3896
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:3203
static BOOLEAN jjPLUSMINUS_Gen(leftv res, leftv u, leftv v)
Definition: iparith.cc:638
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:991
static FORCE_INLINE number n_IntMod(number a, number b, const coeffs r)
for r a field, return n_Init(0,r) always: n_Div(a,b,r)*b+n_IntMod(a,b,r)==a n_IntMod(a,b,r) >=0
Definition: coeffs.h:632
matrix mp_CoeffProc(poly f, poly vars, const ring R)
Definition: matpol.cc:413
static FORCE_INLINE number n_GetNumerator(number &n, const coeffs r)
return the numerator of n (if elements of r are by nature not fractional, result is n) ...
Definition: coeffs.h:612
static BOOLEAN jjBI2IM(leftv res, leftv u)
Definition: iparith.cc:3653
static BOOLEAN jjOP_BI_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:286
void id_Normalize(ideal I, const ring r)
normialize all polys in id
static FORCE_INLINE number n_Gcd(number a, number b, const coeffs r)
in Z: return the gcd of &#39;a&#39; and &#39;b&#39; in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ...
Definition: coeffs.h:690
#define WARN_RING
Definition: iparith.cc:123
static BOOLEAN jjFAC_P(leftv res, leftv u)
Definition: iparith.cc:4061
#define idMaxIdeal(D)
initialise the maximal ideal (at 0)
Definition: ideals.h:33
const CanonicalForm int s
Definition: facAbsFact.cc:55
void id_DelDiv(ideal id, const ring r)
delete id[j], if LT(j) == coeff*mon*LT(i) and vice versa, i.e., delete id[i], if LT(i) == coeff*mon*L...
unsigned si_opt_1
Definition: options.c:5
#define pVar(m)
Definition: polys.h:364
This file provides miscellaneous functionality.
ring rEnvelope(ring R)
Definition: ring.cc:5478
static BOOLEAN jjCALL2ARG(leftv res, leftv u)
Definition: iparith.cc:6627
resolvente syResolvente(ideal arg, int maxlength, int *length, intvec ***weights, BOOLEAN minim)
Definition: syz.cc:394
static BOOLEAN iiExprArith3TabIntern(leftv res, int op, leftv a, leftv b, leftv c, const struct sValCmd3 *dA3, int at, int bt, int ct, const struct sConvertTypes *dConvertTypes)
Definition: iparith.cc:8391
syStrategy syKosz(ideal arg, int *length)
Definition: syz3.cc:1764
int iiTestConvert(int inputType, int outputType)
Definition: gentable.cc:293
static BOOLEAN jjREPART(leftv res, leftv v)
Definition: iparith.cc:4753
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:6543
static BOOLEAN jjRSUM(leftv res, leftv u, leftv v)
Definition: iparith.cc:3196
ideal id_Transp(ideal a, const ring rRing)
transpose a module
static BOOLEAN jjVAR1(leftv res, leftv v)
Definition: iparith.cc:5108
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:2307
poly pSubstPoly(poly p, int var, poly image)
Definition: maps_ip.cc:390
void atSet(idhdl root, const char *name, void *data, int typ)
Definition: attrib.cc:156
Definition: tok.h:143
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
static BOOLEAN jjTEST(leftv, leftv v)
Definition: iparith.cc:7621
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition: kstd1.cc:2971
ideal id_Homogen(ideal h, int varnum, const ring r)
#define pSetm(p)
Definition: polys.h:253
char * rVarStr(ring r)
Definition: ring.cc:594
static int _gentable_sort_cmds(const void *a, const void *b)
compares to entry of cmdsname-list
Definition: iparith.cc:8917
ip_command * command
Definition: ipid.h:24
static FORCE_INLINE BOOLEAN n_IsUnit(number n, const coeffs r)
TRUE iff n has a multiplicative inverse in the given coeff field/ring r.
Definition: coeffs.h:519
static BOOLEAN jjPARDEG(leftv res, leftv v)
Definition: iparith.cc:4614
static BOOLEAN jjRING_2(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5643
number ntDiff(number a, number d, const coeffs cf)
Definition: transext.cc:811
static BOOLEAN jjTIMES_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:915
const poly a
Definition: syzextra.cc:212
Definition: tok.h:108
static BOOLEAN jjLOAD_E(leftv, leftv v, leftv u)
Definition: iparith.cc:2525
void PrintLn()
Definition: reporter.cc:310
static BOOLEAN jjJET_ID_M(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5914
#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:3399
#define Print
Definition: emacs.cc:83
static BOOLEAN jjCOMPARE_S(leftv res, leftv u, leftv v)
Definition: iparith.cc:487
CanonicalForm fp
Definition: cfModGcd.cc:4043
static BOOLEAN jjnInt(leftv res, leftv u)
Definition: iparith.cc:5369
static BOOLEAN jjLIFT(leftv res, leftv u, leftv v)
Definition: iparith.cc:2501
BOOLEAN jjSORTLIST(leftv, leftv arg)
Definition: iparith.cc:9411
void omPrintInfo(FILE *fd)
Definition: omStats.c:129
bigintmat * bimSub(bigintmat *a, bigintmat *b)
Definition: bigintmat.cc:219
static BOOLEAN jjPLUS_MA(leftv res, leftv u, leftv v)
Definition: iparith.cc:809
Definition: tok.h:95
#define TEST_OPT_DEGBOUND
Definition: options.h:108
static BOOLEAN jjKERNEL(leftv res, leftv u, leftv v)
Definition: iparith.cc:2485
static BOOLEAN jjCOMPARE_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:349
#define pAdd(p, q)
Definition: polys.h:186
static BOOLEAN jjPLUS_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:799
static BOOLEAN jjSQR_FREE(leftv res, leftv u)
Definition: iparith.cc:4953
static BOOLEAN jjPFAC1(leftv res, leftv v)
Definition: iparith.cc:4440
number det()
det (via LaPlace in general, hnf for euc. rings)
Definition: bigintmat.cc:1522
static BOOLEAN jjTIMES_MA_BI2(leftv res, leftv u, leftv v)
Definition: iparith.cc:1033
static BOOLEAN jjKBASE2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2472
static BOOLEAN jjHILBERT2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2305
static BOOLEAN jjJET_P_IV(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5891
ideal id_Subst(ideal id, int n, poly e, const ring r)
#define SIMPL_MULT
Definition: iparith.cc:3205
ideal idSubstPar(ideal id, int n, poly e)
Definition: maps_ip.cc:373
static BOOLEAN jjMULT(leftv res, leftv v)
Definition: iparith.cc:4527
static BOOLEAN jjSUBST_Id_I(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6361
static BOOLEAN jjPlural_mat_mat(leftv res, leftv a, leftv b)
Definition: iparith.cc:2762
#define pNSet(n)
Definition: polys.h:295
static BOOLEAN jjPOWER_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:632
Subexpr e
Definition: subexpr.h:106
#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:91
static BOOLEAN jjFACSTD(leftv res, leftv v)
Definition: iparith.cc:4021
static BOOLEAN jjTRANSP_IV(leftv res, leftv v)
Definition: iparith.cc:5018
static BOOLEAN jjCALL3ARG(leftv res, leftv u)
Definition: iparith.cc:6635
static BOOLEAN jjN2BI(leftv res, leftv v)
Definition: iparith.cc:4547
Definition: lists.h:22
static BOOLEAN jjCOUNT_N(leftv res, leftv v)
Definition: iparith.cc:3711
#define nNormalize(n)
Definition: numbers.h:30
static BOOLEAN jjGETDUMP(leftv, leftv v)
Definition: iparith.cc:4077
static BOOLEAN jjINTVEC_PL(leftv res, leftv v)
Definition: iparith.cc:7219
static BOOLEAN jjP2BI(leftv res, leftv v)
Definition: iparith.cc:4638
ideal_list kStdfac(ideal F, ideal Q, tHomog h, intvec **w, ideal D)
Definition: kstdfac.cc:808
static BOOLEAN jjTIMES_MA_P2(leftv res, leftv u, leftv v)
Definition: iparith.cc:1047
void idLiftW(ideal P, ideal Q, int n, matrix &T, ideal &R, short *w)
Definition: ideals.cc:1086
ideal interpolation(const std::vector< ideal > &L, intvec *v)
#define TEST_OPT_PROT
Definition: options.h:98
intvec * scIndIntvec(ideal S, ideal Q)
Definition: hdegree.cc:212
void henselFactors(const int xIndex, const int yIndex, const poly h, const poly f0, const poly g0, const int d, poly &f, poly &g)
Computes a factorization of a polynomial h(x, y) in K[[x]][y] up to a certain degree in x...
int ncols
Definition: matpol.h:22
#define pMaxComp(p)
Definition: polys.h:281
BOOLEAN mpKoszul(leftv res, leftv c, leftv b, leftv id)
Definition: ipshell.cc:2983
loop
Definition: myNF.cc:98
if(0 > strat->sl)
Definition: myNF.cc:73
const struct sConvertTypes dConvertTypes[]
Definition: table.h:1178
#define IDID(a)
Definition: ipid.h:119
static BOOLEAN jjCOUNT_M(leftv res, leftv v)
Definition: iparith.cc:3722
BOOLEAN iiExprArith1(leftv res, leftv a, int op)
Definition: iparith.cc:8333
static BOOLEAN rField_is_Ring_PtoM(const ring r)
Definition: ring.h:471
static int WerrorS_dummy_cnt
Definition: iparith.cc:5253
#define pSetExp(p, i, v)
Definition: polys.h:42
static int si_min(const int a, const int b)
Definition: auxiliary.h:121
int getRTimer()
Definition: timer.cc:172
static BOOLEAN jjRANDOM(leftv res, leftv u, leftv v)
Definition: iparith.cc:2882
static BOOLEAN jjOP_REST(leftv res, leftv u, leftv v)
Definition: iparith.cc:514
#define FALSE
Definition: auxiliary.h:94
unsigned nCmdAllocated
number of commands-slots allocated
Definition: iparith.cc:195
static BOOLEAN jjFAREY_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:2114
poly pHeadProc(poly p)
Definition: iparith.cc:235
matrix mp_InitP(int r, int c, poly p, const ring R)
make it a p * unit matrix
Definition: matpol.cc:123
ideal t_rep_gb(ring r, ideal arg_I, int syz_comp, BOOLEAN F4_mode)
Definition: tgb.cc:3558
Compatiblity layer for legacy polynomial operations (over currRing)
static BOOLEAN jjDIVMOD_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1155
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:5485
ideal kSba(ideal F, ideal Q, tHomog h, intvec **w, int sbaOrder, int arri, intvec *hilb, int syzComp, int newIdeal, intvec *vw)
Definition: kstd1.cc:2416
poly p_Homogen(poly p, int varnum, const ring r)
Definition: p_polys.cc:3153
static BOOLEAN jjL2R(leftv res, leftv v)
Definition: iparith.cc:4375
static BOOLEAN jjOpenClose(leftv, leftv v)
Definition: iparith.cc:4586
Definition: tok.h:38
short res
Definition: gentable.cc:65
static BOOLEAN jjMEMORY(leftv res, leftv v)
Definition: iparith.cc:4479
return P p
Definition: myNF.cc:203
Definition: tok.h:178
BOOLEAN jjWAIT1ST1(leftv res, leftv u)
Definition: iparith.cc:5148
int exprlist_length(leftv v)
Definition: ipshell.cc:544
ideal id_Copy(ideal h1, const ring r)
copy an ideal
short * iv2array(intvec *iv, const ring R)
Definition: weight.cc:208
Definition: mod_raw.h:16
Matrices of numbers.
Definition: bigintmat.h:51
f
Definition: cfModGcd.cc:4022
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:1781
BOOLEAN iiExprArith3(leftv res, int op, leftv a, leftv b, leftv c)
Definition: iparith.cc:8548
static BOOLEAN jjCOLS(leftv res, leftv v)
Definition: iparith.cc:3683
static BOOLEAN rField_is_Ring_ModN(const ring r)
Definition: ring.h:468
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:326
#define nPower(a, b, res)
Definition: numbers.h:38
#define pLmCmp(p, q)
returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
Definition: polys.h:105
static BOOLEAN jjKLAMMER_rest(leftv res, leftv u, leftv v)
Definition: iparith.cc:1581
lists syConvRes(syStrategy syzstr, BOOLEAN toDel, int add_row_shift)
Definition: ipshell.cc:3073
static BOOLEAN jjALIGN_M(leftv res, leftv u, leftv v)
Definition: iparith.cc:1760
static BOOLEAN jjHOMOG1(leftv res, leftv v)
Definition: iparith.cc:4189
static BOOLEAN jjCHINREM_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1663
void omPrintBinStats(FILE *fd)
Definition: omBin.c:692
static BOOLEAN jjPLUS_MA_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:821
char * rParStr(ring r)
Definition: ring.cc:620
poly sm_CallDet(ideal I, const ring R)
Definition: sparsmat.cc:358
BOOLEAN idTestHomModule(ideal m, ideal Q, intvec *w)
Definition: ideals.cc:1834
static BOOLEAN jjGCD_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:2282
static BOOLEAN jjrVarStr(leftv res, leftv v)
Definition: iparith.cc:5344
static BOOLEAN jjPRIME(leftv res, leftv v)
Definition: iparith.cc:4676
static BOOLEAN jjMODULO(leftv res, leftv u, leftv v)
Definition: iparith.cc:2536
ideal id_ChineseRemainder(ideal *xx, number *q, int rl, const ring r)
static BOOLEAN jjROWS(leftv res, leftv v)
Definition: iparith.cc:4779
static BOOLEAN jjDET_BI(leftv res, leftv v)
Definition: iparith.cc:3846
static BOOLEAN jjDUMP(leftv, leftv v)
Definition: iparith.cc:3986
int rows() const
Definition: bigintmat.h:146
static BOOLEAN jjPLUS_S(leftv res, leftv u, leftv v)
Definition: iparith.cc:836
BOOLEAN iiTryLoadLib(leftv v, const char *id)
Definition: iplib.cc:656
static BOOLEAN jjBRACK_Bim(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5428
poly mp_Trace(matrix a, const ring R)
Definition: matpol.cc:288
static BOOLEAN jjCOEF(leftv res, leftv u, leftv v)
Definition: iparith.cc:1774
Definition: tok.h:213
static BOOLEAN jjREDUCE3_ID(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6497
static BOOLEAN jjTIMES_MA_I2(leftv res, leftv u, leftv v)
Definition: iparith.cc:1075
static BOOLEAN jjJACOB_M(leftv res, leftv a)
Definition: iparith.cc:4347
static BOOLEAN jjnlInt(leftv res, leftv u)
Definition: iparith.cc:5376
static BOOLEAN jjIS_RINGVAR0(leftv res, leftv)
Definition: iparith.cc:4311
sleftv iiRETURNEXPR
Definition: iplib.cc:471
static BOOLEAN jjINTERRED(leftv res, leftv v)
Definition: iparith.cc:4291
rational (GMP) numbers
Definition: coeffs.h:31
static BOOLEAN jjMINUS_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:867
static BOOLEAN jjSTD_1(leftv res, leftv u, leftv v)
Definition: iparith.cc:3338
static BOOLEAN jjDOTDOT(leftv res, leftv u, leftv v)
Definition: iparith.cc:343
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:3534
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:542
#define pIsUnit(p)
return true if the Lm is a constant <>0
Definition: polys.h:223
static BOOLEAN jjCONTENT(leftv res, leftv v)
Definition: iparith.cc:3698
static BOOLEAN jjFAC_P2(leftv res, leftv u, leftv dummy)
Definition: iparith.cc:2045
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
int rows() const
Definition: intvec.h:88
static BOOLEAN jjREAD2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2899
static BOOLEAN jjKLAMMER_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1553
#define idSimpleAdd(A, B)
Definition: ideals.h:42
matrix idDiffOp(ideal I, ideal J, BOOLEAN multiply)
Definition: ideals.cc:1916
int singclap_det_i(intvec *m, const ring)
Definition: clapsing.cc:1602
static BOOLEAN jjpHead(leftv res, leftv v)
Definition: iparith.cc:5301
Definition: grammar.cc:270
static BOOLEAN jjCOLON(leftv res, leftv u, leftv v)
Definition: iparith.cc:330
static BOOLEAN jjPARSTR2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2685
int rChar(ring r)
Definition: ring.cc:684
static BOOLEAN jjBI2N(leftv res, leftv u)
Definition: iparith.cc:3638
static BOOLEAN jjUMINUS_MA(leftv res, leftv u)
Definition: iparith.cc:3584
static BOOLEAN jjSUBST_Id_N(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6365
#define IDROOT
Definition: ipid.h:20
static BOOLEAN jjDIV_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:1204
ring rOpposite(ring src)
Definition: ring.cc:5150
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:1600
poly singclap_gcd(poly f, poly g, const ring r)
destroys f and g
Definition: clapsing.cc:287
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
void sdb_show_bp()
Definition: sdb.cc:58
#define pNeg(p)
Definition: polys.h:181
intvec * ivCopy(const intvec *o)
Definition: intvec.h:126
struct sValCmd1 * psValCmd1
Definition: iparith.cc:190
static BOOLEAN jjDEGREE(leftv res, leftv v)
Definition: iparith.cc:3766
bigintmat * bimAdd(bigintmat *a, bigintmat *b)
Matrix-Add/-Sub/-Mult so oder mit operator+/-/* ? : NULL as a result means an error (non-compatible m...
Definition: bigintmat.cc:183
BOOLEAN siq
Definition: subexpr.cc:58
static BOOLEAN jjINTERSECT_PL(leftv res, leftv v)
Definition: iparith.cc:6983
static BOOLEAN jjBREAK1(leftv, leftv v)
Definition: iparith.cc:6606
static BOOLEAN jjEXTGCD_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1999
#define SIMPL_EQU
Definition: iparith.cc:3206
const char sNoName[]
Definition: subexpr.cc:56
int listLength()
Definition: subexpr.cc:61
ideal getMinorIdealCache(const matrix mat, const int minorSize, const int k, const ideal iSB, const int cacheStrategy, const int cacheN, const int cacheW, const bool allDifferent)
Returns the specified set of minors (= subdeterminantes) of the given matrix.
long int64
Definition: auxiliary.h:66
static BOOLEAN jjPlural_mat_poly(leftv res, leftv a, leftv b)
Definition: iparith.cc:2742
static BOOLEAN jjNEWSTRUCT3(leftv, leftv u, leftv v, leftv w)
Definition: iparith.cc:6132
static BOOLEAN jjTRACE_IV(leftv res, leftv v)
Definition: iparith.cc:5008
#define pLmDelete(p)
assume p != NULL, deletes Lm(p)->coef and Lm(p)
Definition: polys.h:76
resolvente res
Definition: syz.h:47
static BOOLEAN jjGT_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1119
static BOOLEAN jjidFreeModule(leftv res, leftv v)
Definition: iparith.cc:5286
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:2439
#define TRUE
Definition: auxiliary.h:98
struct sValCmd1 dArith1[]
Definition: table.h:19
#define nIsOne(n)
Definition: numbers.h:25
lists qrDoubleShift(const matrix A, const number tol1, const number tol2, const number tol3, const ring r=currRing)
Computes all eigenvalues of a given real quadratic matrix with multiplicites.
lib_types type_of_LIB(const char *newlib, char *libnamebuf)
Definition: mod_lib.cc:24
static BOOLEAN jjMINUS_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:851
static BOOLEAN jjDUMMY(leftv res, leftv u)
Definition: iparith.cc:3529
ideal kStd(ideal F, ideal Q, tHomog h, intvec **w, intvec *hilb, int syzComp, int newIdeal, intvec *vw, s_poly_proc_t sp)
Definition: kstd1.cc:2231
syStrategy syResolution(ideal arg, int maxlength, intvec *w, BOOLEAN minim)
Definition: syz.cc:621
BOOLEAN maApplyFetch(int what, map theMap, leftv res, leftv w, ring preimage_r, int *perm, int *par_perm, int P, nMapFunc nMap)
Definition: maps_ip.cc:49
#define IDIDEAL(a)
Definition: ipid.h:130
ideal idMultSect(resolvente arg, int length)
Definition: ideals.cc:340
static BOOLEAN jjHILBERT_IV(leftv res, leftv v)
Definition: iparith.cc:4179
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1430
intvec * ivSub(intvec *a, intvec *b)
Definition: intvec.cc:280
int syDim(syStrategy syzstr)
Definition: syz1.cc:1857
#define pSplit(p, r)
Definition: polys.h:247
void Init()
Definition: subexpr.h:108
static BOOLEAN rField_is_Domain(const ring r)
Definition: ring.h:480
#define UNKNOWN
Definition: tok.h:217
int cmdtok
Definition: grammar.cc:174
static BOOLEAN jjEQUAL_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1309
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
Definition: coeffs.h:582
poly iiHighCorner(ideal I, int ak)
Definition: ipshell.cc:1481
void * ADDRESS
Definition: auxiliary.h:115
static BOOLEAN jjTIMES_MA_BI1(leftv res, leftv u, leftv v)
Definition: iparith.cc:1023
sleftv * leftv
Definition: structs.h:60
static BOOLEAN jjWEDGE(leftv res, leftv u, leftv v)
Definition: iparith.cc:3513
BOOLEAN iiExprArithM(leftv res, leftv a, int op)
Definition: iparith.cc:8638
poly singclap_det(const matrix m, const ring s)
Definition: clapsing.cc:1579
#define SI_SAVE_OPT1(A)
Definition: options.h:20
sValCmdTab jjValCmdTab[]
Definition: iparith.cc:136
static BOOLEAN jjPROC1(leftv res, leftv u)
Definition: iparith.cc:3604
intvec * ivTranp(intvec *o)
Definition: intvec.cc:310
#define PLURAL_MASK
Definition: iparith.cc:99
g
Definition: cfModGcd.cc:4031
static BOOLEAN jjDEG_M(leftv res, leftv u)
Definition: iparith.cc:3755
static BOOLEAN jjDIM_R(leftv res, leftv v)
Definition: iparith.cc:5359
void WerrorS(const char *s)
Definition: feFopen.cc:24
static BOOLEAN jjPROC3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5636
void omPrintStats(FILE *fd)
Definition: omStats.c:115
int k
Definition: cfEzgcd.cc:93
static BOOLEAN jjJanetBasis2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2451
static BOOLEAN jjOP_BIM_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:273
static BOOLEAN jjBRACK_Im(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5401
ideal idModulo(ideal h2, ideal h1, tHomog hom, intvec **w)
Definition: ideals.cc:1988
int min_in()
Definition: intvec.h:113
static BOOLEAN jjDIV_Ma(leftv res, leftv u, leftv v)
Definition: iparith.cc:1279
static intvec * idSort(ideal id, BOOLEAN nolex=TRUE)
Definition: ideals.h:169
static BOOLEAN jjNAMES0(leftv res, leftv)
Definition: iparith.cc:7438
static BOOLEAN rField_is_GF(const ring r)
Definition: ring.h:513
Definition: tok.h:119
static char const ** rParameter(const ring r)
(r->cf->parameter)
Definition: ring.h:616
int inerror
Definition: grammar.cc:175
static BOOLEAN jjTIMES_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:927
static BOOLEAN jjSTD(leftv res, leftv v)
Definition: iparith.cc:4922
static BOOLEAN jjJACOB_P(leftv res, leftv v)
Definition: iparith.cc:4316
static BOOLEAN jjpLength(leftv res, leftv v)
Definition: iparith.cc:5276
#define pLmFreeAndNext(p)
assumes p != NULL, deletes p, returns pNext(p)
Definition: polys.h:74
#define Q
Definition: sirandom.c:25
#define nEqual(n1, n2)
Definition: numbers.h:20
char * showOption()
Definition: misc_ip.cc:717
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:8130
static BOOLEAN jjJET_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:2462
syStrategy syConvList(lists li)
Definition: ipshell.cc:3146
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
Definition: monomials.h:51
static BOOLEAN jjGE_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1094
int traceit
Definition: febase.cc:47
#define pEqualPolys(p1, p2)
Definition: polys.h:383
#define WarnS
Definition: emacs.cc:81
static FORCE_INLINE int n_ParDeg(number n, const coeffs r)
Definition: coeffs.h:804
BOOLEAN jjLOAD(const char *s, BOOLEAN autoexport)
load lib/module given in v
Definition: iparith.cc:5194
static BOOLEAN jjP2N(leftv res, leftv v)
Definition: iparith.cc:4706
ideal idMinEmbedding(ideal arg, BOOLEAN inPlace, intvec **w)
Definition: ideals.cc:2297
#define BITSET
Definition: structs.h:18
static BOOLEAN jjGCD_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:2261
poly singclap_pdivide(poly f, poly g, const ring r)
Definition: clapsing.cc:547
coeffs coeffs_BIGINT
Definition: ipid.cc:54
int Typ()
Definition: subexpr.cc:996
#define omAlloc(size)
Definition: omAllocDecl.h:210
static BOOLEAN jjFAREY_LI(leftv res, leftv u, leftv v)
Definition: iparith.cc:9351
static BOOLEAN jjOPPOSE(leftv res, leftv a, leftv b)
Definition: iparith.cc:2801
static BOOLEAN jjSUBST_Id(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6317
static BOOLEAN jjPRUNE(leftv res, leftv v)
Definition: iparith.cc:4682
static BOOLEAN jjOP_I_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:269
ideal idQuot(ideal h1, ideal h2, BOOLEAN h1IsStb, BOOLEAN resultIsIdeal)
Definition: ideals.cc:1260
#define Sy_bit(x)
Definition: options.h:30
short res
Definition: gentable.cc:74
static BOOLEAN iiExprArith2TabIntern(leftv res, leftv a, int op, leftv b, BOOLEAN proccall, const struct sValCmd2 *dA2, int at, int bt, const struct sConvertTypes *dConvertTypes)
Definition: iparith.cc:7970
long(* pLDegProc)(poly p, int *length, ring r)
Definition: ring.h:45
static BOOLEAN jjINDEX_P_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1445
const char * Name()
Definition: subexpr.h:121
#define pGetComp(p)
Component.
Definition: polys.h:37
static BOOLEAN jjPARSTR1(leftv res, leftv v)
Definition: iparith.cc:4620
static BOOLEAN jjHOMOG1_W(leftv res, leftv v, leftv u)
Definition: iparith.cc:2406
static BOOLEAN jjGE_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1101
static int iiTabIndex(const jjValCmdTab dArithTab, const int len, const int op)
Definition: iparith.cc:8845
BOOLEAN iiExport(leftv v, int toLev)
Definition: ipshell.cc:1383
Definition: idrec.h:34
newstruct_desc newstructFromString(const char *s)
Definition: newstruct.cc:796
static BOOLEAN jjWAIT1ST2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3441
#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:3465
poly redNF(poly h, int &max_ind, int nonorm, kStrategy strat)
Definition: kstd2.cc:1654
static BOOLEAN jjMAP(leftv res, leftv u, leftv v)
Definition: iparith.cc:1636
omBin char_ptr_bin
Definition: ring.cc:55
const char * Fullname()
Definition: subexpr.h:126
static BOOLEAN jjKoszul_Id(leftv res, leftv u, leftv v)
Definition: iparith.cc:2493
static BOOLEAN jjMINUS_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:872
static BOOLEAN idIsZeroDim(ideal i)
Definition: ideals.h:161
#define ivTest(v)
Definition: intvec.h:149
static BOOLEAN jjCOMPARE_MA(leftv res, leftv u, leftv v)
Definition: iparith.cc:432
idhdl get(const char *s, int lev)
Definition: ipid.cc:91
#define SI_PROT_I
Definition: reporter.h:52
ideal idMinBase(ideal h1)
Definition: ideals.cc:45
void monitor(void *F, int mode)
Definition: febase.cc:72
matrix idCoeffOfKBase(ideal arg, ideal kbase, poly how)
Definition: ideals.cc:2231
bool found
Definition: facFactorize.cc:56
static BOOLEAN jjTIMES_MA_I1(leftv res, leftv u, leftv v)
Definition: iparith.cc:1069
static BOOLEAN jjP2I(leftv res, leftv v)
Definition: iparith.cc:4658
ideal id_JetW(ideal i, int d, intvec *iv, const ring R)
static BOOLEAN jjMINOR_M(leftv res, leftv v)
Definition: iparith.cc:5933
static BOOLEAN jjEXPORTTO(leftv, leftv u, leftv v)
Definition: iparith.cc:1973
char * String(void *d=NULL, BOOLEAN typed=FALSE, int dim=1)
Called for conversion to string (used by string(..), write(..),..)
Definition: subexpr.cc:752
int iiRegularity(lists L)
Definition: ipshell.cc:956
static FORCE_INLINE number n_Random(siRandProc p, number p1, number p2, const coeffs cf)
Definition: coeffs.h:983
static BOOLEAN jjUMINUS_BI(leftv res, leftv u)
Definition: iparith.cc:3560
void * data
Definition: subexpr.h:89
static BOOLEAN jjTIMES_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:1011
static BOOLEAN jjCOUNT_RES(leftv res, leftv v)
Definition: iparith.cc:5354
static BOOLEAN jjJanetBasis(leftv res, leftv v)
Definition: iparith.cc:2457
void printBlackboxTypes()
list all defined type (for debugging)
Definition: blackbox.cc:208
#define mflush()
Definition: reporter.h:57
static FORCE_INLINE number n_Param(const int iParameter, const coeffs r)
return the (iParameter^th) parameter as a NEW number NOTE: parameter numbering: 1..n_NumberOfParameters(...)
Definition: coeffs.h:817
static BOOLEAN jjVARSTR2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3428
static BOOLEAN jjLE_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1138
static BOOLEAN jjROWS_IV(leftv res, leftv v)
Definition: iparith.cc:4790
#define pIter(p)
Definition: monomials.h:44
int rSum(ring r1, ring r2, ring &sum)
Definition: ring.cc:1302
static BOOLEAN jjEQUAL_Ma(leftv res, leftv u, leftv v)
Definition: iparith.cc:1321
poly res
Definition: myNF.cc:322
static BOOLEAN jjBAREISS(leftv res, leftv v)
Definition: iparith.cc:3608
intvec * kHomW
Definition: kstd1.cc:2206
matrix mp_Transp(matrix a, const ring R)
Definition: matpol.cc:267
#define IDPACKAGE(a)
Definition: ipid.h:136
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of &#39;a&#39; and &#39;b&#39;, i.e., a*b
Definition: coeffs.h:640
static BOOLEAN jjWAITALL2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3465
static int jjCOMPARE_ALL(const void *aa, const void *bb)
Definition: iparith.cc:9370
int myynest
Definition: febase.cc:46
int scMultInt(ideal S, ideal Q)
Definition: hdegree.cc:799
#define M
Definition: sirandom.c:24
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:10
#define pGetExp(p, i)
Exponent.
Definition: polys.h:41
static BOOLEAN jjBRACK_Ma_IV_IV(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5585
#define V_SHOW_USE
Definition: options.h:50
#define IDTYP(a)
Definition: ipid.h:116
static void WerrorS_dummy(const char *)
Definition: iparith.cc:5254
static BOOLEAN jjCOUNT_IV(leftv res, leftv v)
Definition: iparith.cc:3728
static BOOLEAN jjRES3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6505
static BOOLEAN jjTIMES_MA_N1(leftv res, leftv u, leftv v)
Definition: iparith.cc:1057
static BOOLEAN jjRINGLIST_C(leftv res, leftv v)
Definition: iparith.cc:4765
static BOOLEAN jjSTATUS2L(leftv res, leftv u, leftv v)
Definition: iparith.cc:3294
static BOOLEAN check_valid(const int p, const int op)
Definition: iparith.cc:9143
static BOOLEAN jjPLUS_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:784
char * iiArithGetCmd(int nPos)
Definition: iparith.cc:9049
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:259
static BOOLEAN jjrCharStr(leftv res, leftv v)
Definition: iparith.cc:5296
static BOOLEAN jjKoszul(leftv res, leftv u, leftv v)
Definition: iparith.cc:2489
poly * m
Definition: matpol.h:19
static BOOLEAN jjBRACKET(leftv res, leftv a, leftv b)
Definition: iparith.cc:2782
const char * Tok2Cmdname(int tok)
Definition: iparith.cc:8868
BOOLEAN iiMake_proc(idhdl pn, package pack, sleftv *sl)
Definition: iplib.cc:501
static BOOLEAN jjINDEX_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:1428
int RingDependend(int t)
Definition: gentable.cc:23
Definition: tok.h:56
void luDecomp(const matrix aMat, matrix &pMat, matrix &lMat, matrix &uMat, const ring R)
LU-decomposition of a given (m x n)-matrix.
void id_Shift(ideal M, int s, const ring r)
long p_DegW(poly p, const short *w, const ring R)
Definition: p_polys.cc:689
char my_yylinebuf[80]
Definition: febase.cc:48
static BOOLEAN jjOP_BIM_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:254
int r_IsRingVar(const char *n, char **names, int N)
Definition: ring.cc:222
ideal idSect(ideal h1, ideal h2)
Definition: ideals.cc:201
static BOOLEAN jjREDUCE3_CID(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6478
static BOOLEAN jjIDEAL_Map(leftv res, leftv v)
Definition: iparith.cc:4246
static BOOLEAN jjSUBST_Test(leftv v, leftv w, int &ringvar, poly &monomexpr)
Definition: iparith.cc:6263
const ring r
Definition: syzextra.cc:208
static BOOLEAN jjIm2Iv(leftv res, leftv v)
Definition: iparith.cc:4273
static BOOLEAN jjSUBST_M(leftv res, leftv u)
Definition: iparith.cc:7803
static BOOLEAN jjLU_INVERSE(leftv res, leftv v)
Definition: iparith.cc:7057
static BOOLEAN jjHIGHCORNER_M(leftv res, leftv v)
Definition: iparith.cc:4098
BOOLEAN expected_parms
Definition: grammar.cc:173
static BOOLEAN jjINDEPSET2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2426
intvec * bim2iv(bigintmat *b)
Definition: bigintmat.cc:344
Coefficient rings, fields and other domains suitable for Singular polynomials.
static BOOLEAN jjLT_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1142
static BOOLEAN jjIMPART(leftv res, leftv v)
Definition: iparith.cc:4280
resolvente orderedRes
Definition: syz.h:48
static BOOLEAN jjLOAD1(leftv, leftv v)
Definition: iparith.cc:4429
ideal idSeries(int n, ideal M, matrix U, intvec *w)
Definition: ideals.cc:1886
intvec * kModW
Definition: kstd1.cc:2206
ideal idElimination(ideal h1, poly delVar, intvec *hilb)
Definition: ideals.cc:1353
#define FLAG_TWOSTD
Definition: ipid.h:107
static BOOLEAN jjSUBST_Id_X(leftv res, leftv u, leftv v, leftv w, int input_type)
Definition: iparith.cc:6369
static BOOLEAN jjREDUCE_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:2923
Definition: tok.h:77
#define TIMER_RESOLUTION
Definition: mod2.h:32
BOOLEAN jjWAITALL1(leftv res, leftv u)
Definition: iparith.cc:5163
void id_DelMultiples(ideal id, const ring r)
ideal id = (id[i]), c any unit if id[i] = c*id[j] then id[j] is deleted for j > i ...
Definition: intvec.h:14
#define pSub(a, b)
Definition: polys.h:269
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
void id_DelLmEquals(ideal id, const ring r)
Delete id[j], if Lm(j) == Lm(i) and both LC(j), LC(i) are units and j > i.
static FORCE_INLINE long n_Int(number &n, const coeffs r)
conversion of n to an int; 0 if not possible in Z/pZ: the representing int lying in (-p/2 ...
Definition: coeffs.h:551
const char * iiTwoOps(int t)
Definition: gentable.cc:253
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
poly p_One(const ring r)
Definition: p_polys.cc:1312
short cmd
Definition: iparith.cc:132
static BOOLEAN jjUMINUS_I(leftv res, leftv u)
Definition: iparith.cc:3567
matrix mp_Wedge(matrix a, int ar, const ring R)
Definition: matpol.cc:1663
static BOOLEAN jjWRONG(leftv, leftv)
Definition: iparith.cc:3520
BOOLEAN rComplete(ring r, int force)
this needs to be called whenever a new ring is created: new fields in ring are created (like VarOffse...
Definition: ring.cc:3351
static BOOLEAN jjMATRIX_Ma(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6415
static BOOLEAN jjMSTD(leftv res, leftv v)
Definition: iparith.cc:4512
BOOLEAN jjANY2LIST(leftv res, leftv v, int cnt)
leftv Next()
Definition: subexpr.h:137
int iiArithRemoveCmd(char *szName)
int nrows
Definition: matpol.h:21
tHomog
Definition: structs.h:37
int j
Definition: myNF.cc:70
static BOOLEAN jjUMINUS_P(leftv res, leftv u)
Definition: iparith.cc:3579
static BOOLEAN jjCOEFFS2_KB(leftv res, leftv u, leftv v)
Definition: iparith.cc:1792
static BOOLEAN jjmpTrace(leftv res, leftv v)
Definition: iparith.cc:5329
lists ipNameListLev(idhdl root, int lev)
Definition: ipid.cc:556
static BOOLEAN jjALIGN_V(leftv res, leftv u, leftv v)
Definition: iparith.cc:1750
Definition: tok.h:58
bigintmat * bimMult(bigintmat *a, bigintmat *b)
Definition: bigintmat.cc:256
const char * name
Definition: subexpr.h:88
void pSetDegProcs(ring r, pFDegProc new_FDeg, pLDegProc new_lDeg)
Definition: p_polys.cc:3496
static BOOLEAN jjEQUAL_R(leftv res, leftv u, leftv v)
Definition: iparith.cc:1327
Definition: tok.h:182
static BOOLEAN jjKLAMMER(leftv res, leftv u, leftv v)
Definition: iparith.cc:1540
#define pSetCompP(a, i)
Definition: polys.h:285
#define omFree(addr)
Definition: omAllocDecl.h:261
static long pTotaldegree(poly p)
Definition: polys.h:264
static BOOLEAN jjHOMOG_P_W(leftv res, leftv u, leftv v, leftv)
Definition: iparith.cc:5859
BOOLEAN setOption(leftv res, leftv v)
Definition: misc_ip.cc:575
omInfo_t om_Info
Definition: omStats.c:13
static BOOLEAN jjDIFF_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:1847
int scMult0Int(ideal S, ideal Q, const ring tailRing)
Definition: hdegree.cc:919
#define assume(x)
Definition: mod2.h:394
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:404
poly pSubstPar(poly p, int par, poly image)
Definition: maps_ip.cc:253
The main handler for Singular numbers which are suitable for Singular polynomials.
static FORCE_INLINE number n_Add(number a, number b, const coeffs r)
return the sum of &#39;a&#39; and &#39;b&#39;, i.e., a+b
Definition: coeffs.h:660
static BOOLEAN jjRPAR(leftv res, leftv v)
Definition: iparith.cc:4795
static BOOLEAN jjERROR(leftv, leftv u)
Definition: iparith.cc:1978
static BOOLEAN jjVDIM(leftv res, leftv v)
Definition: iparith.cc:5142
static BOOLEAN jjEQUAL_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1333
static BOOLEAN jjJET4(leftv res, leftv u)
Definition: iparith.cc:7252
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:311
#define nInpNeg(n)
Definition: numbers.h:21
static BOOLEAN jjLEADEXP(leftv res, leftv v)
Definition: iparith.cc:4396
Definition: tok.h:180
int scDimInt(ideal S, ideal Q)
Definition: hdegree.cc:72
static BOOLEAN jjSLIM_GB(leftv res, leftv u)
Definition: iparith.cc:4800
matrix mp_MultI(matrix a, int f, const ring R)
c = f*a
Definition: matpol.cc:145
proc2 p
Definition: iparith.cc:159
#define pLmInit(p)
like pInit, except that expvector is initialized to that of p, p must be != NULL
Definition: polys.h:64
#define pDivideM(a, b)
Definition: polys.h:276
static BOOLEAN jjDIVISION4(leftv res, leftv v)
Definition: iparith.cc:6662
static BOOLEAN jjKBASE(leftv res, leftv v)
Definition: iparith.cc:4369
#define A
Definition: sirandom.c:23
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:73
#define nMult(n1, n2)
Definition: numbers.h:17
static FORCE_INLINE BOOLEAN n_DivBy(number a, number b, const coeffs r)
test whether &#39;a&#39; is divisible &#39;b&#39;; for r encoding a field: TRUE iff &#39;b&#39; does not represent zero in Z:...
Definition: coeffs.h:787
static FORCE_INLINE number n_ChineseRemainderSym(number *a, number *b, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs r)
Definition: coeffs.h:798
static BOOLEAN jjVARSTR1(leftv res, leftv v)
Definition: iparith.cc:5125
static BOOLEAN jjREDUCE5(leftv res, leftv u)
Definition: iparith.cc:7517
pNormalize(P.p)
static BOOLEAN jjELIMIN(leftv res, leftv u, leftv v)
Definition: iparith.cc:1953
static BOOLEAN jjSTD_HILB_W(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6557
const ring R
Definition: DebugPrint.cc:36
static BOOLEAN jjLIFT3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6441
BOOLEAN sm_CheckDet(ideal I, int d, BOOLEAN sw, const ring r)
Definition: sparsmat.cc:307
static BOOLEAN jjMONOM(leftv res, leftv v)
Definition: iparith.cc:2653
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:934
BOOLEAN jjUNIQLIST(leftv, leftv arg)
Definition: iparith.cc:9420
static BOOLEAN jjMOD_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:2585
static BOOLEAN jjBRACK_Ma_IV_I(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5535
long kHomModDeg(poly p, ring r)
Definition: kstd1.cc:2218
Definition: grammar.cc:269
struct sValCmd3 dArith3[]
Definition: table.h:715
static BOOLEAN jjPREIMAGE(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6142
void makeVector()
Definition: intvec.h:94
static BOOLEAN jjKLAMMER_PL(leftv res, leftv u)
Definition: iparith.cc:7335
omBin sSubexpr_bin
Definition: subexpr.cc:49
ideal kInterRed(ideal F, ideal Q)
Definition: kstd1.cc:3542
ideal id_Power(ideal given, int exp, const ring r)
#define SIMPL_NORM
Definition: iparith.cc:3208
BOOLEAN(* proc3)(leftv, leftv, leftv, leftv)
Definition: iparith.cc:167
static BOOLEAN jjSTATUS_M(leftv res, leftv v)
Definition: iparith.cc:7772
static BOOLEAN jjDEG_M_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1811
ip_smatrix * matrix
static BOOLEAN jjDET(leftv res, leftv v)
Definition: iparith.cc:3831
BOOLEAN jjLOAD_TRY(const char *s)
Definition: iparith.cc:5258
static BOOLEAN jjSUBST_P(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6291
static BOOLEAN jjLIFTSTD(leftv res, leftv u, leftv v)
Definition: iparith.cc:2511
static BOOLEAN jjRES(leftv res, leftv u, leftv v)
Definition: iparith.cc:3050
static BOOLEAN jjINDEX_V_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1504
static BOOLEAN jjSTRING_PL(leftv res, leftv v)
Definition: iparith.cc:7587
static BOOLEAN jjRANK1(leftv res, leftv v)
Definition: iparith.cc:4737
static BOOLEAN jjHOMOG_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:2367
idhdl currRingHdl
Definition: ipid.cc:65
static BOOLEAN jjDIV_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1191
void Copy(leftv e)
Definition: subexpr.cc:689
BOOLEAN idInsertPoly(ideal h1, poly h2)
insert h2 into h1 (if h2 is not the zero polynomial) return TRUE iff h2 was indeed inserted ...
#define setFlag(A, F)
Definition: ipid.h:110
static BOOLEAN jjEXTGCD_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:2028
int cols() const
Definition: bigintmat.h:145
static BOOLEAN jjLEADCOEF(leftv res, leftv v)
Definition: iparith.cc:4383
#define pSetComp(p, v)
Definition: polys.h:38
static BOOLEAN jjSBA_2(leftv res, leftv v, leftv u, leftv t)
Definition: iparith.cc:4896
struct sValCmd2 * psValCmd2
Definition: iparith.cc:191
#define pJet(p, m)
Definition: polys.h:350
int m
Definition: cfEzgcd.cc:119
BOOLEAN rSamePolyRep(ring r1, ring r2)
returns TRUE, if r1 and r2 represents the monomials in the same way FALSE, otherwise this is an analo...
Definition: ring.cc:1675
static FORCE_INLINE number n_InpNeg(number n, const coeffs r)
in-place negation of n MUST BE USED: n = n_InpNeg(n) (no copy is returned)
Definition: coeffs.h:561
short ref
Definition: idrec.h:46
#define pIsConstant(p)
like above, except that Comp might be != 0
Definition: polys.h:221
static BOOLEAN jjSBA(leftv res, leftv v)
Definition: iparith.cc:4844
void hnf()
transforms INPLACE to HNF
Definition: bigintmat.cc:1670
ring rDefault(const coeffs cf, int N, char **n, int ord_size, int *ord, int *block0, int *block1, int **wvhdl)
Definition: ring.cc:113
static BOOLEAN jjREGULARITY(leftv res, leftv v)
Definition: iparith.cc:4748
BOOLEAN jjStdJanetBasis(leftv res, leftv v, int flag)
flag: 0: JB, 1: SB
Definition: wrapper.cc:52
#define nSub(n1, n2)
Definition: numbers.h:22
matrix pMultMp(poly p, matrix a, const ring R)
Definition: matpol.cc:175
static BOOLEAN jjDEFINED(leftv res, leftv v)
Definition: iparith.cc:3802
static BOOLEAN jjidVec2Ideal(leftv res, leftv v)
Definition: iparith.cc:5291
struct sValCmdM * psValCmdM
Definition: iparith.cc:193
static int si_max(const int a, const int b)
Definition: auxiliary.h:120
static BOOLEAN jjGE_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1106
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
Definition: coeffs.h:935
static BOOLEAN jjREDUCE_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:2915
idrec * idhdl
Definition: ring.h:18
#define ZERODIVISOR_MASK
Definition: iparith.cc:106
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:877
int p_Compare(const poly a, const poly b, const ring R)
Definition: p_polys.cc:4713
BOOLEAN assumeStdFlag(leftv h)
Definition: subexpr.cc:1475
static BOOLEAN jjOP_I_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:307
static BOOLEAN jjFAREY_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:2125
static BOOLEAN jjRESERVED0(leftv, leftv)
Definition: iparith.cc:7566
omBin sleftv_bin
Definition: subexpr.cc:50
int i
Definition: cfEzgcd.cc:123
ring rInit(leftv pn, leftv rv, leftv ord)
Definition: ipshell.cc:5488
static BOOLEAN jjENVELOPE(leftv res, leftv a)
Definition: iparith.cc:5039
static BOOLEAN jjPFAC2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3170
void PrintS(const char *s)
Definition: reporter.cc:284
static BOOLEAN jjDEG_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1822
lib_types
Definition: mod_raw.h:16
static BOOLEAN jjRINGLIST(leftv res, leftv v)
Definition: iparith.cc:4758
lists ipNameList(idhdl root)
Definition: ipid.cc:533
static BOOLEAN rField_is_Q(const ring r)
Definition: ring.h:501
static BOOLEAN jjCALL1ARG(leftv res, leftv v)
Definition: iparith.cc:6623
static BOOLEAN jjLOAD2(leftv, leftv, leftv v)
Definition: iparith.cc:2521
static BOOLEAN jjidTransp(leftv res, leftv v)
Definition: iparith.cc:5364
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos=-1)
Definition: iparith.cc:9084
lists rDecompose(const ring r)
Definition: ipshell.cc:2010
static long p_MinComp(poly p, ring lmRing, ring tailRing)
Definition: p_polys.h:308
BOOLEAN load_builtin(const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
Definition: iplib.cc:1080
#define SIMPL_LMEQ
Definition: iparith.cc:3204
static BOOLEAN jjSTD_HILB(leftv res, leftv u, leftv v)
Definition: iparith.cc:3312
int IsPrime(int p)
Definition: prime.cc:61
#define SIMPL_NULL
Definition: iparith.cc:3207
static BOOLEAN jjidMinBase(leftv res, leftv v)
Definition: iparith.cc:5312
#define pOne()
Definition: polys.h:297
syStrategy sySchreyer(ideal arg, int maxlength)
Definition: syz0.cc:1024
BOOLEAN sdb_set_breakpoint(const char *pp, int given_lineno)
Definition: sdb.cc:65
static BOOLEAN jjBI2P(leftv res, leftv u)
Definition: iparith.cc:3659
int yyparse(void)
Definition: grammar.cc:2101
matrix id_Module2Matrix(ideal mod, const ring R)
resolvente sySchreyerResolvente(ideal arg, int maxlength, int *length, BOOLEAN isMonomial=FALSE, BOOLEAN notReplace=FALSE)
Definition: syz0.cc:861
static BOOLEAN jjDIM2(leftv res, leftv v, leftv w)
Definition: iparith.cc:1863
static BOOLEAN jjPOWER_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:576
static BOOLEAN jjUMINUS_N(leftv res, leftv u)
Definition: iparith.cc:3572
int sySize(syStrategy syzstr)
Definition: syz1.cc:1837
static BOOLEAN jjDIVISION(leftv res, leftv u, leftv v)
Definition: iparith.cc:1912
static BOOLEAN jjFWALK(leftv res, leftv u, leftv v)
Definition: iparith.cc:2255
static BOOLEAN jjREDUCE3_CP(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6466
static BOOLEAN jjINTERSECT(leftv res, leftv u, leftv v)
Definition: iparith.cc:2433
static unsigned pLength(poly a)
Definition: p_polys.h:189
struct sValCmd2 dArith2[]
Definition: table.h:292
static BOOLEAN jjREDUCE3_P(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6490
#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:5334
static BOOLEAN jjTYPEOF(leftv res, leftv v)
Definition: iparith.cc:5060
static BOOLEAN jjINDEX_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1370
#define IDELEMS(i)
Definition: simpleideals.h:24
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff &#39;n&#39; represents the zero element.
Definition: coeffs.h:468
static BOOLEAN jjFactModD_M(leftv res, leftv v)
Definition: iparith.cc:7640
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition: coeffs.h:725
lists scIndIndset(ideal S, BOOLEAN all, ideal Q)
Definition: ipshell.cc:1022
#define atKill(H, A)
Definition: attrib.h:44
int lSize(lists L)
Definition: lists.cc:25
void(* WerrorS_callback)(const char *s)
Definition: feFopen.cc:21
#define V_DEG_STOP
Definition: options.h:67
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
void iiMakeResolv(resolvente r, int length, int rlen, char *name, int typ0, intvec **weights)
Definition: ipshell.cc:766
static BOOLEAN jjPLUS_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:789
#define IDLEV(a)
Definition: ipid.h:118
char * SPrintEnd()
Definition: reporter.cc:273
resolvente fullres
Definition: syz.h:57
#define TRACE_CALL
Definition: reporter.h:43
#define nDelete(n)
Definition: numbers.h:16
#define IDMAP(a)
Definition: ipid.h:132
#define FLAG_STD
Definition: ipid.h:106
static BOOLEAN jjLISTRING(leftv res, leftv v)
Definition: iparith.cc:4433
static BOOLEAN jjOPTION_PL(leftv res, leftv v)
Definition: iparith.cc:7443
BOOLEAN rHasMixedOrdering(const ring r)
Definition: ring.h:751
poly p_Series(int n, poly p, poly u, intvec *w, const ring R)
Definition: p_polys.cc:4278
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:3815
static BOOLEAN jjIS_RINGVAR_P(leftv res, leftv v)
Definition: iparith.cc:4300
ideal idCopy(ideal A)
Definition: ideals.h:60
static BOOLEAN jjrOrdStr(leftv res, leftv v)
Definition: iparith.cc:5339
static BOOLEAN jjNAMES(leftv res, leftv v)
Definition: iparith.cc:4566
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:2275
short errorreported
Definition: feFopen.cc:23
leftv next
Definition: subexpr.h:87
static BOOLEAN jjBRACK_S(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5385
struct sValCmdM dArithM[]
Definition: table.h:825
void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg)
Definition: p_polys.cc:3508
#define rHasLocalOrMixedOrdering_currRing()
Definition: ring.h:757
static FORCE_INLINE number n_ImPart(number i, const coeffs cf)
Definition: coeffs.h:827
void test_cmd(int i)
Definition: ipshell.cc:506
void rChangeCurrRing(ring r)
Definition: polys.cc:12
static BOOLEAN jjFIND2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2238
static BOOLEAN jjFETCH_M(leftv res, leftv u)
Definition: iparith.cc:6855
static BOOLEAN jjMOD_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:2596
resolvente minres
Definition: syz.h:58
static BOOLEAN rField_is_Zp(const ring r)
Definition: ring.h:495
static FORCE_INLINE number n_Farey(number a, number b, const coeffs r)
Definition: coeffs.h:801
intvec * ivMult(intvec *a, intvec *b)
Definition: intvec.cc:332
ideal idSubstPoly(ideal id, int n, poly e)
Definition: maps_ip.cc:406
static BOOLEAN jjBAREISS3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5655
static BOOLEAN jjSIMPL_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:3300
#define BVERBOSE(a)
Definition: options.h:33
short start
Definition: iparith.cc:133
void p_Shift(poly *p, int i, const ring r)
shifts components of the vector p by i
Definition: p_polys.cc:4514
#define NO_ZERODIVISOR
Definition: iparith.cc:116
static BOOLEAN jjDIM(leftv res, leftv v)
Definition: iparith.cc:3912
INLINE_THIS void Init(int l=0)
static BOOLEAN jjCOEFFS3_KB(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5694
BOOLEAN(* proc2)(leftv, leftv, leftv)
Definition: iparith.cc:156
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition: matpol.cc:47
#define TEST_OPT_RETURN_SB
Definition: options.h:107
#define nInvers(a)
Definition: numbers.h:33
Definition: tok.h:34
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:843
ideal idMult(ideal h1, ideal h2)
hh := h1 * h2
Definition: ideals.h:84
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:158
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
static BOOLEAN jjOP_IV_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:290
static BOOLEAN jjTIMES_MA_P1(leftv res, leftv u, leftv v)
Definition: iparith.cc:1037
static BOOLEAN jjINDEX_V(leftv res, leftv u, leftv v)
Definition: iparith.cc:1474
static FORCE_INLINE number n_ExtGcd(number a, number b, number *s, number *t, const coeffs r)
beware that ExtGCD is only relevant for a few chosen coeff. domains and may perform something unexpec...
Definition: coeffs.h:697
static BOOLEAN jjNEWSTRUCT2(leftv, leftv u, leftv v)
Definition: iparith.cc:2677
#define p_SetmComp
Definition: p_polys.h:239
#define SI_RESTORE_OPT2(A)
Definition: options.h:24
static BOOLEAN jjCOMPARE_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:460
static BOOLEAN jjSQR_FREE2(leftv res, leftv u, leftv dummy)
Definition: iparith.cc:3242
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:38
static BOOLEAN jjGCD_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:2299
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:2746
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
static BOOLEAN jjEXECUTE(leftv, leftv v)
Definition: iparith.cc:4012
#define pSeries(n, p, u, w)
Definition: polys.h:354
static BOOLEAN jjidMaxIdeal(leftv res, leftv v)
Definition: iparith.cc:4222
unsigned nLastIdentifier
valid indentifieres are slot 1..nLastIdentifier
Definition: iparith.cc:196
ring rCopy(ring r)
Definition: ring.cc:1612
matrix mp_Mult(matrix a, matrix b, const ring R)
Definition: matpol.cc:223
int singclap_factorize_retry
Definition: iparith.cc:3241
static BOOLEAN jjMINRES_R(leftv res, leftv v)
Definition: iparith.cc:4533
static BOOLEAN jjPlural_num_mat(leftv res, leftv a, leftv b)
Definition: iparith.cc:2722
static BOOLEAN jjCOEFFS3_P(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5700
void * atGet(idhdl root, const char *name, int t, void *defaultReturnValue)
Definition: attrib.cc:135
short res
Definition: gentable.cc:92
int nr
Definition: lists.h:43
#define nDiv(a, b)
Definition: numbers.h:32
void mp_Coef2(poly v, poly mon, matrix *c, matrix *m, const ring R)
corresponds to Macauley&#39;s coef: the exponent vector of vars has to contain the variables, eg &#39;xy&#39;; then the poly f is searched for monomials in x and y, these monimials are written to the first row of the matrix co. the second row of co contains the respective factors in f. Thus f = sum co[1,i]*co[2,i], i = 1..cols, rows equals 2.
Definition: matpol.cc:515
int & cols()
Definition: matpol.h:25
static BOOLEAN jjRING_LIST(leftv res, leftv v)
Definition: iparith.cc:4772
ideal getMinorIdealHeuristic(const matrix mat, const int minorSize, const int k, const ideal iSB, const bool allDifferent)
Returns the specified set of minors (= subdeterminantes) of the given matrix.
void maFindPerm(char const *const *const preim_names, int preim_n, char const *const *const preim_par, int preim_p, char const *const *const names, int n, char const *const *const par, int nop, int *perm, int *par_perm, n_coeffType ch)
Definition: maps.cc:169
static FORCE_INLINE void n_Power(number a, int b, number *res, const coeffs r)
fill res with the power a^b
Definition: coeffs.h:636
static BOOLEAN jjPLUS_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:779
ideal id_Jet(ideal i, int d, const ring R)
CanonicalForm cf
Definition: cfModGcd.cc:4024
Definition: tok.h:130
#define MATCOLS(i)
Definition: matpol.h:28
Definition: tok.h:116
static BOOLEAN jjJET_ID_IV(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5908
BOOLEAN jjLIST_PL(leftv res, leftv v)
Definition: iparith.cc:7387
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:8600
static BOOLEAN jjTIMES_MA(leftv res, leftv u, leftv v)
Definition: iparith.cc:1079
void mp_Monomials(matrix c, int r, int var, matrix m, const ring R)
Definition: matpol.cc:376
#define nIsZero(n)
Definition: numbers.h:19
static BOOLEAN rField_is_Ring_2toM(const ring r)
Definition: ring.h:465
short res
Definition: gentable.cc:82
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:477
matrix mp_Add(matrix a, matrix b, const ring R)
Definition: matpol.cc:189
#define NULL
Definition: omList.c:10
BOOLEAN idHomIdeal(ideal id, ideal Q=NULL)
Definition: ideals.h:91
static BOOLEAN jjJET_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:2467
int ipower(int b, int m)
int ipower ( int b, int m )
Definition: cf_util.cc:25
matrix id_Module2formatedMatrix(ideal mod, int rows, int cols, const ring R)
slists * lists
Definition: mpr_numeric.h:146
ring rCompose(const lists L, const BOOLEAN check_comp=TRUE)
Definition: ipshell.cc:2695
static BOOLEAN jjHILBERT(leftv, leftv v)
Definition: iparith.cc:4145
ideal id_Farey(ideal x, number N, const ring r)
Definition: ideals.cc:2455
package req_packhdl
Definition: subexpr.h:107
ring syRing
Definition: syz.h:56
static BOOLEAN jjIS_RINGVAR_S(leftv res, leftv v)
Definition: iparith.cc:4305
SRes resPairs
Definition: syz.h:49
static BOOLEAN jjGT_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1124
int length() const
Definition: intvec.h:86
omBin sip_command_bin
Definition: ipid.cc:49
lists primeFactorisation(const number n, const int pBound)
Factorises a given bigint number n into its prime factors less than or equal to a given bound...
Definition: misc_ip.cc:333
static BOOLEAN jjLT_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1146
void rDelete(ring r)
unconditionally deletes fields in r
Definition: ring.cc:448
static BOOLEAN jjPOWER_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:610
SModulFunc_t iiGetBuiltinModInit(const char *libname)
Definition: iplib.cc:643
static BOOLEAN jjQUOT(leftv res, leftv u, leftv v)
Definition: iparith.cc:2874
#define IDINT(a)
Definition: ipid.h:122
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:190
static BOOLEAN jjCOEF_M(leftv, leftv v)
Definition: iparith.cc:6647
ideal walkProc(leftv first, leftv second)
Definition: walk_ip.cc:61
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2484
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of &#39;a&#39; and &#39;b&#39;, i.e., a/b; raises an error if &#39;b&#39; is not invertible in r exceptio...
Definition: coeffs.h:619
long(* pFDegProc)(poly p, ring r)
Definition: ring.h:46
intvec * hSecondSeries(intvec *hseries1)
Definition: hilb.cc:1300
#define jjWRONG2
Definition: iparith.cc:3518
ideal kMin_std(ideal F, ideal Q, tHomog h, intvec **w, ideal &M, intvec *hilb, int syzComp, int reduced)
Definition: kstd1.cc:2822
b *CanonicalForm B
Definition: facBivar.cc:51
BOOLEAN iiCheckTypes(leftv args, const short *type_list, int report)
check a list of arguemys against a given field of types return TRUE if the types match return FALSE (...
Definition: ipshell.cc:6440
#define ABS(x)
Definition: auxiliary.h:111
int luRank(const matrix aMat, const bool isRowEchelon, const ring R)
Computes the rank of a given (m x n)-matrix.
static BOOLEAN jjPLUS_P_MA(leftv res, leftv u, leftv v)
Definition: iparith.cc:832
package basePack
Definition: ipid.cc:64
bool luInverseFromLUDecomp(const matrix pMat, const matrix lMat, const matrix uMat, matrix &iMat, const ring R)
This code computes the inverse by inverting lMat and uMat, and then performing two matrix multiplicat...
coeffs basecoeffs() const
Definition: bigintmat.h:147
void omUpdateInfo()
Definition: omStats.c:24
static BOOLEAN rField_is_Ring_Z(const ring r)
Definition: ring.h:474
static BOOLEAN jjCOUNT_RG(leftv res, leftv v)
Definition: iparith.cc:3733
static BOOLEAN jjUMINUS_IV(leftv res, leftv u)
Definition: iparith.cc:3590
void pNorm(poly p, const ring R=currRing)
Definition: polys.h:345
static BOOLEAN jjTIMES_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:999
#define hasFlag(A, F)
Definition: ipid.h:109
ideal idLiftStd(ideal h1, matrix *ma, tHomog hi, ideal *syz)
Definition: ideals.cc:704
unsigned nCmdUsed
number of commands used
Definition: iparith.cc:194
static BOOLEAN jjMONITOR1(leftv res, leftv v)
Definition: iparith.cc:2608
static BOOLEAN jjMINUS_BIM(leftv res, leftv u, leftv v)
Definition: iparith.cc:892
static BOOLEAN jjQRDS(leftv res, leftv INPUT)
Definition: iparith.cc:7830
void show(int mat=0, int spaces=0) const
Definition: intvec.cc:150
ideal fractalWalkProc(leftv first, leftv second)
Definition: walk_ip.cc:167
char * name
Definition: iparith.cc:140
#define pInit()
allocates a new monomial and initializes everything to 0
Definition: polys.h:61
#define IDRING(a)
Definition: ipid.h:124
static BOOLEAN jjPREIMAGE_R(leftv res, leftv v)
Definition: iparith.cc:4670
int blackboxIsCmd(const char *n, int &tok)
used by scanner: returns ROOT_DECL for known types (and the type number in tok)
Definition: blackbox.cc:191
static BOOLEAN jjPLUS_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:774
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:1065
Definition: tok.h:96
const CanonicalForm & w
Definition: facAbsFact.cc:55
#define pWTotaldegree(p)
Definition: polys.h:265
#define pDelete(p_ptr)
Definition: polys.h:169
package currPack
Definition: ipid.cc:63
static BOOLEAN jjNAMES_I(leftv res, leftv v)
Definition: iparith.cc:4571
static BOOLEAN jjEQUAL_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:1339
proc3 p
Definition: iparith.cc:170
number singclap_det_bi(bigintmat *m, const coeffs cf)
Definition: clapsing.cc:1620
static BOOLEAN jjEXTGCD_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1985
static BOOLEAN jjNAMEOF(leftv res, leftv v)
Definition: iparith.cc:4559
static BOOLEAN jjGT_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1112
static BOOLEAN jjNVARS(leftv res, leftv v)
Definition: iparith.cc:4581
static BOOLEAN jjCOLCOL(leftv res, leftv u, leftv v)
Definition: iparith.cc:700
int cols() const
Definition: intvec.h:87
Variable x
Definition: cfModGcd.cc:4023
int rtyp
Definition: subexpr.h:92
BOOLEAN singclap_extgcd(poly f, poly g, poly &res, poly &pa, poly &pb, const ring r)
Definition: clapsing.cc:460
BOOLEAN mp_IsDiagUnit(matrix U, const ring R)
Definition: matpol.cc:728
static BOOLEAN jjRING_PL(leftv res, leftv a)
Definition: iparith.cc:7930
#define nSize(n)
Definition: numbers.h:39
#define nCopy(n)
Definition: numbers.h:15
sleftv sLastPrinted
Definition: subexpr.cc:55
static SArithBase sArithBase
Base entry for arithmetic.
Definition: iparith.cc:204
int iiArithFindCmd(const char *szName)
Definition: iparith.cc:8989
static FORCE_INLINE number n_GetDenom(number &n, const coeffs r)
return the denominator of n (if elements of r are by nature not fractional, result is 1) ...
Definition: coeffs.h:607
static bool rIsSCA(const ring r)
Definition: nc.h:206
static BOOLEAN jjHOMOG_ID_W(leftv res, leftv u, leftv v, leftv)
Definition: iparith.cc:5841
static BOOLEAN jjUMINUS_BIM(leftv res, leftv u)
Definition: iparith.cc:3597
void CleanUp(ring r=currRing)
Definition: subexpr.cc:333
Definition: tok.h:90
static FORCE_INLINE number n_RePart(number i, const coeffs cf)
Definition: coeffs.h:824
int(* SModulFunc_t)(SModulFunctions *)
Definition: ipid.h:82
static BOOLEAN jjMONITOR2(leftv res, leftv u, leftv v)
Definition: iparith.cc:2612
static Subexpr jjMakeSub(leftv e)
Definition: iparith.cc:7952
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:4449
static BOOLEAN jjFWALK3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5765
void * Data()
Definition: subexpr.cc:1138
static BOOLEAN jjCOUNT_BI(leftv res, leftv v)
Definition: iparith.cc:3706
static BOOLEAN jjrParStr(leftv res, leftv v)
Definition: iparith.cc:5349
static BOOLEAN jjCOLS_BIM(leftv res, leftv v)
Definition: iparith.cc:3688
static FORCE_INLINE BOOLEAN n_Equal(number a, number b, const coeffs r)
TRUE iff &#39;a&#39; and &#39;b&#39; represent the same number; they may have different representations.
Definition: coeffs.h:464
static BOOLEAN jjLE_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1133
ideal idrCopyR(ideal id, ring src_r, ring dest_r)
Definition: prCopy.cc:193
static BOOLEAN jjSYZYGY(leftv res, leftv v)
Definition: iparith.cc:4970
lists rDecompose_list_cf(const ring r)
Definition: ipshell.cc:1879
static BOOLEAN jjLIFTSTD3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6453
int typ
Definition: idrec.h:43
ideal idLift(ideal mod, ideal submod, ideal *rest, BOOLEAN goodShape, BOOLEAN isSB, BOOLEAN divide, matrix *unit)
Definition: ideals.cc:891
short list_length
Definition: syz.h:62
#define pSetCoeff0(p, n)
Definition: monomials.h:67
static BOOLEAN jjCHINREM_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:9184
Definition: tok.h:117
BOOLEAN mp_Equal(matrix a, matrix b, const ring R)
Definition: matpol.cc:596
static BOOLEAN jjDIFF_ID_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:1858
matrix mp_Copy(matrix a, const ring r)
copies matrix a (from ring r to r)
Definition: matpol.cc:74
static BOOLEAN jjDIFF_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:1836
static BOOLEAN jjELIMIN_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:1959
ideal * resolvente
Definition: ideals.h:18
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition: fevoices.cc:171
void SPrintStart()
Definition: reporter.cc:246
void sm_CallBareiss(ideal I, int x, int y, ideal &M, intvec **iv, const ring R)
Definition: sparsmat.cc:403
static FORCE_INLINE number n_SubringGcd(number a, number b, const coeffs r)
Definition: coeffs.h:692
static BOOLEAN jjBAREISS_BIM(leftv res, leftv v)
Definition: iparith.cc:3631
static BOOLEAN jjRING_1(leftv res, leftv u, leftv v)
Definition: iparith.cc:1654
static BOOLEAN jjCALL1MANY(leftv res, leftv u)
Definition: iparith.cc:3674
const char * id
Definition: idrec.h:39
static BOOLEAN jjTIMES_P(leftv res, leftv u, leftv v)
Definition: iparith.cc:944
static BOOLEAN jjROWS_BIM(leftv res, leftv v)
Definition: iparith.cc:4785
attr attribute
Definition: subexpr.h:90
omBin slists_bin
Definition: lists.cc:23
static BOOLEAN jjLE_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1129
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:1392
static BOOLEAN jjSBA_1(leftv res, leftv v, leftv u)
Definition: iparith.cc:4870
static BOOLEAN jjMINUS_IV(leftv res, leftv u, leftv v)
Definition: iparith.cc:882
static BOOLEAN jjPOWER_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:592
cmdnames * sCmds
array of existing commands
Definition: iparith.cc:189
#define ii_div_by_0
Definition: iparith.cc:223
int idElem(const ideal F)
count non-zero elements
char libnamebuf[128]
Definition: libparse.cc:1096
#define NO_CONVERSION
Definition: iparith.cc:125
#define pPower(p, q)
Definition: polys.h:187
static FORCE_INLINE BOOLEAN nCoeff_is_Extension(const coeffs r)
Definition: coeffs.h:863
static BOOLEAN jjMATRIX_Mo(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6402
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2424
static BOOLEAN jjidHead(leftv res, leftv v)
Definition: iparith.cc:5306
void newstruct_setup(const char *n, newstruct_desc d)
Definition: newstruct.cc:692
static BOOLEAN jjOP_I_IM(leftv res, leftv u, leftv v)
Definition: iparith.cc:326
static BOOLEAN jjSort_Id(leftv res, leftv v)
Definition: iparith.cc:4948
int mp_Compare(matrix a, matrix b, const ring R)
Definition: matpol.cc:577
static BOOLEAN jjJET_P_P(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5898
newstruct_desc newstructChildFromString(const char *parent, const char *s)
Definition: newstruct.cc:803
leftv iiMap(map theMap, const char *what)
Definition: ipshell.cc:607
int n_IsParam(const number m, const ring r)
TODO: rewrite somehow...
Definition: ring.cc:5603
static BOOLEAN jjPOWER_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:530
static BOOLEAN jjCOMPARE_IV_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:405
static BOOLEAN jjPLUSPLUS(leftv, leftv u)
Definition: iparith.cc:3548
BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char *newlib, idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
Definition: iplib.cc:807
#define pDiff(a, b)
Definition: polys.h:278
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete &#39;p&#39;
Definition: coeffs.h:459
#define OPT_SB_1
Definition: options.h:90
char * rCharStr(const ring r)
TODO: make it a virtual method of coeffs, together with: Decompose & Compose, rParameter & rPar...
Definition: ring.cc:618
static BOOLEAN jjFACSTD2(leftv res, leftv v, leftv w)
Definition: iparith.cc:2092
static FORCE_INLINE BOOLEAN n_GreaterZero(number n, const coeffs r)
ordered fields: TRUE iff &#39;n&#39; is positive; in Z/pZ: TRUE iff 0 < m <= roundedBelow(p/2), where m is the long representing n in C: TRUE iff (Im(n) != 0 and Im(n) >= 0) or (Im(n) == 0 and Re(n) >= 0) in K(a)/<p(a)>: TRUE iff (n != 0 and (LC(n) > 0 or deg(n) > 0)) in K(t_1, ..., t_n): TRUE iff (LC(numerator(n) is a constant and > 0) or (LC(numerator(n) is not a constant) in Z/2^kZ: TRUE iff 0 < n <= 2^(k-1) in Z/mZ: TRUE iff the internal mpz is greater than zero in Z: TRUE iff n > 0
Definition: coeffs.h:498
#define SI_PROT_O
Definition: reporter.h:53
const char * getBlackboxName(const int t)
return the name to the type given by t (r/o)
Definition: blackbox.cc:185
ideal singclap_factorize(poly f, intvec **v, int with_exps, const ring r)
Definition: clapsing.cc:784
ideal idAdd(ideal h1, ideal h2)
h1 + h2
Definition: ideals.h:68
#define pIsUnivariate(p)
Definition: polys.h:232
Definition: tok.h:166
static BOOLEAN jjREDUCE4(leftv res, leftv u)
Definition: iparith.cc:7453
proc1 p
Definition: iparith.cc:180
static BOOLEAN jjUNIVARIATE(leftv res, leftv v)
Definition: iparith.cc:5103
#define MATROWS(i)
Definition: matpol.h:27
static BOOLEAN jjIDEAL_Ma(leftv res, leftv v)
Definition: iparith.cc:4228
static BOOLEAN jjSTATUS3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6548
static BOOLEAN jjIDEAL_R(leftv res, leftv v)
Definition: iparith.cc:4256
intvec * hFirstSeries(ideal S, intvec *modulweight, ideal Q, intvec *wdegree, ring tailRing)
Definition: hilb.cc:1292
ideal id_Vec2Ideal(poly vec, const ring R)
matrix mp_Sub(matrix a, matrix b, const ring R)
Definition: matpol.cc:206
static BOOLEAN jjDEG(leftv res, leftv v)
Definition: iparith.cc:3747
static FORCE_INLINE char * nCoeffString(const coeffs cf)
TODO: make it a virtual method of coeffs, together with: Decompose & Compose, rParameter & rPar...
Definition: coeffs.h:976
kBucketDestroy & P
Definition: myNF.cc:191
int iiTokType(int op)
Definition: iparith.cc:240
void hLookSeries(ideal S, intvec *modulweight, ideal Q, intvec *wdegree, ring tailRing)
Definition: hilb.cc:1371
static BOOLEAN jjCOUNT_L(leftv res, leftv v)
Definition: iparith.cc:3716
static jList * T
Definition: janet.cc:37
polyrec * poly
Definition: hilb.h:10
static BOOLEAN jjMATRIX_Id(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6379
static int iin_Int(number &n, coeffs cf)
Definition: iparith.cc:228
#define IDDATA(a)
Definition: ipid.h:123
static BOOLEAN jjOR_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1365
int Kstd1_deg
Definition: kutil.cc:236
static BOOLEAN jjMINUS_MA(leftv res, leftv u, leftv v)
Definition: iparith.cc:902
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
static BOOLEAN jjLU_SOLVE(leftv res, leftv v)
Definition: iparith.cc:7138
BOOLEAN rDecompose_CF(leftv res, const coeffs C)
Definition: ipshell.cc:1808
BOOLEAN(* proc1)(leftv, leftv)
Definition: ipshell.h:120
static BOOLEAN jjpMaxComp(leftv res, leftv v)
Definition: iparith.cc:5324
#define pISet(i)
Definition: polys.h:294
#define nInit(i)
Definition: numbers.h:24
char * iiConvName(const char *libname)
Definition: iplib.cc:1214
syStrategy syHilb(ideal arg, int *length)
Definition: syz2.cc:956
int iiOp
Definition: iparith.cc:225
unsigned si_opt_2
Definition: options.c:6
static BOOLEAN currRingIsOverIntegralDomain()
Definition: iparith.cc:5925
static BOOLEAN jjBRACK_Ma(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5456
static Poly * h
Definition: janet.cc:978
int compare(const bigintmat *op) const
Definition: bigintmat.cc:365
int BOOLEAN
Definition: auxiliary.h:85
static BOOLEAN jjPlural_num_poly(leftv res, leftv a, leftv b)
Definition: iparith.cc:2702
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:3824
ideal idSyzygies(ideal h1, tHomog h, intvec **w, BOOLEAN setSyzComp, BOOLEAN setRegularity, int *deg)
Definition: ideals.cc:515
static BOOLEAN jjNOT(leftv res, leftv v)
Definition: iparith.cc:4576
#define IMATELEM(M, I, J)
Definition: intvec.h:77
const poly b
Definition: syzextra.cc:213
BOOLEAN iiExprArith2(leftv res, leftv a, int op, leftv b, BOOLEAN proccall)
Definition: iparith.cc:8143
static BOOLEAN jjHOMOG_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:2384
#define omRealloc(addr, size)
Definition: omAllocDecl.h:225
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2715
#define NONE
Definition: tok.h:216
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition: polys.h:31
void syMake(leftv v, const char *id, package pa)
Definition: subexpr.cc:1501
static BOOLEAN jjRESERVEDNAME(leftv res, leftv v)
Definition: iparith.cc:4722
#define ppJetW(p, m, iv)
Definition: polys.h:351
#define SI_RESTORE_OPT1(A)
Definition: options.h:23
static BOOLEAN jjINDEPSET(leftv res, leftv v)
Definition: iparith.cc:4285
BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition: iplib.cc:982
static FORCE_INLINE int n_Size(number n, const coeffs r)
return a non-negative measure for the complexity of n; return 0 only when n represents zero; (used fo...
Definition: coeffs.h:574
static BOOLEAN jjDET_I(leftv res, leftv v)
Definition: iparith.cc:3882
ideal id_Matrix2Module(matrix mat, const ring R)
static BOOLEAN jjTRANSP_BIM(leftv res, leftv v)
Definition: iparith.cc:5013
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:496
static BOOLEAN jjOPPOSITE(leftv res, leftv a)
Definition: iparith.cc:5024
static BOOLEAN jjCONTRACT(leftv res, leftv u, leftv v)
Definition: iparith.cc:1806
static BOOLEAN jjHIGHCORNER(leftv res, leftv v)
Definition: iparith.cc:4091
proc1 p
Definition: iparith.cc:149
leftv LData()
Definition: subexpr.cc:1407
struct sValCmd3 * psValCmd3
Definition: iparith.cc:192
BOOLEAN idHomModule(ideal m, ideal Q, intvec **w)
Definition: ideals.h:96
char * rOrdStr(ring r)
Definition: ring.cc:522
void Werror(const char *fmt,...)
Definition: reporter.cc:189
static BOOLEAN jjAND_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1360
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:8202
#define nAdd(n1, n2)
Definition: numbers.h:18
syStrategy syLaScala3(ideal arg, int *length)
Definition: syz1.cc:2434
static BOOLEAN jjREAD(leftv res, leftv v)
Definition: iparith.cc:4744
int ivTrace(intvec *o)
Definition: intvec.cc:322
void * CopyD(int t)
Definition: subexpr.cc:708
static BOOLEAN jjCHAR(leftv res, leftv v)
Definition: iparith.cc:3678
const char * lastreserved
Definition: ipshell.cc:80
static BOOLEAN jjEQUAL_I(leftv res, leftv u, leftv v)
Definition: iparith.cc:1315
static BOOLEAN jjLEADMONOM(leftv res, leftv v)
Definition: iparith.cc:4414
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:846
idhdl h0
Definition: libparse.cc:1141
return result
Definition: facAbsBiFact.cc:76
int l
Definition: cfEzgcd.cc:94
static BOOLEAN jjSIMPL_ID(leftv res, leftv u, leftv v)
Definition: iparith.cc:3209
static BOOLEAN jjELIMIN_HILB(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5727
intvec * ivAdd(intvec *a, intvec *b)
Definition: intvec.cc:250
static BOOLEAN jjstrlen(leftv res, leftv v)
Definition: iparith.cc:5271
static BOOLEAN jjFETCH(leftv res, leftv u, leftv v)
Definition: iparith.cc:2133
ideal syMinBase(ideal arg)
Definition: syz.cc:1025
static BOOLEAN jjTWOSTD(leftv res, leftv a)
Definition: iparith.cc:5050
static BOOLEAN jjSTD_HILB_WP(leftv res, leftv INPUT)
Definition: iparith.cc:7847
static BOOLEAN jjDIFF_COEF(leftv res, leftv u, leftv v)
Definition: iparith.cc:4328
static BOOLEAN jjSTATUS2(leftv res, leftv u, leftv v)
Definition: iparith.cc:3289
static BOOLEAN jjORD(leftv res, leftv v)
Definition: iparith.cc:4592
long rank
Definition: matpol.h:20
static BOOLEAN jjFIND3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5734
static BOOLEAN jjDIV_BI(leftv res, leftv u, leftv v)
Definition: iparith.cc:1178
static BOOLEAN jjCOLS_IV(leftv res, leftv v)
Definition: iparith.cc:3693
syStrategy syMinimize(syStrategy syzstr)
Definition: syz1.cc:2402
#define IDMATRIX(a)
Definition: ipid.h:131
#define nGreater(a, b)
Definition: numbers.h:28
#define pCopy(p)
return a copy of the poly
Definition: polys.h:168
#define COMMAND
Definition: tok.h:29
#define MATELEM(mat, i, j)
Definition: matpol.h:29
#define RING_MASK
Definition: iparith.cc:105
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:16
#define V_IMAP
Definition: options.h:51
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:334
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:377
#define SI_SAVE_OPT2(A)
Definition: options.h:21
int IsCmd(const char *n, int &tok)
Definition: iparith.cc:8746
static BOOLEAN jjHILBERT3(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5774
ListNode * next
Definition: janet.h:31
static BOOLEAN jjRANDOM_Im(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:6216
static BOOLEAN jjLT_N(leftv res, leftv u, leftv v)
Definition: iparith.cc:1151
static BOOLEAN jjidElem(leftv res, leftv v)
Definition: iparith.cc:5281
static BOOLEAN jjCOEFFS3_Id(leftv res, leftv u, leftv v, leftv w)
Definition: iparith.cc:5680
#define Warn
Definition: emacs.cc:80
ideal twostd(ideal I)
Compute two-sided GB:
Definition: nc.cc:21
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define idIsConstant(I)
Definition: ideals.h:40