source: git/Singular/extra.cc @ aa37e4

spielwiese
Last change on this file since aa37e4 was 5f42b9, checked in by Hans Schoenemann <hannes@…>, 22 months ago
fix: ccluster (uses CC, configure also)
  • Property mode set to 100644
File size: 117.1 KB
Line 
1/*****************************************
2*  Computer Algebra System SINGULAR      *
3*****************************************/
4/*
5* ABSTRACT: general interface to internals of Singular ("system" command)
6* jjSYSTEM: official commands, must be documented in the manual,
7*           #defines must be local to each command
8* jjEXTENDED_SYSTEM: tests, temporary comands etc.
9*/
10
11#define HAVE_WALK 1
12
13#include "kernel/mod2.h"
14#include "misc/sirandom.h"
15#include "resources/omFindExec.h"
16
17#ifdef HAVE_CCLUSTER
18#undef CC
19#include "ccluster/ccluster.h"
20#endif
21
22#include "factory/factory.h"
23
24#ifdef TIME_WITH_SYS_TIME
25# include <time.h>
26# ifdef HAVE_SYS_TIME_H
27#   include <sys/time.h>
28# endif
29#else
30# ifdef HAVE_SYS_TIME_H
31#   include <sys/time.h>
32# else
33#   include <time.h>
34# endif
35#endif
36#ifdef HAVE_SYS_TIMES_H
37#include <sys/times.h>
38#endif
39
40#include <unistd.h>
41
42#include "misc/options.h"
43
44// #include "coeffs/ffields.h"
45#include "coeffs/coeffs.h"
46#include "coeffs/mpr_complex.h"
47
48
49#include "resources/feResource.h"
50#include "polys/monomials/ring.h"
51#include "kernel/polys.h"
52
53#include "polys/monomials/maps.h"
54#include "polys/matpol.h"
55
56#include "polys/weight.h"
57
58#ifdef HAVE_SHIFTBBA
59#include "polys/shiftop.h"
60#endif
61
62#include "coeffs/bigintmat.h"
63#include "kernel/fast_mult.h"
64#include "kernel/digitech.h"
65#include "kernel/combinatorics/stairc.h"
66#include "kernel/ideals.h"
67#include "kernel/GBEngine/kstd1.h"
68#include "kernel/GBEngine/syz.h"
69#include "kernel/GBEngine/kutil.h"
70#include "kernel/GBEngine/kverify.h"
71
72#include "kernel/linear_algebra/linearAlgebra.h"
73
74#include "kernel/combinatorics/hutil.h"
75
76// for tests of t-rep-GB
77#include "kernel/GBEngine/tgb.h"
78
79#include "kernel/linear_algebra/minpoly.h"
80
81#include "numeric/mpr_base.h"
82
83#include "tok.h"
84#include "ipid.h"
85#include "lists.h"
86#include "cntrlc.h"
87#include "ipshell.h"
88#include "sdb.h"
89#include "feOpt.h"
90#include "fehelp.h"
91#include "distrib.h"
92
93#include "misc_ip.h"
94
95#include "attrib.h"
96
97#include "links/silink.h"
98#include "links/ssiLink.h"
99#include "walk.h"
100#include "Singular/newstruct.h"
101#include "Singular/blackbox.h"
102#include "Singular/pyobject_setup.h"
103
104
105#ifdef HAVE_RINGS
106#include "kernel/GBEngine/ringgb.h"
107#endif
108
109#ifdef HAVE_F5
110#include "kernel/GBEngine/f5gb.h"
111#endif
112
113#ifdef HAVE_WALK
114#include "walk.h"
115#endif
116
117#ifdef HAVE_SPECTRUM
118#include "kernel/spectrum/spectrum.h"
119#endif
120
121#ifdef HAVE_PLURAL
122#include "polys/nc/nc.h"
123#include "polys/nc/ncSAMult.h" // for CMultiplier etc classes
124#include "polys/nc/sca.h"
125#include "kernel/GBEngine/nc.h"
126#include "ipconv.h"
127#ifdef HAVE_RATGRING
128#include "kernel/GBEngine/ratgring.h"
129#endif
130#endif
131
132#ifdef __CYGWIN__ /* only for the DLLTest */
133/* #include "WinDllTest.h" */
134#ifdef HAVE_DL
135#include "polys/mod_raw.h"
136#endif
137#endif
138
139// Define to enable many more system commands
140//#undef MAKE_DISTRIBUTION
141#ifndef MAKE_DISTRIBUTION
142#define HAVE_EXTENDED_SYSTEM 1
143#endif
144
145#include "polys/flintconv.h"
146#include "polys/clapconv.h"
147#include "kernel/GBEngine/kstdfac.h"
148
149#include "polys/clapsing.h"
150
151#ifdef HAVE_EIGENVAL
152#include "eigenval_ip.h"
153#endif
154
155#ifdef HAVE_GMS
156#include "gms.h"
157#endif
158
159#ifdef HAVE_SIMPLEIPC
160#include "Singular/links/simpleipc.h"
161#endif
162
163#ifdef HAVE_PCV
164#include "pcv.h"
165#endif
166
167#ifndef MAKE_DISTRIBUTION
168static BOOLEAN jjEXTENDED_SYSTEM(leftv res, leftv h);
169#endif
170EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG;
171
172/* expects a SINGULAR square matrix with number entries
173   where currRing is expected to be over some field F_p;
174   returns a long** matrix with the "same", i.e.,
175   appropriately mapped entries;
176   leaves singularMatrix unmodified */
177unsigned long** singularMatrixToLongMatrix(matrix singularMatrix)
178{
179  int n = singularMatrix->rows();
180  assume(n == singularMatrix->cols());
181  unsigned long **longMatrix = 0;
182  longMatrix = new unsigned long *[n] ;
183  for (int i = 0 ; i < n; i++)
184    longMatrix[i] = new unsigned long [n];
185  number entry;
186  for (int r = 0; r < n; r++)
187    for (int c = 0; c < n; c++)
188    {
189      poly p=MATELEM(singularMatrix, r + 1, c + 1);
190      int entryAsInt;
191      if (p!=NULL)
192      {
193        entry = p_GetCoeff(p, currRing);
194        entryAsInt = n_Int(entry, currRing->cf);
195        if (entryAsInt < 0) entryAsInt += n_GetChar(currRing->cf);
196      }
197      else
198        entryAsInt=0;
199      longMatrix[r][c] = (unsigned long)entryAsInt;
200    }
201  return longMatrix;
202}
203
204/* expects an array of unsigned longs with valid indices 0..degree;
205   returns the following poly, where x denotes the first ring variable
206   of currRing, and d = degree:
207      polyCoeffs[d] * x^d + polyCoeffs[d-1] * x^(d-1) + ... + polyCoeffs[0]
208   leaves polyCoeffs unmodified */
209poly longCoeffsToSingularPoly(unsigned long *polyCoeffs, const int degree)
210{
211  poly result = NULL;
212  for (int i = 0; i <= degree; i++)
213  {
214    if ((int)polyCoeffs[i] != 0)
215    {
216      poly term = p_ISet((int)polyCoeffs[i], currRing);
217      if (i > 0)
218      {
219        p_SetExp(term, 1, i, currRing);
220        p_Setm(term, currRing);
221      }
222      result = p_Add_q(result, term, currRing);
223    }
224  }
225  return result;
226}
227
228/*2
229*  the "system" command
230*/
231BOOLEAN jjSYSTEM(leftv res, leftv args)
232{
233  if(args->Typ() == STRING_CMD)
234  {
235    const char *sys_cmd=(char *)(args->Data());
236    leftv h=args->next;
237// ONLY documented system calls go here
238// Undocumented system calls go down into jjEXTENDED_SYSTEM (#ifdef HAVE_EXTENDED_SYSTEM)
239/*==================== nblocks ==================================*/
240    if (strcmp(sys_cmd, "nblocks") == 0)
241    {
242      ring r;
243      if (h == NULL)
244      {
245        if (currRingHdl != NULL)
246        {
247          r = IDRING(currRingHdl);
248        }
249        else
250        {
251          WerrorS("no ring active");
252          return TRUE;
253        }
254      }
255      else
256      {
257        if (h->Typ() != RING_CMD)
258        {
259          WerrorS("ring expected");
260          return TRUE;
261        }
262        r = (ring) h->Data();
263      }
264      res->rtyp = INT_CMD;
265      res->data = (void*) (long)(rBlocks(r) - 1);
266      return FALSE;
267    }
268/*==================== version ==================================*/
269    if(strcmp(sys_cmd,"version")==0)
270    {
271      res->rtyp=INT_CMD;
272      res->data=(void *)SINGULAR_VERSION;
273      return FALSE;
274    }
275    else
276/*==================== alarm ==================================*/
277      if(strcmp(sys_cmd,"alarm")==0)
278      {
279        if ((h!=NULL) &&(h->Typ()==INT_CMD))
280        {
281          // standard variant -> SIGALARM (standard: abort)
282          //alarm((unsigned)h->next->Data());
283          // process time (user +system): SIGVTALARM
284          struct itimerval t,o;
285          memset(&t,0,sizeof(t));
286          t.it_value.tv_sec     =(unsigned)((unsigned long)h->Data());
287          setitimer(ITIMER_VIRTUAL,&t,&o);
288          return FALSE;
289        }
290        else
291          WerrorS("int expected");
292      }
293      else
294/*==================== content ==================================*/
295    if(strcmp(sys_cmd,"content")==0)
296    {
297      if ((h!=NULL) && ((h->Typ()==POLY_CMD)||(h->Typ()==VECTOR_CMD)))
298      {
299        int t=h->Typ();
300        poly p=(poly)h->CopyD();
301        if (p!=NULL)
302        {
303           if (!nCoeff_is_Ring(currRing->cf)) p_Cleardenom(p,currRing);
304          p_Content(p,currRing);
305        }
306        res->data=(void *)p;
307        res->rtyp=t;
308        return FALSE;
309      }
310      return TRUE;
311    }
312    else
313/*==================== cpu ==================================*/
314    if(strcmp(sys_cmd,"cpu")==0)
315    {
316      long cpu=1; //feOptValue(FE_OPT_CPUS);
317      #ifdef _SC_NPROCESSORS_ONLN
318      cpu=sysconf(_SC_NPROCESSORS_ONLN);
319      #elif defined(_SC_NPROCESSORS_CONF)
320      cpu=sysconf(_SC_NPROCESSORS_CONF);
321      #endif
322      res->data=(void *)cpu;
323      res->rtyp=INT_CMD;
324      return FALSE;
325    }
326    else
327/*==================== executable ==================================*/
328    if(strcmp(sys_cmd,"executable")==0)
329    {
330      if ((h!=NULL) && (h->Typ()==STRING_CMD))
331      {
332        char tbuf[MAXPATHLEN];
333        char *s=omFindExec((char*)h->Data(),tbuf);
334        if(s==NULL) s=(char*)"";
335        res->data=(void *)omStrDup(s);
336        res->rtyp=STRING_CMD;
337        return FALSE;
338      }
339      return TRUE;
340    }
341    else
342  /*==================== flatten =============================*/
343    if(strcmp(sys_cmd,"flatten")==0)
344    {
345      if ((h!=NULL) &&(h->Typ()==SMATRIX_CMD))
346      {
347        res->data=(char*)sm_Flatten((ideal)h->Data(),currRing);
348        res->rtyp=SMATRIX_CMD;
349        return FALSE;
350      }
351      else
352        WerrorS("smatrix expected");
353    }
354    else
355  /*==================== unflatten =============================*/
356    if(strcmp(sys_cmd,"unflatten")==0)
357    {
358      const short t1[]={2,SMATRIX_CMD,INT_CMD};
359      if (iiCheckTypes(h,t1,1))
360      {
361        res->data=(char*)sm_UnFlatten((ideal)h->Data(),(int)(long)h->next->Data(),currRing);
362        res->rtyp=SMATRIX_CMD;
363        return res->data==NULL;
364      }
365      else return TRUE;
366    }
367    else
368  /*==================== neworder =============================*/
369    if(strcmp(sys_cmd,"neworder")==0)
370    {
371      if ((h!=NULL) &&(h->Typ()==IDEAL_CMD))
372      {
373        res->rtyp=STRING_CMD;
374        res->data=(void *)singclap_neworder((ideal)h->Data(), currRing);
375        return FALSE;
376      }
377      else
378        WerrorS("ideal expected");
379    }
380    else
381/*===== nc_hilb ===============================================*/
382   // Hilbert series of non-commutative monomial algebras
383    if(strcmp(sys_cmd,"nc_hilb") == 0)
384    {
385      ideal i; int lV;
386      bool ig = FALSE;
387      bool mgrad = FALSE;
388      bool autop = FALSE;
389      int trunDegHs=0;
390      if((h != NULL)&&(h->Typ() == IDEAL_CMD))
391        i = (ideal)h->Data();
392      else
393      {
394        WerrorS("nc_Hilb:ideal expected");
395        return TRUE;
396      }
397      h = h->next;
398      if((h != NULL)&&(h->Typ() == INT_CMD))
399        lV = (int)(long)h->Data();
400      else
401      {
402        WerrorS("nc_Hilb:int expected");
403        return TRUE;
404      }
405      h = h->next;
406      while(h != NULL)
407      {
408        if((int)(long)h->Data() == 1)
409          ig = TRUE;
410        else if((int)(long)h->Data() == 2)
411          mgrad = TRUE;
412        else if(h->Typ()==STRING_CMD)
413           autop = TRUE;
414        else if(h->Typ() == INT_CMD)
415          trunDegHs = (int)(long)h->Data();
416        h = h->next;
417      }
418      if(h != NULL)
419      {
420        WerrorS("nc_Hilb:int 1,2, total degree for the truncation, and a string                  for printing the details are expected");
421        return TRUE;
422      }
423
424      HilbertSeries_OrbitData(i, lV, ig, mgrad, autop, trunDegHs);
425      return(FALSE);
426    }
427    else
428/* ====== verify ============================*/
429    if(strcmp(sys_cmd,"verifyGB")==0)
430    {
431      if (rIsNCRing(currRing))
432      {
433        WerrorS("system(\"verifyGB\",<ideal>,..) expects a commutative ring");
434        return TRUE;
435      }
436      if (h->Typ()!=IDEAL_CMD)
437      {
438        WerrorS("expected system(\"verifyGB\",<ideal>,..)");
439        return TRUE;
440      }
441      ideal F=(ideal)h->Data();
442      if (h->next==NULL)
443      {
444        #ifdef HAVE_VSPACE
445        int cpus = (long) feOptValue(FE_OPT_CPUS);
446        if (cpus>1)
447          res->data=(char*)(long) kVerify2(F,currRing->qideal);
448        else
449        #endif
450          res->data=(char*)(long) kVerify1(F,currRing->qideal);
451      }
452      else return TRUE;
453      res->rtyp=INT_CMD;
454      return FALSE;
455    }
456    else
457/*===== rcolon ===============================================*/
458  if(strcmp(sys_cmd,"rcolon") == 0)
459  {
460    const short t1[]={3,IDEAL_CMD,POLY_CMD,INT_CMD};
461    if (iiCheckTypes(h,t1,1))
462    {
463      ideal i = (ideal)h->Data();
464      h = h->next;
465      poly w=(poly)h->Data();
466      h = h->next;
467      int lV = (int)(long)h->Data();
468      res->rtyp = IDEAL_CMD;
469      res->data = RightColonOperation(i, w, lV);
470      return(FALSE);
471    }
472    else
473      return TRUE;
474  }
475  else
476
477/*==================== sh ==================================*/
478    if(strcmp(sys_cmd,"sh")==0)
479    {
480      if (FE_OPT_NO_SHELL_FLAG)
481      {
482        WerrorS("shell execution is disallowed in restricted mode");
483        return TRUE;
484      }
485      res->rtyp=INT_CMD;
486      if (h==NULL) res->data = (void *)(long) system("sh");
487      else if (h->Typ()==STRING_CMD)
488        res->data = (void*)(long) system((char*)(h->Data()));
489      else
490        WerrorS("string expected");
491      return FALSE;
492    }
493    else
494/*========reduce procedure like the global one but with jet bounds=======*/
495    if(strcmp(sys_cmd,"reduce_bound")==0)
496    {
497      poly p;
498      ideal pid=NULL;
499      const short t1[]={3,POLY_CMD,IDEAL_CMD,INT_CMD};
500      const short t2[]={3,IDEAL_CMD,IDEAL_CMD,INT_CMD};
501      const short t3[]={3,VECTOR_CMD,MODUL_CMD,INT_CMD};
502      const short t4[]={3,MODUL_CMD,MODUL_CMD,INT_CMD};
503      if ((iiCheckTypes(h,t1,0))||((iiCheckTypes(h,t3,0))))
504      {
505        p = (poly)h->CopyD();
506      }
507      else if  ((iiCheckTypes(h,t2,0))||(iiCheckTypes(h,t4,1)))
508      {
509        pid = (ideal)h->CopyD();
510      }
511      else return TRUE;
512      //int htype;
513      res->rtyp= h->Typ(); /*htype*/
514      ideal q = (ideal)h->next->CopyD();
515      int bound = (int)(long)h->next->next->Data();
516      if (pid==NULL) /*(htype == POLY_CMD || htype == VECTOR_CMD)*/
517        res->data = (char *)kNFBound(q,currRing->qideal,p,bound);
518      else /*(htype == IDEAL_CMD || htype == MODUL_CMD)*/
519        res->data = (char *)kNFBound(q,currRing->qideal,pid,bound);
520      return FALSE;
521    }
522    else
523/*==================== uname ==================================*/
524    if(strcmp(sys_cmd,"uname")==0)
525    {
526      res->rtyp=STRING_CMD;
527      res->data = omStrDup(S_UNAME);
528      return FALSE;
529    }
530    else
531/*==================== with ==================================*/
532    if(strcmp(sys_cmd,"with")==0)
533    {
534      if (h==NULL)
535      {
536        res->rtyp=STRING_CMD;
537        res->data=(void *)versionString();
538        return FALSE;
539      }
540      else if (h->Typ()==STRING_CMD)
541      {
542        #define TEST_FOR(A) if(strcmp(s,A)==0) res->data=(void *)1; else
543        char *s=(char *)h->Data();
544        res->rtyp=INT_CMD;
545        #ifdef HAVE_DBM
546          TEST_FOR("DBM")
547        #endif
548        #ifdef HAVE_DLD
549          TEST_FOR("DLD")
550        #endif
551          //TEST_FOR("factory")
552          //TEST_FOR("libfac")
553        #ifdef HAVE_READLINE
554          TEST_FOR("readline")
555        #endif
556        #ifdef TEST_MAC_ORDER
557          TEST_FOR("MAC_ORDER")
558        #endif
559        // unconditional since 3-1-0-6
560          TEST_FOR("Namespaces")
561        #ifdef HAVE_DYNAMIC_LOADING
562          TEST_FOR("DynamicLoading")
563        #endif
564        #ifdef HAVE_EIGENVAL
565          TEST_FOR("eigenval")
566        #endif
567        #ifdef HAVE_GMS
568          TEST_FOR("gms")
569        #endif
570        #ifdef OM_NDEBUG
571          TEST_FOR("om_ndebug")
572        #endif
573        #ifdef SING_NDEBUG
574          TEST_FOR("ndebug")
575        #endif
576          {};
577          return FALSE;
578        #undef TEST_FOR
579      }
580      return TRUE;
581    }
582    else
583  /*==================== browsers ==================================*/
584    if (strcmp(sys_cmd,"browsers")==0)
585    {
586      res->rtyp = STRING_CMD;
587      StringSetS("");
588      feStringAppendBrowsers(0);
589      res->data = StringEndS();
590      return FALSE;
591    }
592    else
593  /*==================== pid ==================================*/
594    if (strcmp(sys_cmd,"pid")==0)
595    {
596      res->rtyp=INT_CMD;
597      res->data=(void *)(long) getpid();
598      return FALSE;
599    }
600    else
601  /*==================== getenv ==================================*/
602    if (strcmp(sys_cmd,"getenv")==0)
603    {
604      if ((h!=NULL) && (h->Typ()==STRING_CMD))
605      {
606        res->rtyp=STRING_CMD;
607        const char *r=getenv((char *)h->Data());
608        if (r==NULL) r="";
609        res->data=(void *)omStrDup(r);
610        return FALSE;
611      }
612      else
613      {
614        WerrorS("string expected");
615        return TRUE;
616      }
617    }
618    else
619  /*==================== setenv ==================================*/
620    if (strcmp(sys_cmd,"setenv")==0)
621    {
622  #ifdef HAVE_SETENV
623      const short t[]={2,STRING_CMD,STRING_CMD};
624      if (iiCheckTypes(h,t,1))
625      {
626        res->rtyp=STRING_CMD;
627        setenv((char *)h->Data(), (char *)h->next->Data(), 1);
628        res->data=(void *)omStrDup((char *)h->next->Data());
629        feReInitResources();
630        return FALSE;
631      }
632      else
633      {
634        return TRUE;
635      }
636  #else
637      WerrorS("setenv not supported on this platform");
638      return TRUE;
639  #endif
640    }
641    else
642  /*==================== Singular ==================================*/
643    if (strcmp(sys_cmd, "Singular") == 0)
644    {
645      res->rtyp=STRING_CMD;
646      const char *r=feResource("Singular");
647      if (r == NULL) r="";
648      res->data = (void*) omStrDup( r );
649      return FALSE;
650    }
651    else
652    if (strcmp(sys_cmd, "SingularLib") == 0)
653    {
654      res->rtyp=STRING_CMD;
655      const char *r=feResource("SearchPath");
656      if (r == NULL) r="";
657      res->data = (void*) omStrDup( r );
658      return FALSE;
659    }
660    else
661    if (strcmp(sys_cmd, "SingularBin") == 0)
662    {
663      res->rtyp=STRING_CMD;
664      const char *r=feResource('r');
665      if (r == NULL) r="/usr/local";
666      int l=strlen(r);
667      /* where to find Singular's programs: */
668      #define SINGULAR_PROCS_DIR "/libexec/singular/MOD"
669      int ll=si_max((int)strlen(SINGULAR_PROCS_DIR),(int)strlen(LIBEXEC_DIR));
670      char *s=(char*)omAlloc(l+ll+2);
671      if ((strstr(r,".libs/..")==NULL)   /*not installed Singular (libtool)*/
672      &&(strstr(r,"Singular/..")==NULL)) /*not installed Singular (static)*/
673      {
674        strcpy(s,r);
675        strcat(s,SINGULAR_PROCS_DIR);
676        if (access(s,X_OK)==0)
677        {
678          strcat(s,"/");
679        }
680        else
681        {
682          /*second try: LIBEXEC_DIR*/
683          strcpy(s,LIBEXEC_DIR);
684          if (access(s,X_OK)==0)
685          {
686            strcat(s,"/");
687          }
688          else
689          {
690            s[0]='\0';
691          }
692        }
693      }
694      else
695      {
696        const char *r=feResource('b');
697        if (r == NULL)
698        {
699          s[0]='\0';
700        }
701        else
702        {
703          strcpy(s,r);
704          strcat(s,"/");
705        }
706      }
707      res->data = (void*)s;
708      return FALSE;
709    }
710    else
711  /*==================== options ==================================*/
712    if (strstr(sys_cmd, "--") == sys_cmd)
713    {
714      if (strcmp(sys_cmd, "--") == 0)
715      {
716        fePrintOptValues();
717        return FALSE;
718      }
719      feOptIndex opt = feGetOptIndex(&sys_cmd[2]);
720      if (opt == FE_OPT_UNDEF)
721      {
722        Werror("Unknown option %s", sys_cmd);
723        WerrorS("Use 'system(\"--\");' for listing of available options");
724        return TRUE;
725      }
726      // for Untyped Options (help version),
727      // setting it just triggers action
728      if (feOptSpec[opt].type == feOptUntyped)
729      {
730        feSetOptValue(opt,0);
731        return FALSE;
732      }
733      if (h == NULL)
734      {
735        if (feOptSpec[opt].type == feOptString)
736        {
737          res->rtyp = STRING_CMD;
738          const char *r=(const char*)feOptSpec[opt].value;
739          if (r == NULL) r="";
740          res->data = omStrDup(r);
741        }
742        else
743        {
744          res->rtyp = INT_CMD;
745          res->data = feOptSpec[opt].value;
746        }
747        return FALSE;
748      }
749      if (h->Typ() != STRING_CMD &&
750          h->Typ() != INT_CMD)
751      {
752        WerrorS("Need string or int argument to set option value");
753        return TRUE;
754      }
755      const char* errormsg;
756      if (h->Typ() == INT_CMD)
757      {
758        if (feOptSpec[opt].type == feOptString)
759        {
760          Werror("Need string argument to set value of option %s", sys_cmd);
761          return TRUE;
762        }
763        errormsg = feSetOptValue(opt, (int)((long) h->Data()));
764        if (errormsg != NULL)
765          Werror("Option '--%s=%d' %s", sys_cmd, (int) ((long)h->Data()), errormsg);
766      }
767      else
768      {
769        errormsg = feSetOptValue(opt, (char*) h->Data());
770        if (errormsg != NULL)
771          Werror("Option '--%s=%s' %s", sys_cmd, (char*) h->Data(), errormsg);
772      }
773      if (errormsg != NULL) return TRUE;
774      return FALSE;
775    }
776    else
777  /*==================== HC ==================================*/
778    if (strcmp(sys_cmd,"HC")==0)
779    {
780      res->rtyp=INT_CMD;
781      res->data=(void *)(long) HCord;
782      return FALSE;
783    }
784    else
785  /*==================== random ==================================*/
786    if(strcmp(sys_cmd,"random")==0)
787    {
788      const short t[]={1,INT_CMD};
789      if (h!=NULL)
790      {
791        if (iiCheckTypes(h,t,1))
792        {
793          siRandomStart=(int)((long)h->Data());
794          siSeed=siRandomStart;
795          factoryseed(siRandomStart);
796          return FALSE;
797        }
798        else
799        {
800          return TRUE;
801        }
802      }
803      res->rtyp=INT_CMD;
804      res->data=(void*)(long) siSeed;
805      return FALSE;
806    }
807    else
808  /*======================= demon_list =====================*/
809    if (strcmp(sys_cmd,"denom_list")==0)
810    {
811      res->rtyp=LIST_CMD;
812      extern lists get_denom_list();
813      res->data=(lists)get_denom_list();
814      return FALSE;
815    }
816    else
817    /*==================== complexNearZero ======================*/
818    if(strcmp(sys_cmd,"complexNearZero")==0)
819    {
820      const short t[]={2,NUMBER_CMD,INT_CMD};
821      if (iiCheckTypes(h,t,1))
822      {
823        if ( !rField_is_long_C(currRing) )
824        {
825          WerrorS( "unsupported ground field!");
826          return TRUE;
827        }
828        else
829        {
830          res->rtyp=INT_CMD;
831          res->data=(void*)complexNearZero((gmp_complex*)h->Data(),
832                             (int)((long)(h->next->Data())));
833          return FALSE;
834        }
835      }
836      else
837      {
838        return TRUE;
839      }
840    }
841    else
842  /*==================== getPrecDigits ======================*/
843    if(strcmp(sys_cmd,"getPrecDigits")==0)
844    {
845      if ( (currRing==NULL)
846      ||  (!rField_is_long_C(currRing) && !rField_is_long_R(currRing)))
847      {
848        WerrorS( "unsupported ground field!");
849        return TRUE;
850      }
851      res->rtyp=INT_CMD;
852      res->data=(void*)(long)gmp_output_digits;
853      //if (gmp_output_digits!=getGMPFloatDigits())
854      //{ Print("%d, %d\n",getGMPFloatDigits(),gmp_output_digits);}
855      return FALSE;
856    }
857    else
858  /*==================== lduDecomp ======================*/
859    if(strcmp(sys_cmd, "lduDecomp")==0)
860    {
861      const short t[]={1,MATRIX_CMD};
862      if (iiCheckTypes(h,t,1))
863      {
864        matrix aMat = (matrix)h->Data();
865        matrix pMat; matrix lMat; matrix dMat; matrix uMat;
866        poly l; poly u; poly prodLU;
867        lduDecomp(aMat, pMat, lMat, dMat, uMat, l, u, prodLU);
868        lists L = (lists)omAllocBin(slists_bin);
869        L->Init(7);
870        L->m[0].rtyp = MATRIX_CMD; L->m[0].data=(void*)pMat;
871        L->m[1].rtyp = MATRIX_CMD; L->m[1].data=(void*)lMat;
872        L->m[2].rtyp = MATRIX_CMD; L->m[2].data=(void*)dMat;
873        L->m[3].rtyp = MATRIX_CMD; L->m[3].data=(void*)uMat;
874        L->m[4].rtyp = POLY_CMD; L->m[4].data=(void*)l;
875        L->m[5].rtyp = POLY_CMD; L->m[5].data=(void*)u;
876        L->m[6].rtyp = POLY_CMD; L->m[6].data=(void*)prodLU;
877        res->rtyp = LIST_CMD;
878        res->data = (char *)L;
879        return FALSE;
880      }
881      else
882      {
883        return TRUE;
884      }
885    }
886    else
887  /*==================== lduSolve ======================*/
888    if(strcmp(sys_cmd, "lduSolve")==0)
889    {
890      /* for solving a linear equation system A * x = b, via the
891           given LDU-decomposition of the matrix A;
892           There is one valid parametrisation:
893           1) exactly eight arguments P, L, D, U, l, u, lTimesU, b;
894              P, L, D, and U realise the LDU-decomposition of A, that is,
895              P * A = L * D^(-1) * U, and P, L, D, and U satisfy the
896              properties decribed in method 'luSolveViaLDUDecomp' in
897              linearAlgebra.h; see there;
898              l, u, and lTimesU are as described in the same location;
899              b is the right-hand side vector of the linear equation system;
900           The method will return a list of either 1 entry or three entries:
901           1) [0] if there is no solution to the system;
902           2) [1, x, H] if there is at least one solution;
903              x is any solution of the given linear system,
904              H is the matrix with column vectors spanning the homogeneous
905              solution space.
906           The method produces an error if matrix and vector sizes do not
907           fit. */
908      const short t[]={7,MATRIX_CMD,MATRIX_CMD,MATRIX_CMD,MATRIX_CMD,POLY_CMD,POLY_CMD,MATRIX_CMD};
909      if (!iiCheckTypes(h,t,1))
910      {
911        return TRUE;
912      }
913      if (rField_is_Ring(currRing))
914      {
915        WerrorS("field required");
916        return TRUE;
917      }
918      matrix pMat  = (matrix)h->Data();
919      matrix lMat  = (matrix)h->next->Data();
920      matrix dMat  = (matrix)h->next->next->Data();
921      matrix uMat  = (matrix)h->next->next->next->Data();
922      poly l       = (poly)  h->next->next->next->next->Data();
923      poly u       = (poly)  h->next->next->next->next->next->Data();
924      poly lTimesU = (poly)  h->next->next->next->next->next->next->Data();
925      matrix bVec  = (matrix)h->next->next->next->next->next->next->next->Data();
926      matrix xVec; int solvable; matrix homogSolSpace;
927      if (pMat->rows() != pMat->cols())
928      {
929        Werror("first matrix (%d x %d) is not quadratic",
930                 pMat->rows(), pMat->cols());
931        return TRUE;
932      }
933      if (lMat->rows() != lMat->cols())
934      {
935        Werror("second matrix (%d x %d) is not quadratic",
936                 lMat->rows(), lMat->cols());
937        return TRUE;
938      }
939      if (dMat->rows() != dMat->cols())
940      {
941        Werror("third matrix (%d x %d) is not quadratic",
942                 dMat->rows(), dMat->cols());
943        return TRUE;
944      }
945      if (dMat->cols() != uMat->rows())
946      {
947        Werror("third matrix (%d x %d) and fourth matrix (%d x %d) %s",
948                 dMat->rows(), dMat->cols(), uMat->rows(), uMat->cols(),
949                 "do not t");
950        return TRUE;
951      }
952      if (uMat->rows() != bVec->rows())
953      {
954        Werror("fourth matrix (%d x %d) and vector (%d x 1) do not fit",
955                 uMat->rows(), uMat->cols(), bVec->rows());
956        return TRUE;
957      }
958      solvable = luSolveViaLDUDecomp(pMat, lMat, dMat, uMat, l, u, lTimesU,
959                                       bVec, xVec, homogSolSpace);
960
961      /* build the return structure; a list with either one or
962           three entries */
963      lists ll = (lists)omAllocBin(slists_bin);
964      if (solvable)
965      {
966        ll->Init(3);
967        ll->m[0].rtyp=INT_CMD;    ll->m[0].data=(void *)(long)solvable;
968        ll->m[1].rtyp=MATRIX_CMD; ll->m[1].data=(void *)xVec;
969        ll->m[2].rtyp=MATRIX_CMD; ll->m[2].data=(void *)homogSolSpace;
970      }
971      else
972      {
973        ll->Init(1);
974        ll->m[0].rtyp=INT_CMD;    ll->m[0].data=(void *)(long)solvable;
975      }
976      res->rtyp = LIST_CMD;
977      res->data=(char*)ll;
978      return FALSE;
979    }
980    else
981  /*==== countedref: reference and shared ====*/
982    if (strcmp(sys_cmd, "shared") == 0)
983    {
984      #ifndef SI_COUNTEDREF_AUTOLOAD
985      void countedref_shared_load();
986      countedref_shared_load();
987      #endif
988      res->rtyp = NONE;
989      return FALSE;
990    }
991    else if (strcmp(sys_cmd, "reference") == 0)
992    {
993      #ifndef SI_COUNTEDREF_AUTOLOAD
994      void countedref_reference_load();
995      countedref_reference_load();
996      #endif
997      res->rtyp = NONE;
998      return FALSE;
999    }
1000    else
1001/*==================== semaphore =================*/
1002#ifdef HAVE_SIMPLEIPC
1003    if (strcmp(sys_cmd,"semaphore")==0)
1004    {
1005      if((h!=NULL) && (h->Typ()==STRING_CMD) && (h->next!=NULL) && (h->next->Typ()==INT_CMD))
1006      {
1007        int v=1;
1008        if ((h->next->next!=NULL)&& (h->next->next->Typ()==INT_CMD))
1009          v=(int)(long)h->next->next->Data();
1010        res->data=(char *)(long)simpleipc_cmd((char *)h->Data(),(int)(long)h->next->Data(),v);
1011        res->rtyp=INT_CMD;
1012        return FALSE;
1013      }
1014      else
1015      {
1016        WerrorS("Usage: system(\"semaphore\",<cmd>,int)");
1017        return TRUE;
1018      }
1019    }
1020    else
1021#endif
1022/*==================== reserved port =================*/
1023    if (strcmp(sys_cmd,"reserve")==0)
1024    {
1025      int ssiReservePort(int clients);
1026      const short t[]={1,INT_CMD};
1027      if (iiCheckTypes(h,t,1))
1028      {
1029        res->rtyp=INT_CMD;
1030        int p=ssiReservePort((int)(long)h->Data());
1031        res->data=(void*)(long)p;
1032        return (p==0);
1033      }
1034      return TRUE;
1035    }
1036    else
1037/*==================== reserved link =================*/
1038    if (strcmp(sys_cmd,"reservedLink")==0)
1039    {
1040      res->rtyp=LINK_CMD;
1041      si_link p=ssiCommandLink();
1042      res->data=(void*)p;
1043      return (p==NULL);
1044    }
1045    else
1046/*==================== install newstruct =================*/
1047    if (strcmp(sys_cmd,"install")==0)
1048    {
1049      const short t[]={4,STRING_CMD,STRING_CMD,PROC_CMD,INT_CMD};
1050      if (iiCheckTypes(h,t,1))
1051      {
1052        return newstruct_set_proc((char*)h->Data(),(char*)h->next->Data(),
1053                                (int)(long)h->next->next->next->Data(),
1054                                (procinfov)h->next->next->Data());
1055      }
1056      return TRUE;
1057    }
1058    else
1059/*==================== newstruct =================*/
1060    if (strcmp(sys_cmd,"newstruct")==0)
1061    {
1062      const short t[]={1,STRING_CMD};
1063      if (iiCheckTypes(h,t,1))
1064      {
1065        int id=0;
1066        char *n=(char*)h->Data();
1067        blackboxIsCmd(n,id);
1068        if (id>0)
1069        {
1070          blackbox *bb=getBlackboxStuff(id);
1071          if (BB_LIKE_LIST(bb))
1072          {
1073            newstruct_desc desc=(newstruct_desc)bb->data;
1074            newstructShow(desc);
1075            return FALSE;
1076          }
1077          else Werror("'%s' is not a newstruct",n);
1078        }
1079        else Werror("'%s' is not a blackbox object",n);
1080      }
1081      return TRUE;
1082    }
1083    else
1084/*==================== blackbox =================*/
1085    if (strcmp(sys_cmd,"blackbox")==0)
1086    {
1087      printBlackboxTypes();
1088      return FALSE;
1089    }
1090    else
1091  /*================= absBiFact ======================*/
1092    #if defined(HAVE_FLINT) || defined(HAVE_NTL)
1093    if (strcmp(sys_cmd, "absFact") == 0)
1094    {
1095      const short t[]={1,POLY_CMD};
1096      if (iiCheckTypes(h,t,1)
1097      && (currRing!=NULL)
1098      && (getCoeffType(currRing->cf)==n_transExt))
1099      {
1100        res->rtyp=LIST_CMD;
1101        intvec *v=NULL;
1102        ideal mipos= NULL;
1103        int n= 0;
1104        ideal f=singclap_absFactorize((poly)(h->Data()), mipos, &v, n, currRing);
1105        if (f==NULL) return TRUE;
1106        ivTest(v);
1107        lists l=(lists)omAllocBin(slists_bin);
1108        l->Init(4);
1109        l->m[0].rtyp=IDEAL_CMD;
1110        l->m[0].data=(void *)f;
1111        l->m[1].rtyp=INTVEC_CMD;
1112        l->m[1].data=(void *)v;
1113        l->m[2].rtyp=IDEAL_CMD;
1114        l->m[2].data=(void*) mipos;
1115        l->m[3].rtyp=INT_CMD;
1116        l->m[3].data=(void*) (long) n;
1117        res->data=(void *)l;
1118        return FALSE;
1119      }
1120      else return TRUE;
1121    }
1122    else
1123    #endif
1124  /* =================== LLL via NTL ==============================*/
1125  #ifdef HAVE_NTL
1126    if (strcmp(sys_cmd, "LLL") == 0)
1127    {
1128      if (h!=NULL)
1129      {
1130        res->rtyp=h->Typ();
1131        if (h->Typ()==MATRIX_CMD)
1132        {
1133          res->data=(char *)singntl_LLL((matrix)h->Data(), currRing);
1134          return FALSE;
1135        }
1136        else if (h->Typ()==INTMAT_CMD)
1137        {
1138          res->data=(char *)singntl_LLL((intvec*)h->Data());
1139          return FALSE;
1140        }
1141        else return TRUE;
1142      }
1143      else return TRUE;
1144    }
1145    else
1146  #endif
1147  /* =================== LLL via Flint ==============================*/
1148  #ifdef HAVE_FLINT
1149  #if __FLINT_RELEASE >= 20500
1150    if (strcmp(sys_cmd, "LLL_Flint") == 0)
1151    {
1152      if (h!=NULL)
1153      {
1154        if(h->next == NULL)
1155        {
1156            res->rtyp=h->Typ();
1157            if (h->Typ()==BIGINTMAT_CMD)
1158            {
1159              res->data=(char *)singflint_LLL((bigintmat*)h->Data(), NULL);
1160              return FALSE;
1161            }
1162            else if (h->Typ()==INTMAT_CMD)
1163            {
1164              res->data=(char *)singflint_LLL((intvec*)h->Data(), NULL);
1165              return FALSE;
1166            }
1167            else return TRUE;
1168        }
1169        if(h->next->Typ()!= INT_CMD)
1170        {
1171            WerrorS("matrix,int or bigint,int expected");
1172            return TRUE;
1173        }
1174        if(h->next->Typ()== INT_CMD)
1175        {
1176            if(((int)((long)(h->next->Data())) != 0) && (int)((long)(h->next->Data()) != 1))
1177            {
1178                WerrorS("int is different from 0, 1");
1179                return TRUE;
1180            }
1181            res->rtyp=h->Typ();
1182            if((long)(h->next->Data()) == 0)
1183            {
1184                if (h->Typ()==BIGINTMAT_CMD)
1185                {
1186                  res->data=(char *)singflint_LLL((bigintmat*)h->Data(), NULL);
1187                  return FALSE;
1188                }
1189                else if (h->Typ()==INTMAT_CMD)
1190                {
1191                  res->data=(char *)singflint_LLL((intvec*)h->Data(), NULL);
1192                  return FALSE;
1193                }
1194                else return TRUE;
1195            }
1196            // This will give also the transformation matrix U s.t. res = U * m
1197            if((long)(h->next->Data()) == 1)
1198            {
1199                if (h->Typ()==BIGINTMAT_CMD)
1200                {
1201                  bigintmat* m = (bigintmat*)h->Data();
1202                  bigintmat* T = new bigintmat(m->rows(),m->rows(),m->basecoeffs());
1203                  for(int i = 1; i<=m->rows(); i++)
1204                  {
1205                    n_Delete(&(BIMATELEM(*T,i,i)),T->basecoeffs());
1206                    BIMATELEM(*T,i,i)=n_Init(1, T->basecoeffs());
1207                  }
1208                  m = singflint_LLL(m,T);
1209                  lists L = (lists)omAllocBin(slists_bin);
1210                  L->Init(2);
1211                  L->m[0].rtyp = BIGINTMAT_CMD;  L->m[0].data = (void*)m;
1212                  L->m[1].rtyp = BIGINTMAT_CMD;  L->m[1].data = (void*)T;
1213                  res->data=L;
1214                  res->rtyp=LIST_CMD;
1215                  return FALSE;
1216                }
1217                else if (h->Typ()==INTMAT_CMD)
1218                {
1219                  intvec* m = (intvec*)h->Data();
1220                  intvec* T = new intvec(m->rows(),m->rows(),(int)0);
1221                  for(int i = 1; i<=m->rows(); i++)
1222                    IMATELEM(*T,i,i)=1;
1223                  m = singflint_LLL(m,T);
1224                  lists L = (lists)omAllocBin(slists_bin);
1225                  L->Init(2);
1226                  L->m[0].rtyp = INTMAT_CMD;  L->m[0].data = (void*)m;
1227                  L->m[1].rtyp = INTMAT_CMD;  L->m[1].data = (void*)T;
1228                  res->data=L;
1229                  res->rtyp=LIST_CMD;
1230                  return FALSE;
1231                }
1232                else return TRUE;
1233            }
1234        }
1235
1236      }
1237      else return TRUE;
1238    }
1239    else
1240  #endif
1241  #endif
1242/* ====== rref ============================*/
1243  #if defined(HAVE_FLINT) || defined(HAVE_NTL)
1244  if(strcmp(sys_cmd,"rref")==0)
1245  {
1246    const short t1[]={1,MATRIX_CMD};
1247    const short t2[]={1,SMATRIX_CMD};
1248    if (iiCheckTypes(h,t1,0))
1249    {
1250      matrix M=(matrix)h->Data();
1251      #if defined(HAVE_FLINT)
1252      res->data=(void*)singflint_rref(M,currRing);
1253      #elif defined(HAVE_NTL)
1254      res->data=(void*)singntl_rref(M,currRing);
1255      #endif
1256      res->rtyp=MATRIX_CMD;
1257      return FALSE;
1258    }
1259    else if (iiCheckTypes(h,t2,1))
1260    {
1261      ideal M=(ideal)h->Data();
1262      #if defined(HAVE_FLINT)
1263      res->data=(void*)singflint_rref(M,currRing);
1264      #elif defined(HAVE_NTL)
1265      res->data=(void*)singntl_rref(M,currRing);
1266      #endif
1267      res->rtyp=SMATRIX_CMD;
1268      return FALSE;
1269    }
1270    else
1271    {
1272      WerrorS("expected system(\"rref\",<matrix>/<smatrix>)");
1273      return TRUE;
1274    }
1275  }
1276  else
1277  #endif
1278  /*==================== pcv ==================================*/
1279  #ifdef HAVE_PCV
1280    if(strcmp(sys_cmd,"pcvLAddL")==0)
1281    {
1282      return pcvLAddL(res,h);
1283    }
1284    else
1285    if(strcmp(sys_cmd,"pcvPMulL")==0)
1286    {
1287      return pcvPMulL(res,h);
1288    }
1289    else
1290    if(strcmp(sys_cmd,"pcvMinDeg")==0)
1291    {
1292      return pcvMinDeg(res,h);
1293    }
1294    else
1295    if(strcmp(sys_cmd,"pcvP2CV")==0)
1296    {
1297      return pcvP2CV(res,h);
1298    }
1299    else
1300    if(strcmp(sys_cmd,"pcvCV2P")==0)
1301    {
1302      return pcvCV2P(res,h);
1303    }
1304    else
1305    if(strcmp(sys_cmd,"pcvDim")==0)
1306    {
1307      return pcvDim(res,h);
1308    }
1309    else
1310    if(strcmp(sys_cmd,"pcvBasis")==0)
1311    {
1312      return pcvBasis(res,h);
1313    }
1314    else
1315  #endif
1316  /*==================== hessenberg/eigenvalues ==================================*/
1317  #ifdef HAVE_EIGENVAL
1318    if(strcmp(sys_cmd,"hessenberg")==0)
1319    {
1320      return evHessenberg(res,h);
1321    }
1322    else
1323  #endif
1324  /*==================== eigenvalues ==================================*/
1325  #ifdef HAVE_EIGENVAL
1326    if(strcmp(sys_cmd,"eigenvals")==0)
1327    {
1328      return evEigenvals(res,h);
1329    }
1330    else
1331  #endif
1332  /*==================== rowelim ==================================*/
1333  #ifdef HAVE_EIGENVAL
1334    if(strcmp(sys_cmd,"rowelim")==0)
1335    {
1336      return evRowElim(res,h);
1337    }
1338    else
1339  #endif
1340  /*==================== rowcolswap ==================================*/
1341  #ifdef HAVE_EIGENVAL
1342    if(strcmp(sys_cmd,"rowcolswap")==0)
1343    {
1344      return evSwap(res,h);
1345    }
1346    else
1347  #endif
1348  /*==================== Gauss-Manin system ==================================*/
1349  #ifdef HAVE_GMS
1350    if(strcmp(sys_cmd,"gmsnf")==0)
1351    {
1352      return gmsNF(res,h);
1353    }
1354    else
1355  #endif
1356  /*==================== contributors =============================*/
1357    if(strcmp(sys_cmd,"contributors") == 0)
1358    {
1359      res->rtyp=STRING_CMD;
1360      res->data=(void *)omStrDup(
1361         "Olaf Bachmann, Michael Brickenstein, Hubert Grassmann, Kai Krueger, Victor Levandovskyy, Wolfgang Neumann, Thomas Nuessler, Wilfred Pohl, Jens Schmidt, Mathias Schulze, Thomas Siebert, Ruediger Stobbe, Moritz Wenk, Tim Wichmann");
1362      return FALSE;
1363    }
1364    else
1365  /*==================== spectrum =============================*/
1366    #ifdef HAVE_SPECTRUM
1367    if(strcmp(sys_cmd,"spectrum") == 0)
1368    {
1369      if ((h==NULL) || (h->Typ()!=POLY_CMD))
1370      {
1371        WerrorS("poly expected");
1372        return TRUE;
1373      }
1374      if (h->next==NULL)
1375        return spectrumProc(res,h);
1376      if (h->next->Typ()!=INT_CMD)
1377      {
1378        WerrorS("poly,int expected");
1379        return TRUE;
1380      }
1381      if(((long)h->next->Data())==1L)
1382         return spectrumfProc(res,h);
1383      return spectrumProc(res,h);
1384    }
1385    else
1386  /*==================== semic =============================*/
1387    if(strcmp(sys_cmd,"semic") == 0)
1388    {
1389      if ((h->next!=NULL)
1390      && (h->Typ()==LIST_CMD)
1391      && (h->next->Typ()==LIST_CMD))
1392      {
1393        if (h->next->next==NULL)
1394          return semicProc(res,h,h->next);
1395        else if (h->next->next->Typ()==INT_CMD)
1396          return semicProc3(res,h,h->next,h->next->next);
1397      }
1398      return TRUE;
1399    }
1400    else
1401  /*==================== spadd =============================*/
1402    if(strcmp(sys_cmd,"spadd") == 0)
1403    {
1404      const short t[]={2,LIST_CMD,LIST_CMD};
1405      if (iiCheckTypes(h,t,1))
1406      {
1407        return spaddProc(res,h,h->next);
1408      }
1409      return TRUE;
1410    }
1411    else
1412  /*==================== spmul =============================*/
1413    if(strcmp(sys_cmd,"spmul") == 0)
1414    {
1415      const short t[]={2,LIST_CMD,INT_CMD};
1416      if (iiCheckTypes(h,t,1))
1417      {
1418        return spmulProc(res,h,h->next);
1419      }
1420      return TRUE;
1421    }
1422    else
1423  #endif
1424/*==================== tensorModuleMult ========================= */
1425  #define HAVE_SHEAFCOH_TRICKS 1
1426
1427  #ifdef HAVE_SHEAFCOH_TRICKS
1428    if(strcmp(sys_cmd,"tensorModuleMult")==0)
1429    {
1430      const short t[]={2,INT_CMD,MODUL_CMD};
1431  //      WarnS("tensorModuleMult!");
1432      if (iiCheckTypes(h,t,1))
1433      {
1434        int m = (int)( (long)h->Data() );
1435        ideal M = (ideal)h->next->Data();
1436        res->rtyp=MODUL_CMD;
1437        res->data=(void *)id_TensorModuleMult(m, M, currRing);
1438        return FALSE;
1439      }
1440      return TRUE;
1441    }
1442    else
1443  #endif
1444  /*==================== twostd  =================*/
1445  #ifdef HAVE_PLURAL
1446    if (strcmp(sys_cmd, "twostd") == 0)
1447    {
1448      ideal I;
1449      if ((h!=NULL) && (h->Typ()==IDEAL_CMD))
1450      {
1451        I=(ideal)h->CopyD();
1452        res->rtyp=IDEAL_CMD;
1453        if (rIsPluralRing(currRing)) res->data=twostd(I);
1454        else res->data=I;
1455        setFlag(res,FLAG_TWOSTD);
1456        setFlag(res,FLAG_STD);
1457      }
1458      else return TRUE;
1459      return FALSE;
1460    }
1461    else
1462  #endif
1463  /*==================== lie bracket =================*/
1464  #ifdef HAVE_PLURAL
1465    if (strcmp(sys_cmd, "bracket") == 0)
1466    {
1467      const short t[]={2,POLY_CMD,POLY_CMD};
1468      if (iiCheckTypes(h,t,1))
1469      {
1470        poly p=(poly)h->CopyD();
1471        h=h->next;
1472        poly q=(poly)h->Data();
1473        res->rtyp=POLY_CMD;
1474        if (rIsPluralRing(currRing))  res->data=nc_p_Bracket_qq(p,q, currRing);
1475        return FALSE;
1476      }
1477      return TRUE;
1478    }
1479    else
1480  #endif
1481  /*==================== env ==================================*/
1482  #ifdef HAVE_PLURAL
1483    if (strcmp(sys_cmd, "env")==0)
1484    {
1485      if ((h!=NULL) && (h->Typ()==RING_CMD))
1486      {
1487        ring r = (ring)h->Data();
1488        res->data = rEnvelope(r);
1489        res->rtyp = RING_CMD;
1490        return FALSE;
1491      }
1492      else
1493      {
1494        WerrorS("`system(\"env\",<ring>)` expected");
1495        return TRUE;
1496      }
1497    }
1498    else
1499  #endif
1500/* ============ opp ======================== */
1501  #ifdef HAVE_PLURAL
1502    if (strcmp(sys_cmd, "opp")==0)
1503    {
1504      if ((h!=NULL) && (h->Typ()==RING_CMD))
1505      {
1506        ring r=(ring)h->Data();
1507        res->data=rOpposite(r);
1508        res->rtyp=RING_CMD;
1509        return FALSE;
1510      }
1511      else
1512      {
1513        WerrorS("`system(\"opp\",<ring>)` expected");
1514        return TRUE;
1515      }
1516    }
1517    else
1518  #endif
1519  /*==================== oppose ==================================*/
1520  #ifdef HAVE_PLURAL
1521    if (strcmp(sys_cmd, "oppose")==0)
1522    {
1523      if ((h!=NULL) && (h->Typ()==RING_CMD)
1524      && (h->next!= NULL))
1525      {
1526        ring Rop = (ring)h->Data();
1527        h   = h->next;
1528        idhdl w;
1529        if ((w=Rop->idroot->get(h->Name(),myynest))!=NULL)
1530        {
1531          poly p = (poly)IDDATA(w);
1532          res->data = pOppose(Rop, p, currRing); // into CurrRing?
1533          res->rtyp = POLY_CMD;
1534          return FALSE;
1535        }
1536      }
1537      else
1538      {
1539        WerrorS("`system(\"oppose\",<ring>,<poly>)` expected");
1540        return TRUE;
1541      }
1542    }
1543    else
1544  #endif
1545  /*==================== walk stuff =================*/
1546  /*==================== walkNextWeight =================*/
1547  #ifdef HAVE_WALK
1548  #ifdef OWNW
1549    if (strcmp(sys_cmd, "walkNextWeight") == 0)
1550    {
1551      const short t[]={3,INTVEC_CMD,INTVEC_CMD,IDEAL_CMD};
1552      if (!iiCheckTypes(h,t,1)) return TRUE;
1553      if (((intvec*) h->Data())->length() != currRing->N ||
1554          ((intvec*) h->next->Data())->length() != currRing->N)
1555      {
1556        Werror("system(\"walkNextWeight\" ...) intvecs not of length %d\n",
1557               currRing->N);
1558        return TRUE;
1559      }
1560      res->data = (void*) walkNextWeight(((intvec*) h->Data()),
1561                                         ((intvec*) h->next->Data()),
1562                                         (ideal) h->next->next->Data());
1563      if (res->data == NULL || res->data == (void*) 1L)
1564      {
1565        res->rtyp = INT_CMD;
1566      }
1567      else
1568      {
1569        res->rtyp = INTVEC_CMD;
1570      }
1571      return FALSE;
1572    }
1573    else
1574  #endif
1575  #endif
1576  /*==================== walkNextWeight =================*/
1577  #ifdef HAVE_WALK
1578  #ifdef OWNW
1579    if (strcmp(sys_cmd, "walkInitials") == 0)
1580    {
1581      if (h == NULL || h->Typ() != IDEAL_CMD)
1582      {
1583        WerrorS("system(\"walkInitials\", ideal) expected");
1584        return TRUE;
1585      }
1586      res->data = (void*) walkInitials((ideal) h->Data());
1587      res->rtyp = IDEAL_CMD;
1588      return FALSE;
1589    }
1590    else
1591  #endif
1592  #endif
1593  /*==================== walkAddIntVec =================*/
1594  #ifdef HAVE_WALK
1595  #ifdef WAIV
1596    if (strcmp(sys_cmd, "walkAddIntVec") == 0)
1597    {
1598      const short t[]={2,INTVEC_CMD,INTVEC_CMD};
1599      if (!iiCheckTypes(h,t,1)) return TRUE;
1600      intvec* arg1 = (intvec*) h->Data();
1601      intvec* arg2 = (intvec*) h->next->Data();
1602      res->data = (intvec*) walkAddIntVec(arg1, arg2);
1603      res->rtyp = INTVEC_CMD;
1604      return FALSE;
1605    }
1606    else
1607  #endif
1608  #endif
1609  /*==================== MwalkNextWeight =================*/
1610  #ifdef HAVE_WALK
1611  #ifdef MwaklNextWeight
1612    if (strcmp(sys_cmd, "MwalkNextWeight") == 0)
1613    {
1614      const short t[]={3,INTVEC_CMD,INTVEC_CMD,IDEAL_CMD};
1615      if (!iiCheckTypes(h,t,1)) return TRUE;
1616      if (((intvec*) h->Data())->length() != currRing->N ||
1617        ((intvec*) h->next->Data())->length() != currRing->N)
1618      {
1619        Werror("system(\"MwalkNextWeight\" ...) intvecs not of length %d\n",
1620               currRing->N);
1621        return TRUE;
1622      }
1623      intvec* arg1 = (intvec*) h->Data();
1624      intvec* arg2 = (intvec*) h->next->Data();
1625      ideal arg3   =   (ideal) h->next->next->Data();
1626      intvec* result = (intvec*) MwalkNextWeight(arg1, arg2, arg3);
1627      res->rtyp = INTVEC_CMD;
1628      res->data =  result;
1629      return FALSE;
1630    }
1631    else
1632  #endif //MWalkNextWeight
1633  #endif
1634  /*==================== Mivdp =================*/
1635  #ifdef HAVE_WALK
1636    if(strcmp(sys_cmd, "Mivdp") == 0)
1637    {
1638      if (h == NULL || h->Typ() != INT_CMD)
1639      {
1640        WerrorS("system(\"Mivdp\", int) expected");
1641        return TRUE;
1642      }
1643      if ((int) ((long)(h->Data())) != currRing->N)
1644      {
1645        Werror("system(\"Mivdp\" ...) intvecs not of length %d\n",
1646               currRing->N);
1647        return TRUE;
1648      }
1649      int arg1 = (int) ((long)(h->Data()));
1650      intvec* result = (intvec*) Mivdp(arg1);
1651      res->rtyp = INTVEC_CMD;
1652      res->data =  result;
1653      return FALSE;
1654    }
1655    else
1656  #endif
1657  /*==================== Mivlp =================*/
1658  #ifdef HAVE_WALK
1659    if(strcmp(sys_cmd, "Mivlp") == 0)
1660    {
1661      if (h == NULL || h->Typ() != INT_CMD)
1662      {
1663        WerrorS("system(\"Mivlp\", int) expected");
1664        return TRUE;
1665      }
1666      if ((int) ((long)(h->Data())) != currRing->N)
1667      {
1668        Werror("system(\"Mivlp\" ...) intvecs not of length %d\n",
1669               currRing->N);
1670        return TRUE;
1671      }
1672      int arg1 = (int) ((long)(h->Data()));
1673      intvec* result = (intvec*) Mivlp(arg1);
1674      res->rtyp = INTVEC_CMD;
1675      res->data =  result;
1676      return FALSE;
1677    }
1678    else
1679  #endif
1680  /*==================== MpDiv =================*/
1681  #ifdef HAVE_WALK
1682  #ifdef MpDiv
1683    if(strcmp(sys_cmd, "MpDiv") == 0)
1684    {
1685      const short t[]={2,POLY_CMD,POLY_CMD};
1686      if (!iiCheckTypes(h,t,1)) return TRUE;
1687      poly arg1 = (poly) h->Data();
1688      poly arg2 = (poly) h->next->Data();
1689      poly result = MpDiv(arg1, arg2);
1690      res->rtyp = POLY_CMD;
1691      res->data = result;
1692      return FALSE;
1693    }
1694    else
1695  #endif
1696  #endif
1697  /*==================== MpMult =================*/
1698  #ifdef HAVE_WALK
1699  #ifdef MpMult
1700    if(strcmp(sys_cmd, "MpMult") == 0)
1701    {
1702      const short t[]={2,POLY_CMD,POLY_CMD};
1703      if (!iiCheckTypes(h,t,1)) return TRUE;
1704      poly arg1 = (poly) h->Data();
1705      poly arg2 = (poly) h->next->Data();
1706      poly result = MpMult(arg1, arg2);
1707      res->rtyp = POLY_CMD;
1708      res->data = result;
1709      return FALSE;
1710    }
1711    else
1712  #endif
1713  #endif
1714  /*==================== MivSame =================*/
1715  #ifdef HAVE_WALK
1716    if (strcmp(sys_cmd, "MivSame") == 0)
1717    {
1718      const short t[]={2,INTVEC_CMD,INTVEC_CMD};
1719      if (!iiCheckTypes(h,t,1)) return TRUE;
1720      /*
1721      if (((intvec*) h->Data())->length() != currRing->N ||
1722      ((intvec*) h->next->Data())->length() != currRing->N)
1723      {
1724        Werror("system(\"MivSame\" ...) intvecs not of length %d\n",
1725               currRing->N);
1726        return TRUE;
1727      }
1728      */
1729      intvec* arg1 = (intvec*) h->Data();
1730      intvec* arg2 = (intvec*) h->next->Data();
1731      /*
1732      poly result = (poly) MivSame(arg1, arg2);
1733      res->rtyp = POLY_CMD;
1734      res->data =  (poly) result;
1735      */
1736      res->rtyp = INT_CMD;
1737      res->data = (void*)(long) MivSame(arg1, arg2);
1738      return FALSE;
1739    }
1740    else
1741  #endif
1742  /*==================== M3ivSame =================*/
1743  #ifdef HAVE_WALK
1744    if (strcmp(sys_cmd, "M3ivSame") == 0)
1745    {
1746      const short t[]={3,INTVEC_CMD,INTVEC_CMD,INTVEC_CMD};
1747      if (!iiCheckTypes(h,t,1)) return TRUE;
1748      /*
1749      if (((intvec*) h->Data())->length() != currRing->N ||
1750        ((intvec*) h->next->Data())->length() != currRing->N ||
1751        ((intvec*) h->next->next->Data())->length() != currRing->N )
1752      {
1753        Werror("system(\"M3ivSame\" ...) intvecs not of length %d\n",
1754              currRing->N);
1755        return TRUE;
1756      }
1757      */
1758      intvec* arg1 = (intvec*) h->Data();
1759      intvec* arg2 = (intvec*) h->next->Data();
1760      intvec* arg3 = (intvec*) h->next->next->Data();
1761      /*
1762      poly result = (poly) M3ivSame(arg1, arg2, arg3);
1763      res->rtyp = POLY_CMD;
1764      res->data =  (poly) result;
1765      */
1766      res->rtyp = INT_CMD;
1767      res->data = (void*)(long) M3ivSame(arg1, arg2, arg3);
1768      return FALSE;
1769    }
1770    else
1771  #endif
1772  /*==================== MwalkInitialForm =================*/
1773  #ifdef HAVE_WALK
1774    if(strcmp(sys_cmd, "MwalkInitialForm") == 0)
1775    {
1776      const short t[]={2,IDEAL_CMD,INTVEC_CMD};
1777      if (!iiCheckTypes(h,t,1)) return TRUE;
1778      if(((intvec*) h->next->Data())->length() != currRing->N)
1779      {
1780        Werror("system \"MwalkInitialForm\"...) intvec not of length %d\n",
1781               currRing->N);
1782        return TRUE;
1783      }
1784      ideal id      = (ideal) h->Data();
1785      intvec* int_w = (intvec*) h->next->Data();
1786      ideal result  = (ideal) MwalkInitialForm(id, int_w);
1787      res->rtyp = IDEAL_CMD;
1788      res->data = result;
1789      return FALSE;
1790    }
1791    else
1792  #endif
1793  /*==================== MivMatrixOrder =================*/
1794  #ifdef HAVE_WALK
1795    /************** Perturbation walk **********/
1796    if(strcmp(sys_cmd, "MivMatrixOrder") == 0)
1797    {
1798      if(h==NULL || h->Typ() != INTVEC_CMD)
1799      {
1800        WerrorS("system(\"MivMatrixOrder\",intvec) expected");
1801        return TRUE;
1802      }
1803      intvec* arg1 = (intvec*) h->Data();
1804      intvec* result = MivMatrixOrder(arg1);
1805      res->rtyp = INTVEC_CMD;
1806      res->data =  result;
1807      return FALSE;
1808    }
1809    else
1810  #endif
1811  /*==================== MivMatrixOrderdp =================*/
1812  #ifdef HAVE_WALK
1813    if(strcmp(sys_cmd, "MivMatrixOrderdp") == 0)
1814    {
1815      if(h==NULL || h->Typ() != INT_CMD)
1816      {
1817        WerrorS("system(\"MivMatrixOrderdp\",intvec) expected");
1818        return TRUE;
1819      }
1820      int arg1 = (int) ((long)(h->Data()));
1821      intvec* result = (intvec*) MivMatrixOrderdp(arg1);
1822      res->rtyp = INTVEC_CMD;
1823      res->data =  result;
1824      return FALSE;
1825    }
1826    else
1827  #endif
1828  /*==================== MPertVectors =================*/
1829  #ifdef HAVE_WALK
1830    if(strcmp(sys_cmd, "MPertVectors") == 0)
1831    {
1832      const short t[]={3,IDEAL_CMD,INTVEC_CMD,INT_CMD};
1833      if (!iiCheckTypes(h,t,1)) return TRUE;
1834      ideal arg1 = (ideal) h->Data();
1835      intvec* arg2 = (intvec*) h->next->Data();
1836      int arg3 = (int) ((long)(h->next->next->Data()));
1837      intvec* result = (intvec*) MPertVectors(arg1, arg2, arg3);
1838      res->rtyp = INTVEC_CMD;
1839      res->data =  result;
1840      return FALSE;
1841    }
1842    else
1843  #endif
1844  /*==================== MPertVectorslp =================*/
1845  #ifdef HAVE_WALK
1846    if(strcmp(sys_cmd, "MPertVectorslp") == 0)
1847    {
1848      const short t[]={3,IDEAL_CMD,INTVEC_CMD,INT_CMD};
1849      if (!iiCheckTypes(h,t,1)) return TRUE;
1850      ideal arg1 = (ideal) h->Data();
1851      intvec* arg2 = (intvec*) h->next->Data();
1852      int arg3 = (int) ((long)(h->next->next->Data()));
1853      intvec* result = (intvec*) MPertVectorslp(arg1, arg2, arg3);
1854      res->rtyp = INTVEC_CMD;
1855      res->data =  result;
1856      return FALSE;
1857    }
1858    else
1859  #endif
1860    /************** fractal walk **********/
1861  #ifdef HAVE_WALK
1862    if(strcmp(sys_cmd, "Mfpertvector") == 0)
1863    {
1864      const short t[]={2,IDEAL_CMD,INTVEC_CMD};
1865      if (!iiCheckTypes(h,t,1)) return TRUE;
1866      ideal arg1 = (ideal) h->Data();
1867      intvec* arg2 = (intvec*) h->next->Data();
1868      intvec* result = Mfpertvector(arg1, arg2);
1869      res->rtyp = INTVEC_CMD;
1870      res->data =  result;
1871      return FALSE;
1872    }
1873    else
1874  #endif
1875  /*==================== MivUnit =================*/
1876  #ifdef HAVE_WALK
1877    if(strcmp(sys_cmd, "MivUnit") == 0)
1878    {
1879      const short t[]={1,INT_CMD};
1880      if (!iiCheckTypes(h,t,1)) return TRUE;
1881      int arg1 = (int) ((long)(h->Data()));
1882      intvec* result = (intvec*) MivUnit(arg1);
1883      res->rtyp = INTVEC_CMD;
1884      res->data =  result;
1885      return FALSE;
1886    }
1887    else
1888  #endif
1889  /*==================== MivWeightOrderlp =================*/
1890  #ifdef HAVE_WALK
1891    if(strcmp(sys_cmd, "MivWeightOrderlp") == 0)
1892    {
1893      const short t[]={1,INTVEC_CMD};
1894      if (!iiCheckTypes(h,t,1)) return TRUE;
1895      intvec* arg1 = (intvec*) h->Data();
1896      intvec* result = MivWeightOrderlp(arg1);
1897      res->rtyp = INTVEC_CMD;
1898      res->data =  result;
1899      return FALSE;
1900    }
1901    else
1902  #endif
1903  /*==================== MivWeightOrderdp =================*/
1904  #ifdef HAVE_WALK
1905    if(strcmp(sys_cmd, "MivWeightOrderdp") == 0)
1906    {
1907      if(h==NULL || h->Typ() != INTVEC_CMD)
1908      {
1909        WerrorS("system(\"MivWeightOrderdp\",intvec) expected");
1910        return TRUE;
1911      }
1912      intvec* arg1 = (intvec*) h->Data();
1913      //int arg2 = (int) h->next->Data();
1914      intvec* result = MivWeightOrderdp(arg1);
1915      res->rtyp = INTVEC_CMD;
1916      res->data =  result;
1917      return FALSE;
1918    }
1919    else
1920  #endif
1921  /*==================== MivMatrixOrderlp =================*/
1922  #ifdef HAVE_WALK
1923    if(strcmp(sys_cmd, "MivMatrixOrderlp") == 0)
1924    {
1925      if(h==NULL || h->Typ() != INT_CMD)
1926      {
1927        WerrorS("system(\"MivMatrixOrderlp\",int) expected");
1928        return TRUE;
1929      }
1930      int arg1 = (int) ((long)(h->Data()));
1931      intvec* result = (intvec*) MivMatrixOrderlp(arg1);
1932      res->rtyp = INTVEC_CMD;
1933      res->data =  result;
1934      return FALSE;
1935    }
1936    else
1937  #endif
1938  /*==================== MkInterRedNextWeight =================*/
1939  #ifdef HAVE_WALK
1940    if (strcmp(sys_cmd, "MkInterRedNextWeight") == 0)
1941    {
1942      const short t[]={3,INTVEC_CMD,INTVEC_CMD,IDEAL_CMD};
1943      if (!iiCheckTypes(h,t,1)) return TRUE;
1944      if (((intvec*) h->Data())->length() != currRing->N ||
1945        ((intvec*) h->next->Data())->length() != currRing->N)
1946      {
1947        Werror("system(\"MkInterRedNextWeight\" ...) intvecs not of length %d\n",
1948                 currRing->N);
1949        return TRUE;
1950      }
1951      intvec* arg1 = (intvec*) h->Data();
1952      intvec* arg2 = (intvec*) h->next->Data();
1953      ideal arg3   =   (ideal) h->next->next->Data();
1954      intvec* result = (intvec*) MkInterRedNextWeight(arg1, arg2, arg3);
1955      res->rtyp = INTVEC_CMD;
1956      res->data =  result;
1957      return FALSE;
1958    }
1959    else
1960  #endif
1961  /*==================== MPertNextWeight =================*/
1962  #ifdef HAVE_WALK
1963  #ifdef MPertNextWeight
1964    if (strcmp(sys_cmd, "MPertNextWeight") == 0)
1965    {
1966      const short t[]={3,INTVEC_CMD,IDEAL_CMD,INT_CMD};
1967      if (!iiCheckTypes(h,t,1)) return TRUE;
1968      if (((intvec*) h->Data())->length() != currRing->N)
1969      {
1970        Werror("system(\"MPertNextWeight\" ...) intvecs not of length %d\n",
1971                 currRing->N);
1972        return TRUE;
1973      }
1974      intvec* arg1 = (intvec*) h->Data();
1975      ideal arg2 = (ideal) h->next->Data();
1976      int arg3   =   (int) h->next->next->Data();
1977      intvec* result = (intvec*) MPertNextWeight(arg1, arg2, arg3);
1978      res->rtyp = INTVEC_CMD;
1979      res->data =  result;
1980      return FALSE;
1981    }
1982    else
1983  #endif //MPertNextWeight
1984  #endif
1985  /*==================== Mivperttarget =================*/
1986  #ifdef HAVE_WALK
1987  #ifdef Mivperttarget
1988    if (strcmp(sys_cmd, "Mivperttarget") == 0)
1989    {
1990      const short t[]={2,IDEAL_CMD,INT_CMD};
1991      if (!iiCheckTypes(h,t,1)) return TRUE;
1992      ideal arg1 = (ideal) h->Data();
1993      int arg2 = (int) h->next->Data();
1994      intvec* result = (intvec*) Mivperttarget(arg1, arg2);
1995      res->rtyp = INTVEC_CMD;
1996      res->data =  result;
1997      return FALSE;
1998    }
1999    else
2000  #endif //Mivperttarget
2001  #endif
2002  /*==================== Mwalk =================*/
2003  #ifdef HAVE_WALK
2004    if (strcmp(sys_cmd, "Mwalk") == 0)
2005    {
2006      const short t[]={6,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,RING_CMD,INT_CMD,INT_CMD};
2007      if (!iiCheckTypes(h,t,1)) return TRUE;
2008      if (((intvec*) h->next->Data())->length() != currRing->N &&
2009        ((intvec*) h->next->next->Data())->length() != currRing->N )
2010      {
2011        Werror("system(\"Mwalk\" ...) intvecs not of length %d\n",
2012           currRing->N);
2013        return TRUE;
2014      }
2015      ideal arg1 = (ideal) h->CopyD();
2016      intvec* arg2 = (intvec*) h->next->Data();
2017      intvec* arg3 = (intvec*) h->next->next->Data();
2018      ring arg4 = (ring) h->next->next->next->Data();
2019      int arg5 = (int) (long) h->next->next->next->next->Data();
2020      int arg6 = (int) (long) h->next->next->next->next->next->Data();
2021      ideal result = (ideal) Mwalk(arg1, arg2, arg3, arg4, arg5, arg6);
2022      res->rtyp = IDEAL_CMD;
2023      res->data =  result;
2024      return FALSE;
2025    }
2026    else
2027  #endif
2028  /*==================== Mpwalk =================*/
2029  #ifdef HAVE_WALK
2030  #ifdef MPWALK_ORIG
2031    if (strcmp(sys_cmd, "Mwalk") == 0)
2032    {
2033      const short t[]={4,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,RING_CMD};
2034      if (!iiCheckTypes(h,t,1)) return TRUE;
2035      if ((((intvec*) h->next->Data())->length() != currRing->N &&
2036          ((intvec*) h->next->next->Data())->length() != currRing->N ) &&
2037          (((intvec*) h->next->Data())->length() != (currRing->N)*(currRing->N) &&
2038          ((intvec*) h->next->next->Data())->length() != (currRing->N)*(currRing->N)))
2039      {
2040        Werror("system(\"Mwalk\" ...) intvecs not of length %d or %d\n",
2041               currRing->N,(currRing->N)*(currRing->N));
2042        return TRUE;
2043      }
2044      ideal arg1 = (ideal) h->Data();
2045      intvec* arg2 = (intvec*) h->next->Data();
2046      intvec* arg3   =  (intvec*) h->next->next->Data();
2047      ring arg4 = (ring) h->next->next->next->Data();
2048      ideal result = (ideal) Mwalk(arg1, arg2, arg3,arg4);
2049      res->rtyp = IDEAL_CMD;
2050      res->data =  result;
2051      return FALSE;
2052    }
2053    else
2054  #else
2055    if (strcmp(sys_cmd, "Mpwalk") == 0)
2056    {
2057      const short t[]={8,IDEAL_CMD,INT_CMD,INT_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD,INT_CMD};
2058      if (!iiCheckTypes(h,t,1)) return TRUE;
2059      if(((intvec*) h->next->next->next->Data())->length() != currRing->N &&
2060         ((intvec*) h->next->next->next->next->Data())->length()!=currRing->N)
2061      {
2062        Werror("system(\"Mpwalk\" ...) intvecs not of length %d\n",currRing->N);
2063        return TRUE;
2064      }
2065      ideal arg1 = (ideal) h->Data();
2066      int arg2 = (int) (long) h->next->Data();
2067      int arg3 = (int) (long) h->next->next->Data();
2068      intvec* arg4 = (intvec*) h->next->next->next->Data();
2069      intvec* arg5 = (intvec*) h->next->next->next->next->Data();
2070      int arg6 = (int) (long) h->next->next->next->next->next->Data();
2071      int arg7 = (int) (long) h->next->next->next->next->next->next->Data();
2072      int arg8 = (int) (long) h->next->next->next->next->next->next->next->Data();
2073      ideal result = (ideal) Mpwalk(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
2074      res->rtyp = IDEAL_CMD;
2075      res->data =  result;
2076      return FALSE;
2077    }
2078    else
2079    #endif
2080  #endif
2081  /*==================== Mrwalk =================*/
2082  #ifdef HAVE_WALK
2083    if (strcmp(sys_cmd, "Mrwalk") == 0)
2084    {
2085      const short t[]={7,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD,INT_CMD,INT_CMD};
2086      if (!iiCheckTypes(h,t,1)) return TRUE;
2087      if(((intvec*) h->next->Data())->length() != currRing->N &&
2088         ((intvec*) h->next->Data())->length() != (currRing->N)*(currRing->N) &&
2089         ((intvec*) h->next->next->Data())->length() != currRing->N &&
2090         ((intvec*) h->next->next->Data())->length() != (currRing->N)*(currRing->N) )
2091      {
2092        Werror("system(\"Mrwalk\" ...) intvecs not of length %d or %d\n",
2093               currRing->N,(currRing->N)*(currRing->N));
2094        return TRUE;
2095      }
2096      ideal arg1 = (ideal) h->Data();
2097      intvec* arg2 = (intvec*) h->next->Data();
2098      intvec* arg3 =  (intvec*) h->next->next->Data();
2099      int arg4 = (int)(long) h->next->next->next->Data();
2100      int arg5 = (int)(long) h->next->next->next->next->Data();
2101      int arg6 = (int)(long) h->next->next->next->next->next->Data();
2102      int arg7 = (int)(long) h->next->next->next->next->next->next->Data();
2103      ideal result = (ideal) Mrwalk(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
2104      res->rtyp = IDEAL_CMD;
2105      res->data =  result;
2106      return FALSE;
2107    }
2108    else
2109  #endif
2110  /*==================== MAltwalk1 =================*/
2111  #ifdef HAVE_WALK
2112    if (strcmp(sys_cmd, "MAltwalk1") == 0)
2113    {
2114      const short t[]={5,IDEAL_CMD,INT_CMD,INT_CMD,INTVEC_CMD,INTVEC_CMD};
2115      if (!iiCheckTypes(h,t,1)) return TRUE;
2116      if (((intvec*) h->next->next->next->Data())->length() != currRing->N &&
2117        ((intvec*) h->next->next->next->next->Data())->length()!=currRing->N)
2118      {
2119        Werror("system(\"MAltwalk1\" ...) intvecs not of length %d\n",
2120                 currRing->N);
2121        return TRUE;
2122      }
2123      ideal arg1 = (ideal) h->Data();
2124      int arg2 = (int) ((long)(h->next->Data()));
2125      int arg3 = (int) ((long)(h->next->next->Data()));
2126      intvec* arg4 = (intvec*) h->next->next->next->Data();
2127      intvec* arg5   =  (intvec*) h->next->next->next->next->Data();
2128      ideal result = (ideal) MAltwalk1(arg1, arg2, arg3, arg4, arg5);
2129      res->rtyp = IDEAL_CMD;
2130      res->data =  result;
2131      return FALSE;
2132    }
2133    else
2134  #endif
2135  /*==================== MAltwalk1 =================*/
2136  #ifdef HAVE_WALK
2137  #ifdef MFWALK_ALT
2138    if (strcmp(sys_cmd, "Mfwalk_alt") == 0)
2139    {
2140      const short t[]={4,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD};
2141      if (!iiCheckTypes(h,t,1)) return TRUE;
2142      if (((intvec*) h->next->Data())->length() != currRing->N &&
2143        ((intvec*) h->next->next->Data())->length() != currRing->N )
2144      {
2145        Werror("system(\"Mfwalk\" ...) intvecs not of length %d\n",
2146              currRing->N);
2147        return TRUE;
2148      }
2149      ideal arg1 = (ideal) h->Data();
2150      intvec* arg2 = (intvec*) h->next->Data();
2151      intvec* arg3   =  (intvec*) h->next->next->Data();
2152      int arg4 = (int) h->next->next->next->Data();
2153      ideal result = (ideal) Mfwalk_alt(arg1, arg2, arg3, arg4);
2154      res->rtyp = IDEAL_CMD;
2155      res->data =  result;
2156      return FALSE;
2157    }
2158    else
2159  #endif
2160  #endif
2161  /*==================== Mfwalk =================*/
2162  #ifdef HAVE_WALK
2163    if (strcmp(sys_cmd, "Mfwalk") == 0)
2164    {
2165      const short t[]={5,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD};
2166      if (!iiCheckTypes(h,t,1)) return TRUE;
2167      if (((intvec*) h->next->Data())->length() != currRing->N &&
2168        ((intvec*) h->next->next->Data())->length() != currRing->N )
2169      {
2170        Werror("system(\"Mfwalk\" ...) intvecs not of length %d\n",
2171                 currRing->N);
2172        return TRUE;
2173      }
2174      ideal arg1 = (ideal) h->Data();
2175      intvec* arg2 = (intvec*) h->next->Data();
2176      intvec* arg3 = (intvec*) h->next->next->Data();
2177      int arg4 = (int)(long) h->next->next->next->Data();
2178      int arg5 = (int)(long) h->next->next->next->next->Data();
2179      ideal result = (ideal) Mfwalk(arg1, arg2, arg3, arg4, arg5);
2180      res->rtyp = IDEAL_CMD;
2181      res->data =  result;
2182      return FALSE;
2183    }
2184    else
2185  #endif
2186  /*==================== Mfrwalk =================*/
2187  #ifdef HAVE_WALK
2188    if (strcmp(sys_cmd, "Mfrwalk") == 0)
2189    {
2190      const short t[]={6,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD,INT_CMD};
2191      if (!iiCheckTypes(h,t,1)) return TRUE;
2192/*
2193      if (((intvec*) h->next->Data())->length() != currRing->N &&
2194          ((intvec*) h->next->next->Data())->length() != currRing->N)
2195      {
2196        Werror("system(\"Mfrwalk\" ...) intvecs not of length %d\n",currRing->N);
2197        return TRUE;
2198      }
2199*/
2200      if((((intvec*) h->next->Data())->length() != currRing->N &&
2201         ((intvec*) h->next->next->Data())->length() != currRing->N ) &&
2202         (((intvec*) h->next->Data())->length() != (currRing->N)*(currRing->N) &&
2203         ((intvec*) h->next->next->Data())->length() != (currRing->N)*(currRing->N) ))
2204      {
2205        Werror("system(\"Mfrwalk\" ...) intvecs not of length %d or %d\n",
2206               currRing->N,(currRing->N)*(currRing->N));
2207        return TRUE;
2208      }
2209
2210      ideal arg1 = (ideal) h->Data();
2211      intvec* arg2 = (intvec*) h->next->Data();
2212      intvec* arg3 = (intvec*) h->next->next->Data();
2213      int arg4 = (int)(long) h->next->next->next->Data();
2214      int arg5 = (int)(long) h->next->next->next->next->Data();
2215      int arg6 = (int)(long) h->next->next->next->next->next->Data();
2216      ideal result = (ideal) Mfrwalk(arg1, arg2, arg3, arg4, arg5, arg6);
2217      res->rtyp = IDEAL_CMD;
2218      res->data =  result;
2219      return FALSE;
2220    }
2221    else
2222  /*==================== Mprwalk =================*/
2223    if (strcmp(sys_cmd, "Mprwalk") == 0)
2224    {
2225      const short t[]={9,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD,INT_CMD,INT_CMD,INT_CMD,INT_CMD};
2226      if (!iiCheckTypes(h,t,1)) return TRUE;
2227      if((((intvec*) h->next->Data())->length() != currRing->N &&
2228         ((intvec*) h->next->next->Data())->length() != currRing->N ) &&
2229         (((intvec*) h->next->Data())->length() != (currRing->N)*(currRing->N) &&
2230         ((intvec*) h->next->next->Data())->length() != (currRing->N)*(currRing->N) ))
2231      {
2232        Werror("system(\"Mrwalk\" ...) intvecs not of length %d or %d\n",
2233               currRing->N,(currRing->N)*(currRing->N));
2234        return TRUE;
2235      }
2236      ideal arg1 = (ideal) h->Data();
2237      intvec* arg2 = (intvec*) h->next->Data();
2238      intvec* arg3 =  (intvec*) h->next->next->Data();
2239      int arg4 = (int)(long) h->next->next->next->Data();
2240      int arg5 = (int)(long) h->next->next->next->next->Data();
2241      int arg6 = (int)(long) h->next->next->next->next->next->Data();
2242      int arg7 = (int)(long) h->next->next->next->next->next->next->Data();
2243      int arg8 = (int)(long) h->next->next->next->next->next->next->next->Data();
2244      int arg9 = (int)(long) h->next->next->next->next->next->next->next->next->Data();
2245      ideal result = (ideal) Mprwalk(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
2246      res->rtyp = IDEAL_CMD;
2247      res->data =  result;
2248      return FALSE;
2249    }
2250    else
2251  #endif
2252  /*==================== TranMImprovwalk =================*/
2253  #ifdef HAVE_WALK
2254  #ifdef TRAN_Orig
2255    if (strcmp(sys_cmd, "TranMImprovwalk") == 0)
2256    {
2257      const short t[]={3,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD};
2258      if (!iiCheckTypes(h,t,1)) return TRUE;
2259      if (((intvec*) h->next->Data())->length() != currRing->N &&
2260        ((intvec*) h->next->next->Data())->length() != currRing->N )
2261      {
2262        Werror("system(\"TranMImprovwalk\" ...) intvecs not of length %d\n",
2263              currRing->N);
2264        return TRUE;
2265      }
2266      ideal arg1 = (ideal) h->Data();
2267      intvec* arg2 = (intvec*) h->next->Data();
2268      intvec* arg3   =  (intvec*) h->next->next->Data();
2269      ideal result = (ideal) TranMImprovwalk(arg1, arg2, arg3);
2270      res->rtyp = IDEAL_CMD;
2271      res->data =  result;
2272      return FALSE;
2273    }
2274    else
2275  #endif
2276  #endif
2277  /*==================== MAltwalk2 =================*/
2278  #ifdef HAVE_WALK
2279    if (strcmp(sys_cmd, "MAltwalk2") == 0)
2280    {
2281      const short t[]={3,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD};
2282      if (!iiCheckTypes(h,t,1)) return TRUE;
2283      if (((intvec*) h->next->Data())->length() != currRing->N &&
2284        ((intvec*) h->next->next->Data())->length() != currRing->N )
2285      {
2286        Werror("system(\"MAltwalk2\" ...) intvecs not of length %d\n",
2287                 currRing->N);
2288        return TRUE;
2289      }
2290      ideal arg1 = (ideal) h->Data();
2291      intvec* arg2 = (intvec*) h->next->Data();
2292      intvec* arg3   =  (intvec*) h->next->next->Data();
2293      ideal result = (ideal) MAltwalk2(arg1, arg2, arg3);
2294      res->rtyp = IDEAL_CMD;
2295      res->data =  result;
2296      return FALSE;
2297    }
2298    else
2299  #endif
2300  /*==================== MAltwalk2 =================*/
2301  #ifdef HAVE_WALK
2302    if (strcmp(sys_cmd, "TranMImprovwalk") == 0)
2303    {
2304      const short t[]={4,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD};
2305      if (!iiCheckTypes(h,t,1)) return TRUE;
2306      if (((intvec*) h->next->Data())->length() != currRing->N &&
2307        ((intvec*) h->next->next->Data())->length() != currRing->N )
2308      {
2309        Werror("system(\"TranMImprovwalk\" ...) intvecs not of length %d\n",
2310                 currRing->N);
2311        return TRUE;
2312      }
2313      ideal arg1 = (ideal) h->Data();
2314      intvec* arg2 = (intvec*) h->next->Data();
2315      intvec* arg3   =  (intvec*) h->next->next->Data();
2316      int arg4   =  (int) ((long)(h->next->next->next->Data()));
2317      ideal result = (ideal) TranMImprovwalk(arg1, arg2, arg3, arg4);
2318      res->rtyp = IDEAL_CMD;
2319      res->data =  result;
2320      return FALSE;
2321    }
2322    else
2323  #endif
2324  /*==================== TranMrImprovwalk =================*/
2325  #if 0
2326  #ifdef HAVE_WALK
2327    if (strcmp(sys_cmd, "TranMrImprovwalk") == 0)
2328    {
2329      if (h == NULL || h->Typ() != IDEAL_CMD ||
2330        h->next == NULL || h->next->Typ() != INTVEC_CMD ||
2331        h->next->next == NULL || h->next->next->Typ() != INTVEC_CMD ||
2332        h->next->next->next == NULL || h->next->next->next->Typ() != INT_CMD ||
2333        h->next->next->next == NULL || h->next->next->next->next->Typ() != INT_CMD ||
2334        h->next->next->next == NULL || h->next->next->next->next->next->Typ() != INT_CMD)
2335      {
2336        WerrorS("system(\"TranMrImprovwalk\", ideal, intvec, intvec) expected");
2337        return TRUE;
2338      }
2339      if (((intvec*) h->next->Data())->length() != currRing->N &&
2340        ((intvec*) h->next->next->Data())->length() != currRing->N )
2341      {
2342        Werror("system(\"TranMrImprovwalk\" ...) intvecs not of length %d\n", currRing->N);
2343        return TRUE;
2344      }
2345      ideal arg1 = (ideal) h->Data();
2346      intvec* arg2 = (intvec*) h->next->Data();
2347      intvec* arg3 = (intvec*) h->next->next->Data();
2348      int arg4 = (int)(long) h->next->next->next->Data();
2349      int arg5 = (int)(long) h->next->next->next->next->Data();
2350      int arg6 = (int)(long) h->next->next->next->next->next->Data();
2351      ideal result = (ideal) TranMrImprovwalk(arg1, arg2, arg3, arg4, arg5, arg6);
2352      res->rtyp = IDEAL_CMD;
2353      res->data =  result;
2354      return FALSE;
2355    }
2356    else
2357  #endif
2358  #endif
2359  /*================= Extended system call ========================*/
2360    {
2361       #ifndef MAKE_DISTRIBUTION
2362       return(jjEXTENDED_SYSTEM(res, args));
2363       #else
2364       Werror( "system(\"%s\",...) %s", sys_cmd, feNotImplemented );
2365       #endif
2366    }
2367  } /* typ==string */
2368  return TRUE;
2369}
2370
2371
2372#ifdef HAVE_EXTENDED_SYSTEM
2373  // You can put your own system calls here
2374#  include "kernel/fglm/fglm.h"
2375#  ifdef HAVE_NEWTON
2376#    include "hc_newton.h"
2377#  endif
2378
2379static BOOLEAN jjEXTENDED_SYSTEM(leftv res, leftv h)
2380{
2381    if(h->Typ() == STRING_CMD)
2382    {
2383      char *sys_cmd=(char *)(h->Data());
2384      h=h->next;
2385  /*==================== test syz strat =================*/
2386      if (strcmp(sys_cmd, "syz") == 0)
2387      {
2388         if ((h!=NULL) && (h->Typ()==STRING_CMD))
2389         {
2390           const char *s=(const char *)h->Data();
2391           if (strcmp(s,"posInT_EcartFDegpLength")==0)
2392             test_PosInT=posInT_EcartFDegpLength;
2393           else if (strcmp(s,"posInT_FDegpLength")==0)
2394             test_PosInT=posInT_FDegpLength;
2395           else if (strcmp(s,"posInT_pLength")==0)
2396             test_PosInT=posInT_pLength;
2397           else if (strcmp(s,"posInT0")==0)
2398             test_PosInT=posInT0;
2399           else if (strcmp(s,"posInT1")==0)
2400             test_PosInT=posInT1;
2401           else if (strcmp(s,"posInT2")==0)
2402             test_PosInT=posInT2;
2403           else if (strcmp(s,"posInT11")==0)
2404             test_PosInT=posInT11;
2405           else if (strcmp(s,"posInT110")==0)
2406             test_PosInT=posInT110;
2407           else if (strcmp(s,"posInT13")==0)
2408             test_PosInT=posInT13;
2409           else if (strcmp(s,"posInT15")==0)
2410             test_PosInT=posInT15;
2411           else if (strcmp(s,"posInT17")==0)
2412             test_PosInT=posInT17;
2413           else if (strcmp(s,"posInT17_c")==0)
2414             test_PosInT=posInT17_c;
2415           else if (strcmp(s,"posInT19")==0)
2416             test_PosInT=posInT19;
2417           else PrintS("valid posInT:0,1,2,11,110,13,15,17,17_c,19,_EcartFDegpLength,_FDegpLength,_pLength,_EcartpLength\n");
2418         }
2419         else
2420         {
2421           test_PosInT=NULL;
2422           test_PosInL=NULL;
2423         }
2424         si_opt_2|=Sy_bit(23);
2425         return FALSE;
2426      }
2427      else
2428  /*==================== locNF ======================================*/
2429      if(strcmp(sys_cmd,"locNF")==0)
2430      {
2431        const short t[]={4,VECTOR_CMD,MODUL_CMD,INT_CMD,INTVEC_CMD};
2432        if (iiCheckTypes(h,t,1))
2433        {
2434          poly f=(poly)h->Data();
2435          h=h->next;
2436          ideal m=(ideal)h->Data();
2437          assumeStdFlag(h);
2438          h=h->next;
2439          int n=(int)((long)h->Data());
2440          h=h->next;
2441          intvec *v=(intvec *)h->Data();
2442
2443          /* == now the work starts == */
2444
2445          int * iv=iv2array(v, currRing);
2446          poly r=0;
2447          poly hp=ppJetW(f,n,iv);
2448          int s=MATCOLS(m);
2449          int j=0;
2450          matrix T=mp_InitI(s,1,0, currRing);
2451
2452          while (hp != NULL)
2453          {
2454            if (pDivisibleBy(m->m[j],hp))
2455            {
2456              if (MATELEM(T,j+1,1)==0)
2457              {
2458                MATELEM(T,j+1,1)=pDivideM(pHead(hp),pHead(m->m[j]));
2459              }
2460              else
2461              {
2462                pAdd(MATELEM(T,j+1,1),pDivideM(pHead(hp),pHead(m->m[j])));
2463              }
2464              hp=ppJetW(ksOldSpolyRed(m->m[j],hp,0),n,iv);
2465              j=0;
2466            }
2467            else
2468            {
2469              if (j==s-1)
2470              {
2471                r=pAdd(r,pHead(hp));
2472                hp=pLmDeleteAndNext(hp); /* hp=pSub(hp,pHead(hp));*/
2473                j=0;
2474              }
2475              else
2476              {
2477                j++;
2478              }
2479            }
2480          }
2481
2482          matrix Temp=mp_Transp((matrix) id_Vec2Ideal(r, currRing), currRing);
2483          matrix R=mpNew(MATCOLS((matrix) id_Vec2Ideal(f, currRing)),1);
2484          for (int k=1;k<=MATROWS(Temp);k++)
2485          {
2486            MATELEM(R,k,1)=MATELEM(Temp,k,1);
2487          }
2488
2489          lists L=(lists)omAllocBin(slists_bin);
2490          L->Init(2);
2491          L->m[0].rtyp=MATRIX_CMD;   L->m[0].data=(void *)R;
2492          L->m[1].rtyp=MATRIX_CMD;   L->m[1].data=(void *)T;
2493          res->data=L;
2494          res->rtyp=LIST_CMD;
2495          // iv aufraeumen
2496          omFree(iv);
2497          return FALSE;
2498        }
2499        else
2500          return TRUE;
2501      }
2502      else
2503  /*==================== poly debug ==================================*/
2504        if(strcmp(sys_cmd,"p")==0)
2505        {
2506#  ifdef RDEBUG
2507          p_DebugPrint((poly)h->Data(), currRing);
2508#  else
2509          WarnS("Sorry: not available for release build!");
2510#  endif
2511          return FALSE;
2512        }
2513        else
2514  /*==================== setsyzcomp ==================================*/
2515      if(strcmp(sys_cmd,"setsyzcomp")==0)
2516      {
2517        if ((h!=NULL) && (h->Typ()==INT_CMD))
2518        {
2519          int k = (int)(long)h->Data();
2520          if ( currRing->order[0] == ringorder_s )
2521          {
2522            rSetSyzComp(k, currRing);
2523          }
2524        }
2525      }
2526  /*==================== ring debug ==================================*/
2527        if(strcmp(sys_cmd,"r")==0)
2528        {
2529#  ifdef RDEBUG
2530          rDebugPrint((ring)h->Data());
2531#  else
2532          WarnS("Sorry: not available for release build!");
2533#  endif
2534          return FALSE;
2535        }
2536        else
2537  /*==================== changeRing ========================*/
2538        /* The following code changes the names of the variables in the
2539           current ring to "x1", "x2", ..., "xN", where N is the number
2540           of variables in the current ring.
2541           The purpose of this rewriting is to eliminate indexed variables,
2542           as they may cause problems when generating scripts for Magma,
2543           Maple, or Macaulay2. */
2544        if(strcmp(sys_cmd,"changeRing")==0)
2545        {
2546          int varN = currRing->N;
2547          char h[10];
2548          for (int i = 1; i <= varN; i++)
2549          {
2550            omFree(currRing->names[i - 1]);
2551            sprintf(h, "x%d", i);
2552            currRing->names[i - 1] = omStrDup(h);
2553          }
2554          rComplete(currRing);
2555          res->rtyp = INT_CMD;
2556          res->data = (void*)0L;
2557          return FALSE;
2558        }
2559        else
2560  /*==================== mtrack ==================================*/
2561      if(strcmp(sys_cmd,"mtrack")==0)
2562      {
2563  #ifdef OM_TRACK
2564        om_Opts.MarkAsStatic = 1;
2565        FILE *fd = NULL;
2566        int max = 5;
2567        while (h != NULL)
2568        {
2569          omMarkAsStaticAddr(h);
2570          if (fd == NULL && h->Typ()==STRING_CMD)
2571          {
2572            char *fn=(char*) h->Data();
2573            fd = fopen(fn, "w");
2574            if (fd == NULL)
2575              Warn("Can not open %s for writing og mtrack. Using stdout",fn);
2576          }
2577          else if (h->Typ() == INT_CMD)
2578          {
2579            max = (int)(long)h->Data();
2580          }
2581          h = h->Next();
2582        }
2583        omPrintUsedTrackAddrs((fd == NULL ? stdout : fd), max);
2584        if (fd != NULL) fclose(fd);
2585        om_Opts.MarkAsStatic = 0;
2586        return FALSE;
2587  #else
2588        WerrorS("system(\"mtrack\",..) is not implemented in this version");
2589        return TRUE;
2590  #endif
2591      }
2592      else
2593  /*==================== backtrace ==================================*/
2594  #ifndef OM_NDEBUG
2595      if(strcmp(sys_cmd,"backtrace")==0)
2596      {
2597        omPrintCurrentBackTrace(stdout);
2598        return FALSE;
2599      }
2600      else
2601  #endif
2602
2603#if !defined(OM_NDEBUG)
2604  /*==================== omMemoryTest ==================================*/
2605      if (strcmp(sys_cmd,"omMemoryTest")==0)
2606      {
2607
2608#ifdef OM_STATS_H
2609        PrintS("\n[om_Info]: \n");
2610        omUpdateInfo();
2611#define OM_PRINT(name) Print(" %-22s : %10ld \n", #name, om_Info . name)
2612        OM_PRINT(MaxBytesSystem);
2613        OM_PRINT(CurrentBytesSystem);
2614        OM_PRINT(MaxBytesSbrk);
2615        OM_PRINT(CurrentBytesSbrk);
2616        OM_PRINT(MaxBytesMmap);
2617        OM_PRINT(CurrentBytesMmap);
2618        OM_PRINT(UsedBytes);
2619        OM_PRINT(AvailBytes);
2620        OM_PRINT(UsedBytesMalloc);
2621        OM_PRINT(AvailBytesMalloc);
2622        OM_PRINT(MaxBytesFromMalloc);
2623        OM_PRINT(CurrentBytesFromMalloc);
2624        OM_PRINT(MaxBytesFromValloc);
2625        OM_PRINT(CurrentBytesFromValloc);
2626        OM_PRINT(UsedBytesFromValloc);
2627        OM_PRINT(AvailBytesFromValloc);
2628        OM_PRINT(MaxPages);
2629        OM_PRINT(UsedPages);
2630        OM_PRINT(AvailPages);
2631        OM_PRINT(MaxRegionsAlloc);
2632        OM_PRINT(CurrentRegionsAlloc);
2633#undef OM_PRINT
2634#endif
2635
2636#ifdef OM_OPTS_H
2637        PrintS("\n[om_Opts]: \n");
2638#define OM_PRINT(format, name) Print(" %-22s : %10" format"\n", #name, om_Opts . name)
2639        OM_PRINT("d", MinTrack);
2640        OM_PRINT("d", MinCheck);
2641        OM_PRINT("d", MaxTrack);
2642        OM_PRINT("d", MaxCheck);
2643        OM_PRINT("d", Keep);
2644        OM_PRINT("d", HowToReportErrors);
2645        OM_PRINT("d", MarkAsStatic);
2646        OM_PRINT("u", PagesPerRegion);
2647        OM_PRINT("p", OutOfMemoryFunc);
2648        OM_PRINT("p", MemoryLowFunc);
2649        OM_PRINT("p", ErrorHook);
2650#undef OM_PRINT
2651#endif
2652
2653#ifdef OM_ERROR_H
2654        Print("\n\n[om_ErrorStatus]        : '%s' (%s)\n",
2655                omError2String(om_ErrorStatus),
2656                omError2Serror(om_ErrorStatus));
2657        Print("[om_InternalErrorStatus]: '%s' (%s)\n",
2658                omError2String(om_InternalErrorStatus),
2659                omError2Serror(om_InternalErrorStatus));
2660
2661#endif
2662
2663//        omTestMemory(1);
2664//        omtTestErrors();
2665        return FALSE;
2666      }
2667      else
2668#endif
2669  /*==================== pDivStat =============================*/
2670  #if defined(PDEBUG) || defined(PDIV_DEBUG)
2671      if(strcmp(sys_cmd,"pDivStat")==0)
2672      {
2673        extern void pPrintDivisbleByStat();
2674        pPrintDivisbleByStat();
2675        return FALSE;
2676      }
2677      else
2678  #endif
2679  /*==================== red =============================*/
2680  #if 0
2681      if(strcmp(sys_cmd,"red")==0)
2682      {
2683        if ((h!=NULL) &&(h->Typ()==IDEAL_CMD))
2684        {
2685          res->rtyp=IDEAL_CMD;
2686          res->data=(void *)kStdred((ideal)h->Data(),NULL,testHomog,NULL);
2687          setFlag(res,FLAG_STD);
2688          return FALSE;
2689        }
2690        else
2691          WerrorS("ideal expected");
2692      }
2693      else
2694  #endif
2695  /*==================== fastcomb =============================*/
2696      if(strcmp(sys_cmd,"fastcomb")==0)
2697      {
2698        if ((h!=NULL) &&(h->Typ()==IDEAL_CMD))
2699        {
2700          if (h->next!=NULL)
2701          {
2702            if (h->next->Typ()!=POLY_CMD)
2703            {
2704              WarnS("Wrong types for poly= comb(ideal,poly)");
2705            }
2706          }
2707          res->rtyp=POLY_CMD;
2708          res->data=(void *) fglmLinearCombination(
2709                             (ideal)h->Data(),(poly)h->next->Data());
2710          return FALSE;
2711        }
2712        else
2713          WerrorS("ideal expected");
2714      }
2715      else
2716  /*==================== comb =============================*/
2717      if(strcmp(sys_cmd,"comb")==0)
2718      {
2719        if ((h!=NULL) &&(h->Typ()==IDEAL_CMD))
2720        {
2721          if (h->next!=NULL)
2722          {
2723            if (h->next->Typ()!=POLY_CMD)
2724            {
2725                WarnS("Wrong types for poly= comb(ideal,poly)");
2726            }
2727          }
2728          res->rtyp=POLY_CMD;
2729          res->data=(void *)fglmNewLinearCombination(
2730                              (ideal)h->Data(),(poly)h->next->Data());
2731          return FALSE;
2732        }
2733        else
2734          WerrorS("ideal expected");
2735      }
2736      else
2737  #if 0 /* debug only */
2738  /*==================== listall ===================================*/
2739      if(strcmp(sys_cmd,"listall")==0)
2740      {
2741        void listall(int showproc);
2742        int showproc=0;
2743        if ((h!=NULL) && (h->Typ()==INT_CMD)) showproc=(int)((long)h->Data());
2744        listall(showproc);
2745        return FALSE;
2746      }
2747      else
2748  #endif
2749  #if 0 /* debug only */
2750  /*==================== proclist =================================*/
2751      if(strcmp(sys_cmd,"proclist")==0)
2752      {
2753        void piShowProcList();
2754        piShowProcList();
2755        return FALSE;
2756      }
2757      else
2758  #endif
2759  /* ==================== newton ================================*/
2760  #ifdef HAVE_NEWTON
2761      if(strcmp(sys_cmd,"newton")==0)
2762      {
2763        if ((h->Typ()!=POLY_CMD)
2764        || (h->next->Typ()!=INT_CMD)
2765        || (h->next->next->Typ()!=INT_CMD))
2766        {
2767          WerrorS("system(\"newton\",<poly>,<int>,<int>) expected");
2768          return TRUE;
2769        }
2770        poly  p=(poly)(h->Data());
2771        int l=pLength(p);
2772        short *points=(short *)omAlloc(currRing->N*l*sizeof(short));
2773        int i,j,k;
2774        k=0;
2775        poly pp=p;
2776        for (i=0;pp!=NULL;i++)
2777        {
2778          for(j=1;j<=currRing->N;j++)
2779          {
2780            points[k]=pGetExp(pp,j);
2781            k++;
2782          }
2783          pIter(pp);
2784        }
2785        hc_ERG r=hc_KOENIG(currRing->N,      // dimension
2786                  l,      // number of points
2787                  (short*) points,   // points: x_1, y_1,z_1, x_2,y_2,z2,...
2788                  currRing->OrdSgn==-1,
2789                  (int) (h->next->Data()),      // 1: Milnor, 0: Newton
2790                  (int) (h->next->next->Data()) // debug
2791                 );
2792        //----<>---Output-----------------------
2793
2794
2795  //  PrintS("Bin jetzt in extra.cc bei der Auswertung.\n"); // **********
2796
2797
2798        lists L=(lists)omAllocBin(slists_bin);
2799        L->Init(6);
2800        L->m[0].rtyp=STRING_CMD;               // newtonnumber;
2801        L->m[0].data=(void *)omStrDup(r.nZahl);
2802        L->m[1].rtyp=INT_CMD;
2803        L->m[1].data=(void *)(long)r.achse;          // flag for unoccupied axes
2804        L->m[2].rtyp=INT_CMD;
2805        L->m[2].data=(void *)(long)r.deg;            // #degenerations
2806        if ( r.deg != 0)              // only if degenerations exist
2807        {
2808          L->m[3].rtyp=INT_CMD;
2809          L->m[3].data=(void *)(long)r.anz_punkte;     // #points
2810          //---<>--number of points------
2811          int anz = r.anz_punkte;    // number of points
2812          int dim = (currRing->N);     // dimension
2813          intvec* v = new intvec( anz*dim );
2814          for (i=0; i<anz*dim; i++)    // copy points
2815            (*v)[i] = r.pu[i];
2816          L->m[4].rtyp=INTVEC_CMD;
2817          L->m[4].data=(void *)v;
2818          //---<>--degenerations---------
2819          int deg = r.deg;    // number of points
2820          intvec* w = new intvec( r.speicher );  // necessary memory
2821          i=0;               // start copying
2822          do
2823          {
2824            (*w)[i] = r.deg_tab[i];
2825            i++;
2826          }
2827          while (r.deg_tab[i-1] != -2);   // mark for end of list
2828          L->m[5].rtyp=INTVEC_CMD;
2829          L->m[5].data=(void *)w;
2830        }
2831        else
2832        {
2833          L->m[3].rtyp=INT_CMD; L->m[3].data=(char *)0;
2834          L->m[4].rtyp=DEF_CMD;
2835          L->m[5].rtyp=DEF_CMD;
2836        }
2837
2838        res->data=(void *)L;
2839        res->rtyp=LIST_CMD;
2840        // free all pointer in r:
2841        delete[] r.nZahl;
2842        delete[] r.pu;
2843        delete[] r.deg_tab;      // Ist das ein Problem??
2844
2845        omFreeSize((ADDRESS)points,currRing->N*l*sizeof(short));
2846        return FALSE;
2847      }
2848      else
2849  #endif
2850  /*==== connection to Sebastian Jambor's code ======*/
2851  /* This code connects Sebastian Jambor's code for
2852     computing the minimal polynomial of an (n x n) matrix
2853     with entries in F_p to SINGULAR. Two conversion methods
2854     are needed; see further up in this file:
2855        (1) conversion of a matrix with long entries to
2856            a SINGULAR matrix with number entries, where
2857            the numbers are coefficients in currRing;
2858        (2) conversion of an array of longs (encoding the
2859            coefficients of the minimal polynomial) to a
2860            SINGULAR poly living in currRing. */
2861      if (strcmp(sys_cmd, "minpoly") == 0)
2862      {
2863        if ((h == NULL) || (h->Typ() != MATRIX_CMD) || h->next != NULL)
2864        {
2865          Werror("expected exactly one argument: %s",
2866                 "a square matrix with number entries");
2867          return TRUE;
2868        }
2869        else
2870        {
2871          matrix m = (matrix)h->Data();
2872          int n = m->rows();
2873          unsigned long p = (unsigned long)n_GetChar(currRing->cf);
2874          if (n != m->cols())
2875          {
2876            WerrorS("expected exactly one argument: "
2877                   "a square matrix with number entries");
2878            return TRUE;
2879          }
2880          unsigned long** ml = singularMatrixToLongMatrix(m);
2881          unsigned long* polyCoeffs = computeMinimalPolynomial(ml, n, p);
2882          poly theMinPoly = longCoeffsToSingularPoly(polyCoeffs, n);
2883          res->rtyp = POLY_CMD;
2884          res->data = (void *)theMinPoly;
2885          for (int i = 0; i < n; i++) delete[] ml[i];
2886          delete[] ml;
2887          delete[] polyCoeffs;
2888          return FALSE;
2889        }
2890      }
2891      else
2892  /*==================== sdb_flags =================*/
2893  #ifdef HAVE_SDB
2894      if (strcmp(sys_cmd, "sdb_flags") == 0)
2895      {
2896        if ((h!=NULL) && (h->Typ()==INT_CMD))
2897        {
2898          sdb_flags=(int)((long)h->Data());
2899        }
2900        else
2901        {
2902          WerrorS("system(\"sdb_flags\",`int`) expected");
2903          return TRUE;
2904        }
2905        return FALSE;
2906      }
2907      else
2908  #endif
2909  /*==================== sdb_edit =================*/
2910  #ifdef HAVE_SDB
2911      if (strcmp(sys_cmd, "sdb_edit") == 0)
2912      {
2913        if (FE_OPT_NO_SHELL_FLAG)
2914        {
2915          WerrorS("shell execution is disallowed in restricted mode");
2916          return TRUE;
2917        }
2918        if ((h!=NULL) && (h->Typ()==PROC_CMD))
2919        {
2920          procinfov p=(procinfov)h->Data();
2921          sdb_edit(p);
2922        }
2923        else
2924        {
2925          WerrorS("system(\"sdb_edit\",`proc`) expected");
2926          return TRUE;
2927        }
2928        return FALSE;
2929      }
2930      else
2931  #endif
2932  /*==================== GF =================*/
2933  #if 0 // for testing only
2934      if (strcmp(sys_cmd, "GF") == 0)
2935      {
2936        if ((h!=NULL) && (h->Typ()==POLY_CMD))
2937        {
2938          int c=rChar(currRing);
2939          setCharacteristic( c,nfMinPoly[0], currRing->parameter[0][0] );
2940          CanonicalForm F( convSingGFFactoryGF( (poly)h->Data(), currRing ) );
2941          res->rtyp=POLY_CMD;
2942          res->data=convFactoryGFSingGF( F, currRing );
2943          return FALSE;
2944        }
2945        else { WerrorS("wrong typ"); return TRUE;}
2946      }
2947      else
2948  #endif
2949  /*==================== SVD =================*/
2950  #ifdef HAVE_SVD
2951       if (strcmp(sys_cmd, "svd") == 0)
2952       {
2953            extern lists testsvd(matrix M);
2954              res->rtyp=LIST_CMD;
2955            res->data=(char*)(testsvd((matrix)h->Data()));
2956            return FALSE;
2957       }
2958       else
2959  #endif
2960  /*==================== redNF_ring =================*/
2961  #ifdef HAVE_RINGS
2962      if (strcmp(sys_cmd, "redNF_ring")==0)
2963      {
2964        ring r = currRing;
2965        poly f = (poly) h->Data();
2966        h = h->next;
2967        ideal G = (ideal) h->Data();
2968        res->rtyp=POLY_CMD;
2969        res->data=(poly) ringRedNF(f, G, r);
2970        return(FALSE);
2971      }
2972      else
2973  #endif
2974  /*==================== Roune Hilb  =================*/
2975       if (strcmp(sys_cmd, "hilbroune") == 0)
2976       {
2977         if ((h!=NULL) && (h->Typ()==IDEAL_CMD))
2978         {
2979           slicehilb((ideal)h->Data());
2980         }
2981         else return TRUE;
2982         return FALSE;
2983       }
2984      else
2985  /*==================== F5 Implementation =================*/
2986  #ifdef HAVE_F5
2987      if (strcmp(sys_cmd, "f5")==0)
2988      {
2989        if (h->Typ()!=IDEAL_CMD)
2990        {
2991          WerrorS("ideal expected");
2992          return TRUE;
2993        }
2994
2995        ring r = currRing;
2996        ideal G = (ideal) h->Data();
2997        h = h->next;
2998        int opt;
2999        if(h != NULL) {
3000          opt = (int) (long) h->Data();
3001        }
3002        else {
3003          opt = 2;
3004        }
3005        h = h->next;
3006        int plus;
3007        if(h != NULL) {
3008          plus = (int) (long) h->Data();
3009        }
3010        else {
3011          plus = 0;
3012        }
3013        h = h->next;
3014        int termination;
3015        if(h != NULL) {
3016          termination = (int) (long) h->Data();
3017        }
3018        else {
3019          termination = 0;
3020        }
3021        res->rtyp=IDEAL_CMD;
3022        res->data=(ideal) F5main(G,r,opt,plus,termination);
3023        return FALSE;
3024      }
3025      else
3026  #endif
3027  /*==================== Testing groebner basis =================*/
3028  #ifdef HAVE_RINGS
3029      if (strcmp(sys_cmd, "NF_ring")==0)
3030      {
3031        ring r = currRing;
3032        poly f = (poly) h->Data();
3033        h = h->next;
3034        ideal G = (ideal) h->Data();
3035        res->rtyp=POLY_CMD;
3036        res->data=(poly) ringNF(f, G, r);
3037        return(FALSE);
3038      }
3039      else
3040      if (strcmp(sys_cmd, "spoly")==0)
3041      {
3042        poly f = pCopy((poly) h->Data());
3043        h = h->next;
3044        poly g = pCopy((poly) h->Data());
3045
3046        res->rtyp=POLY_CMD;
3047        res->data=(poly) plain_spoly(f,g);
3048        return(FALSE);
3049      }
3050      else
3051      if (strcmp(sys_cmd, "testGB")==0)
3052      {
3053        ideal I = (ideal) h->Data();
3054        h = h->next;
3055        ideal GI = (ideal) h->Data();
3056        res->rtyp = INT_CMD;
3057        res->data = (void *)(long) testGB(I, GI);
3058        return(FALSE);
3059      }
3060      else
3061  #endif
3062    /*==================== sca:AltVar ==================================*/
3063  #ifdef HAVE_PLURAL
3064      if ( (strcmp(sys_cmd, "AltVarStart") == 0) || (strcmp(sys_cmd, "AltVarEnd") == 0) )
3065      {
3066        ring r = currRing;
3067
3068        if((h!=NULL) && (h->Typ()==RING_CMD)) r = (ring)h->Data(); else
3069        {
3070          WerrorS("`system(\"AltVarStart/End\"[,<ring>])` expected");
3071          return TRUE;
3072        }
3073
3074        res->rtyp=INT_CMD;
3075
3076        if (rIsSCA(r))
3077        {
3078          if(strcmp(sys_cmd, "AltVarStart") == 0)
3079            res->data = (void*)(long)scaFirstAltVar(r);
3080          else
3081            res->data = (void*)(long)scaLastAltVar(r);
3082          return FALSE;
3083        }
3084
3085        WerrorS("`system(\"AltVarStart/End\",<ring>) requires a SCA ring");
3086        return TRUE;
3087      }
3088      else
3089  #endif
3090  /*==================== RatNF, noncomm rational coeffs =================*/
3091  #ifdef HAVE_RATGRING
3092      if (strcmp(sys_cmd, "intratNF") == 0)
3093      {
3094        poly p;
3095        poly *q;
3096        ideal I;
3097        int is, k, id;
3098        if ((h!=NULL) && (h->Typ()==POLY_CMD))
3099        {
3100          p=(poly)h->CopyD();
3101          h=h->next;
3102          //        PrintS("poly is done\n");
3103        }
3104        else return TRUE;
3105        if ((h!=NULL) && (h->Typ()==IDEAL_CMD))
3106        {
3107          I=(ideal)h->CopyD();
3108          q = I->m;
3109          h=h->next;
3110          //        PrintS("ideal is done\n");
3111        }
3112        else return TRUE;
3113        if ((h!=NULL) && (h->Typ()==INT_CMD))
3114        {
3115          is=(int)((long)(h->Data()));
3116          //        res->rtyp=INT_CMD;
3117          //        PrintS("int is done\n");
3118          //        res->rtyp=IDEAL_CMD;
3119          if (rIsPluralRing(currRing))
3120          {
3121            id = IDELEMS(I);
3122                   int *pl=(int*)omAlloc0(IDELEMS(I)*sizeof(int));
3123            for(k=0; k < id; k++)
3124            {
3125              pl[k] = pLength(I->m[k]);
3126            }
3127            PrintS("starting redRat\n");
3128            //res->data = (char *)
3129            redRat(&p, q, pl, (int)IDELEMS(I),is,currRing);
3130            res->data=p;
3131            res->rtyp=POLY_CMD;
3132            //        res->data = ncGCD(p,q,currRing);
3133          }
3134          else
3135          {
3136            res->rtyp=POLY_CMD;
3137            res->data=p;
3138          }
3139        }
3140        else return TRUE;
3141        return FALSE;
3142      }
3143      else
3144  /*==================== RatNF, noncomm rational coeffs =================*/
3145      if (strcmp(sys_cmd, "ratNF") == 0)
3146      {
3147        poly p,q;
3148        int is, htype;
3149        if ((h!=NULL) && ( (h->Typ()==POLY_CMD) || (h->Typ()==VECTOR_CMD) ) )
3150        {
3151          p=(poly)h->CopyD();
3152          h=h->next;
3153          htype = h->Typ();
3154        }
3155        else return TRUE;
3156        if ((h!=NULL) && ( (h->Typ()==POLY_CMD) || (h->Typ()==VECTOR_CMD) ) )
3157        {
3158          q=(poly)h->CopyD();
3159          h=h->next;
3160        }
3161        else return TRUE;
3162        if ((h!=NULL) && (h->Typ()==INT_CMD))
3163        {
3164          is=(int)((long)(h->Data()));
3165          res->rtyp=htype;
3166          //        res->rtyp=IDEAL_CMD;
3167          if (rIsPluralRing(currRing))
3168          {
3169            res->data = nc_rat_ReduceSpolyNew(q,p,is, currRing);
3170            //        res->data = ncGCD(p,q,currRing);
3171          }
3172          else res->data=p;
3173        }
3174        else return TRUE;
3175        return FALSE;
3176      }
3177      else
3178        /*==================== RatSpoly, noncomm rational coeffs =================*/
3179      if (strcmp(sys_cmd, "ratSpoly") == 0)
3180      {
3181        poly p,q;
3182        int is;
3183        if ((h!=NULL) && (h->Typ()==POLY_CMD))
3184        {
3185          p=(poly)h->CopyD();
3186          h=h->next;
3187        }
3188        else return TRUE;
3189        if ((h!=NULL) && (h->Typ()==POLY_CMD))
3190        {
3191          q=(poly)h->CopyD();
3192          h=h->next;
3193        }
3194        else return TRUE;
3195        if ((h!=NULL) && (h->Typ()==INT_CMD))
3196        {
3197          is=(int)((long)(h->Data()));
3198          res->rtyp=POLY_CMD;
3199          //        res->rtyp=IDEAL_CMD;
3200          if (rIsPluralRing(currRing))
3201          {
3202            res->data = nc_rat_CreateSpoly(p,q,is,currRing);
3203            //        res->data = ncGCD(p,q,currRing);
3204          }
3205          else res->data=p;
3206        }
3207        else return TRUE;
3208        return FALSE;
3209      }
3210      else
3211  #endif // HAVE_RATGRING
3212  /*==================== Rat def =================*/
3213      if (strcmp(sys_cmd, "ratVar") == 0)
3214      {
3215        int start,end;
3216        if ((h!=NULL) && (h->Typ()==POLY_CMD))
3217        {
3218          start=pIsPurePower((poly)h->Data());
3219          h=h->next;
3220        }
3221        else return TRUE;
3222        if ((h!=NULL) && (h->Typ()==POLY_CMD))
3223        {
3224          end=pIsPurePower((poly)h->Data());
3225          h=h->next;
3226        }
3227        else return TRUE;
3228        currRing->real_var_start=start;
3229        currRing->real_var_end=end;
3230        return (start==0)||(end==0)||(start>end);
3231      }
3232      else
3233  /*==================== t-rep-GB ==================================*/
3234      if (strcmp(sys_cmd, "unifastmult")==0)
3235      {
3236        poly f = (poly)h->Data();
3237        h=h->next;
3238        poly g=(poly)h->Data();
3239        res->rtyp=POLY_CMD;
3240        res->data=unifastmult(f,g,currRing);
3241        return(FALSE);
3242      }
3243      else
3244      if (strcmp(sys_cmd, "multifastmult")==0)
3245      {
3246        poly f = (poly)h->Data();
3247        h=h->next;
3248        poly g=(poly)h->Data();
3249        res->rtyp=POLY_CMD;
3250        res->data=multifastmult(f,g,currRing);
3251        return(FALSE);
3252      }
3253      else
3254      if (strcmp(sys_cmd, "mults")==0)
3255      {
3256        res->rtyp=INT_CMD ;
3257        res->data=(void*)(long) Mults();
3258        return(FALSE);
3259      }
3260      else
3261      if (strcmp(sys_cmd, "fastpower")==0)
3262      {
3263        ring r = currRing;
3264        poly f = (poly)h->Data();
3265        h=h->next;
3266        int n=(int)((long)h->Data());
3267        res->rtyp=POLY_CMD ;
3268        res->data=(void*) pFastPower(f,n,r);
3269        return(FALSE);
3270      }
3271      else
3272      if (strcmp(sys_cmd, "normalpower")==0)
3273      {
3274        poly f = (poly)h->Data();
3275        h=h->next;
3276        int n=(int)((long)h->Data());
3277        res->rtyp=POLY_CMD ;
3278        res->data=(void*) pPower(pCopy(f),n);
3279        return(FALSE);
3280      }
3281      else
3282      if (strcmp(sys_cmd, "MCpower")==0)
3283      {
3284        ring r = currRing;
3285        poly f = (poly)h->Data();
3286        h=h->next;
3287        int n=(int)((long)h->Data());
3288        res->rtyp=POLY_CMD ;
3289        res->data=(void*) pFastPowerMC(f,n,r);
3290        return(FALSE);
3291      }
3292      else
3293      if (strcmp(sys_cmd, "bit_subst")==0)
3294      {
3295        ring r = currRing;
3296        poly outer = (poly)h->Data();
3297        h=h->next;
3298        poly inner=(poly)h->Data();
3299        res->rtyp=POLY_CMD ;
3300        res->data=(void*) uni_subst_bits(outer, inner,r);
3301        return(FALSE);
3302      }
3303      else
3304  /*==================== gcd-varianten =================*/
3305      if (strcmp(sys_cmd, "gcd") == 0)
3306      {
3307        if (h==NULL)
3308        {
3309        #if 0
3310          Print("FLINT_P:%d (use Flints gcd for polynomials in char p)\n",isOn(SW_USE_FL_GCD_P));
3311          Print("FLINT_0:%d (use Flints gcd for polynomials in char 0)\n",isOn(SW_USE_FL_GCD_0));
3312        #endif
3313          Print("EZGCD:%d (use EZGCD for gcd of polynomials in char 0)\n",isOn(SW_USE_EZGCD));
3314          Print("EZGCD_P:%d (use EZGCD_P for gcd of polynomials in char p)\n",isOn(SW_USE_EZGCD_P));
3315          Print("CRGCD:%d (use chinese Remainder for gcd of polynomials in char 0)\n",isOn(SW_USE_CHINREM_GCD));
3316          #ifndef __CYGWIN__
3317          Print("homog:%d (use homog. test for factorization of polynomials)\n",singular_homog_flag);
3318          #endif
3319          return FALSE;
3320        }
3321        else
3322        if ((h!=NULL) && (h->Typ()==STRING_CMD)
3323        && (h->next!=NULL) && (h->next->Typ()==INT_CMD))
3324        {
3325          int d=(int)(long)h->next->Data();
3326          char *s=(char *)h->Data();
3327        #if 0
3328          if (strcmp(s,"FLINT_P")==0) { if (d) On(SW_USE_FL_GCD_P); else Off(SW_USE_FL_GCD_P); } else
3329          if (strcmp(s,"FLINT_0")==0) { if (d) On(SW_USE_FL_GCD_0); else Off(SW_USE_FL_GCD_0); } else
3330        #endif
3331          if (strcmp(s,"EZGCD")==0) { if (d) On(SW_USE_EZGCD); else Off(SW_USE_EZGCD); } else
3332          if (strcmp(s,"EZGCD_P")==0) { if (d) On(SW_USE_EZGCD_P); else Off(SW_USE_EZGCD_P); } else
3333          if (strcmp(s,"CRGCD")==0) { if (d) On(SW_USE_CHINREM_GCD); else Off(SW_USE_CHINREM_GCD); } else
3334          #ifndef __CYGWIN__
3335          if (strcmp(s,"homog")==0) { if (d) singular_homog_flag=1; else singular_homog_flag=0; } else
3336          #endif
3337          return TRUE;
3338          return FALSE;
3339        }
3340        else return TRUE;
3341      }
3342      else
3343  /*==================== subring =================*/
3344      if (strcmp(sys_cmd, "subring") == 0)
3345      {
3346        if (h!=NULL)
3347        {
3348          extern ring rSubring(ring r,leftv v); /* ipshell.cc*/
3349          res->data=(char *)rSubring(currRing,h);
3350          res->rtyp=RING_CMD;
3351          return res->data==NULL;
3352        }
3353        else return TRUE;
3354      }
3355      else
3356  /*==================== HNF =================*/
3357  #ifdef HAVE_NTL
3358      if (strcmp(sys_cmd, "HNF") == 0)
3359      {
3360        if (h!=NULL)
3361        {
3362          res->rtyp=h->Typ();
3363          if (h->Typ()==MATRIX_CMD)
3364          {
3365            res->data=(char *)singntl_HNF((matrix)h->Data(), currRing);
3366            return FALSE;
3367          }
3368          else if (h->Typ()==INTMAT_CMD)
3369          {
3370            res->data=(char *)singntl_HNF((intvec*)h->Data());
3371            return FALSE;
3372          }
3373          else if (h->Typ()==INTMAT_CMD)
3374          {
3375            res->data=(char *)singntl_HNF((intvec*)h->Data());
3376            return FALSE;
3377          }
3378          else
3379          {
3380            WerrorS("expected `system(\"HNF\",<matrix|intmat|bigintmat>)`");
3381            return TRUE;
3382          }
3383        }
3384        else return TRUE;
3385      }
3386      else
3387  /*================= probIrredTest ======================*/
3388      if (strcmp (sys_cmd, "probIrredTest") == 0)
3389      {
3390        if (h!=NULL && (h->Typ()== POLY_CMD) && ((h->next != NULL) && h->next->Typ() == STRING_CMD))
3391        {
3392          CanonicalForm F= convSingPFactoryP((poly)(h->Data()), currRing);
3393          char *s=(char *)h->next->Data();
3394          double error= atof (s);
3395          int irred= probIrredTest (F, error);
3396          res->rtyp= INT_CMD;
3397          res->data= (void*)(long)irred;
3398          return FALSE;
3399        }
3400        else return TRUE;
3401      }
3402      else
3403  #endif
3404  /*==================== mpz_t loader ======================*/
3405    if(strcmp(sys_cmd, "GNUmpLoad")==0)
3406    {
3407      if ((h != NULL) && (h->Typ() == STRING_CMD))
3408      {
3409        char* filename = (char*)h->Data();
3410        FILE* f = fopen(filename, "r");
3411        if (f == NULL)
3412        {
3413          WerrorS( "invalid file name (in paths use '/')");
3414          return FALSE;
3415        }
3416        mpz_t m; mpz_init(m);
3417        mpz_inp_str(m, f, 10);
3418        fclose(f);
3419        number n = n_InitMPZ(m, coeffs_BIGINT);
3420        res->rtyp = BIGINT_CMD;
3421        res->data = (void*)n;
3422        return FALSE;
3423      }
3424      else
3425      {
3426        WerrorS( "expected valid file name as a string");
3427        return TRUE;
3428      }
3429    }
3430    else
3431  /*==================== intvec matching ======================*/
3432    /* Given two non-empty intvecs, the call
3433            'system("intvecMatchingSegments", ivec, jvec);'
3434         computes all occurences of jvec in ivec, i.e., it returns
3435         a list of int indices k such that ivec[k..size(jvec)+k-1] = jvec.
3436         If no such k exists (e.g. when ivec is shorter than jvec), an
3437         intvec with the single entry 0 is being returned. */
3438    if(strcmp(sys_cmd, "intvecMatchingSegments")==0)
3439    {
3440      if ((h       != NULL) && (h->Typ()       == INTVEC_CMD) &&
3441          (h->next != NULL) && (h->next->Typ() == INTVEC_CMD) &&
3442          (h->next->next == NULL))
3443      {
3444        intvec* ivec = (intvec*)h->Data();
3445        intvec* jvec = (intvec*)h->next->Data();
3446        intvec* r = new intvec(1); (*r)[0] = 0;
3447        int validEntries = 0;
3448        for (int k = 0; k <= ivec->rows() - jvec->rows(); k++)
3449        {
3450          if (memcmp(&(*ivec)[k], &(*jvec)[0],
3451                       sizeof(int) * jvec->rows()) == 0)
3452          {
3453            if (validEntries == 0)
3454              (*r)[0] = k + 1;
3455            else
3456            {
3457              r->resize(validEntries + 1);
3458              (*r)[validEntries] = k + 1;
3459            }
3460            validEntries++;
3461          }
3462        }
3463        res->rtyp = INTVEC_CMD;
3464        res->data = (void*)r;
3465        return FALSE;
3466      }
3467      else
3468      {
3469        WerrorS("expected two non-empty intvecs as arguments");
3470        return TRUE;
3471      }
3472    }
3473    else
3474  /* ================== intvecOverlap ======================= */
3475    /* Given two non-empty intvecs, the call
3476            'system("intvecOverlap", ivec, jvec);'
3477         computes the longest intvec kvec such that ivec ends with kvec
3478         and jvec starts with kvec. The length of this overlap is being
3479         returned. If there is no overlap at all, then 0 is being returned. */
3480    if(strcmp(sys_cmd, "intvecOverlap")==0)
3481    {
3482      if ((h       != NULL) && (h->Typ()       == INTVEC_CMD) &&
3483            (h->next != NULL) && (h->next->Typ() == INTVEC_CMD) &&
3484            (h->next->next == NULL))
3485      {
3486        intvec* ivec = (intvec*)h->Data();
3487        intvec* jvec = (intvec*)h->next->Data();
3488        int ir = ivec->rows(); int jr = jvec->rows();
3489        int r = jr; if (ir < jr) r = ir;   /* r = min{ir, jr} */
3490        while ((r >= 1) && (memcmp(&(*ivec)[ir - r], &(*jvec)[0],
3491                                     sizeof(int) * r) != 0))
3492          r--;
3493        res->rtyp = INT_CMD;
3494        res->data = (void*)(long)r;
3495        return FALSE;
3496      }
3497      else
3498      {
3499        WerrorS("expected two non-empty intvecs as arguments");
3500        return TRUE;
3501      }
3502    }
3503    else
3504  /*==================== Hensel's lemma ======================*/
3505    if(strcmp(sys_cmd, "henselfactors")==0)
3506    {
3507      if ((h != NULL) && (h->Typ() == INT_CMD) &&
3508        (h->next != NULL) && (h->next->Typ() == INT_CMD) &&
3509        (h->next->next != NULL) && (h->next->next->Typ() == POLY_CMD) &&
3510        (h->next->next->next != NULL) &&
3511        (h->next->next->next->Typ() == POLY_CMD) &&
3512        (h->next->next->next->next != NULL) &&
3513        (h->next->next->next->next->Typ() == POLY_CMD) &&
3514        (h->next->next->next->next->next != NULL) &&
3515        (h->next->next->next->next->next->Typ() == INT_CMD) &&
3516        (h->next->next->next->next->next->next == NULL))
3517      {
3518        int xIndex = (int)(long)h->Data();
3519        int yIndex = (int)(long)h->next->Data();
3520        poly hh    = (poly)h->next->next->Data();
3521        poly f0    = (poly)h->next->next->next->Data();
3522        poly g0    = (poly)h->next->next->next->next->Data();
3523        int d      = (int)(long)h->next->next->next->next->next->Data();
3524        poly f; poly g;
3525        henselFactors(xIndex, yIndex, hh, f0, g0, d, f, g);
3526        lists L = (lists)omAllocBin(slists_bin);
3527        L->Init(2);
3528        L->m[0].rtyp = POLY_CMD; L->m[0].data=(void*)f;
3529        L->m[1].rtyp = POLY_CMD; L->m[1].data=(void*)g;
3530        res->rtyp = LIST_CMD;
3531        res->data = (char *)L;
3532        return FALSE;
3533      }
3534      else
3535      {
3536        WerrorS( "expected argument list (int, int, poly, poly, poly, int)");
3537        return TRUE;
3538      }
3539    }
3540    else
3541  /*==================== Approx_Step  =================*/
3542  #ifdef HAVE_PLURAL
3543    if (strcmp(sys_cmd, "astep") == 0)
3544    {
3545      ideal I;
3546      if ((h!=NULL) && (h->Typ()==IDEAL_CMD))
3547      {
3548        I=(ideal)h->CopyD();
3549        res->rtyp=IDEAL_CMD;
3550        if (rIsPluralRing(currRing)) res->data=Approx_Step(I);
3551        else res->data=I;
3552        setFlag(res,FLAG_STD);
3553      }
3554      else return TRUE;
3555      return FALSE;
3556    }
3557    else
3558  #endif
3559  /*==================== PrintMat  =================*/
3560  #ifdef HAVE_PLURAL
3561    if (strcmp(sys_cmd, "PrintMat") == 0)
3562    {
3563      int a;
3564      int b;
3565      ring r;
3566      int metric;
3567      if (h!=NULL)
3568      {
3569        if (h->Typ()==INT_CMD)
3570        {
3571          a=(int)((long)(h->Data()));
3572          h=h->next;
3573        }
3574        else if (h->Typ()==INT_CMD)
3575        {
3576          b=(int)((long)(h->Data()));
3577          h=h->next;
3578        }
3579        else if (h->Typ()==RING_CMD)
3580        {
3581          r=(ring)h->Data();
3582          h=h->next;
3583        }
3584        else
3585          return TRUE;
3586      }
3587      else
3588        return TRUE;
3589      if ((h!=NULL) && (h->Typ()==INT_CMD))
3590      {
3591        metric=(int)((long)(h->Data()));
3592      }
3593      res->rtyp=MATRIX_CMD;
3594      if (rIsPluralRing(r)) res->data=nc_PrintMat(a,b,r,metric);
3595      else res->data=NULL;
3596      return FALSE;
3597    }
3598    else
3599  #endif
3600/* ============ NCUseExtensions ======================== */
3601  #ifdef HAVE_PLURAL
3602    if(strcmp(sys_cmd,"NCUseExtensions")==0)
3603    {
3604      if ((h!=NULL) && (h->Typ()==INT_CMD))
3605        res->data=(void *)(long)setNCExtensions( (int)((long)(h->Data())) );
3606      else
3607        res->data=(void *)(long)getNCExtensions();
3608      res->rtyp=INT_CMD;
3609      return FALSE;
3610    }
3611    else
3612  #endif
3613/* ============ NCGetType ======================== */
3614  #ifdef HAVE_PLURAL
3615    if(strcmp(sys_cmd,"NCGetType")==0)
3616    {
3617      res->rtyp=INT_CMD;
3618      if( rIsPluralRing(currRing) )
3619        res->data=(void *)(long)ncRingType(currRing);
3620      else
3621        res->data=(void *)(-1L);
3622      return FALSE;
3623    }
3624    else
3625  #endif
3626/* ============ ForceSCA ======================== */
3627  #ifdef HAVE_PLURAL
3628    if(strcmp(sys_cmd,"ForceSCA")==0)
3629    {
3630      if( !rIsPluralRing(currRing) )
3631        return TRUE;
3632      int b, e;
3633      if ((h!=NULL) && (h->Typ()==INT_CMD))
3634      {
3635        b = (int)((long)(h->Data()));
3636        h=h->next;
3637      }
3638      else return TRUE;
3639      if ((h!=NULL) && (h->Typ()==INT_CMD))
3640      {
3641        e = (int)((long)(h->Data()));
3642      }
3643      else return TRUE;
3644      if( !sca_Force(currRing, b, e) )
3645        return TRUE;
3646      return FALSE;
3647    }
3648    else
3649  #endif
3650/* ============ ForceNewNCMultiplication ======================== */
3651  #ifdef HAVE_PLURAL
3652    if(strcmp(sys_cmd,"ForceNewNCMultiplication")==0)
3653    {
3654      if( !rIsPluralRing(currRing) )
3655        return TRUE;
3656      if( !ncInitSpecialPairMultiplication(currRing) ) // No Plural!
3657        return TRUE;
3658      return FALSE;
3659    }
3660    else
3661  #endif
3662/* ============ ForceNewOldNCMultiplication ======================== */
3663  #ifdef HAVE_PLURAL
3664    if(strcmp(sys_cmd,"ForceNewOldNCMultiplication")==0)
3665    {
3666      if( !rIsPluralRing(currRing) )
3667        return TRUE;
3668      if( !ncInitSpecialPowersMultiplication(currRing) ) // Enable Formula for Plural (depends on swiches)!
3669        return TRUE;
3670      return FALSE;
3671    }
3672    else
3673  #endif
3674/*==================== test64 =================*/
3675  #if 0
3676    if(strcmp(sys_cmd,"test64")==0)
3677    {
3678      long l=8;int i;
3679      for(i=1;i<62;i++)
3680      {
3681        l=l<<1;
3682        number n=n_Init(l,coeffs_BIGINT);
3683        Print("%ld= ",l);n_Print(n,coeffs_BIGINT);
3684        CanonicalForm nn=n_convSingNFactoryN(n,TRUE,coeffs_BIGINT);
3685        n_Delete(&n,coeffs_BIGINT);
3686        n=n_convFactoryNSingN(nn,coeffs_BIGINT);
3687        PrintS(" F:");
3688        n_Print(n,coeffs_BIGINT);
3689        PrintLn();
3690        n_Delete(&n,coeffs_BIGINT);
3691      }
3692      Print("SIZEOF_LONG=%d\n",SIZEOF_LONG);
3693      return FALSE;
3694    }
3695    else
3696   #endif
3697/*==================== n_SwitchChinRem =================*/
3698    if(strcmp(sys_cmd,"cache_chinrem")==0)
3699    {
3700      EXTERN_VAR int n_SwitchChinRem;
3701      Print("caching inverse in chines remainder:%d\n",n_SwitchChinRem);
3702      if ((h!=NULL)&&(h->Typ()==INT_CMD))
3703        n_SwitchChinRem=(int)(long)h->Data();
3704      return FALSE;
3705    }
3706    else
3707/*==================== LU for bigintmat =================*/
3708#ifdef SINGULAR_4_2
3709    if(strcmp(sys_cmd,"LU")==0)
3710    {
3711      if ((h!=NULL) && (h->Typ()==CMATRIX_CMD))
3712      {
3713        // get the argument:
3714        bigintmat *b=(bigintmat *)h->Data();
3715        // just for tests: simply transpose
3716        bigintmat *bb=b->transpose();
3717        // return the result:
3718        res->rtyp=CMATRIX_CMD;
3719        res->data=(char*)bb;
3720        return FALSE;
3721      }
3722      else
3723      {
3724        WerrorS("system(\"LU\",<cmatrix>) expected");
3725        return TRUE;
3726      }
3727    }
3728    else
3729#endif
3730/*==================== sort =================*/
3731    if(strcmp(sys_cmd,"sort")==0)
3732    {
3733      extern BOOLEAN jjSORTLIST(leftv,leftv);
3734      if (h->Typ()==LIST_CMD)
3735        return jjSORTLIST(res,h);
3736      else
3737        return TRUE;
3738    }
3739    else
3740/*==================== uniq =================*/
3741    if(strcmp(sys_cmd,"uniq")==0)
3742    {
3743      extern BOOLEAN jjUNIQLIST(leftv, leftv);
3744      if (h->Typ()==LIST_CMD)
3745        return jjUNIQLIST(res,h);
3746      else
3747        return TRUE;
3748    }
3749    else
3750/*==================== GF(p,n) ==================================*/
3751    if(strcmp(sys_cmd,"GF")==0)
3752    {
3753      const short t[]={3,INT_CMD,INT_CMD,STRING_CMD};
3754      if (iiCheckTypes(h,t,1))
3755      {
3756        int p=(int)(long)h->Data();
3757        int n=(int)(long)h->next->Data();
3758        char *v=(char*)h->next->next->CopyD();
3759        GFInfo param;
3760        param.GFChar = p;
3761        param.GFDegree = n;
3762        param.GFPar_name = v;
3763        coeffs cf= nInitChar(n_GF, &param);
3764        res->rtyp=CRING_CMD;
3765        res->data=cf;
3766        return FALSE;
3767      }
3768      else
3769        return TRUE;
3770    }
3771    else
3772/*==================== power* ==================================*/
3773    #if 0
3774    if(strcmp(sys_cmd,"power1")==0)
3775    {
3776      res->rtyp=POLY_CMD;
3777      poly f=(poly)h->CopyD();
3778      poly g=pPower(f,2000);
3779      res->data=(void *)g;
3780      return FALSE;
3781    }
3782    else
3783    if(strcmp(sys_cmd,"power2")==0)
3784    {
3785      res->rtyp=POLY_CMD;
3786      poly f=(poly)h->Data();
3787      poly g=pOne();
3788      for(int i=0;i<2000;i++)
3789        g=pMult(g,pCopy(f));
3790      res->data=(void *)g;
3791      return FALSE;
3792    }
3793    if(strcmp(sys_cmd,"power3")==0)
3794    {
3795      res->rtyp=POLY_CMD;
3796      poly f=(poly)h->Data();
3797      poly p2=pMult(pCopy(f),pCopy(f));
3798      poly p4=pMult(pCopy(p2),pCopy(p2));
3799      poly p8=pMult(pCopy(p4),pCopy(p4));
3800      poly p16=pMult(pCopy(p8),pCopy(p8));
3801      poly p32=pMult(pCopy(p16),pCopy(p16));
3802      poly p64=pMult(pCopy(p32),pCopy(p32));
3803      poly p128=pMult(pCopy(p64),pCopy(p64));
3804      poly p256=pMult(pCopy(p128),pCopy(p128));
3805      poly p512=pMult(pCopy(p256),pCopy(p256));
3806      poly p1024=pMult(pCopy(p512),pCopy(p512));
3807      poly p1536=pMult(p1024,p512);
3808      poly p1792=pMult(p1536,p256);
3809      poly p1920=pMult(p1792,p128);
3810      poly p1984=pMult(p1920,p64);
3811      poly p2000=pMult(p1984,p16);
3812      res->data=(void *)p2000;
3813      pDelete(&p2);
3814      pDelete(&p4);
3815      pDelete(&p8);
3816      //pDelete(&p16);
3817      pDelete(&p32);
3818      //pDelete(&p64);
3819      //pDelete(&p128);
3820      //pDelete(&p256);
3821      //pDelete(&p512);
3822      //pDelete(&p1024);
3823      //pDelete(&p1536);
3824      //pDelete(&p1792);
3825      //pDelete(&p1920);
3826      //pDelete(&p1984);
3827      return FALSE;
3828    }
3829    else
3830    #endif
3831/* ccluster --------------------------------------------------------------*/
3832#ifdef HAVE_CCLUSTER
3833    if(strcmp(sys_cmd,"ccluster")==0)
3834    {
3835      if ((currRing!=NULL)
3836      && (rField_is_Q(currRing) || rField_is_R(currRing) || rField_is_long_R(currRing)))
3837      {
3838        const short t[]={5,POLY_CMD,NUMBER_CMD,NUMBER_CMD,NUMBER_CMD,NUMBER_CMD};
3839        const short t2[]={6,POLY_CMD,POLY_CMD,NUMBER_CMD,NUMBER_CMD,NUMBER_CMD,NUMBER_CMD};
3840
3841//         printf("test t : %d\n", h->Typ()==POLY_CMD);
3842//         printf("test t : %d\n", h->next->Typ()==POLY_CMD);
3843        int pol_with_complex_coeffs=0;
3844        if (h->next->Typ()==POLY_CMD)
3845            pol_with_complex_coeffs=1;
3846
3847        if ( (pol_with_complex_coeffs==0 && iiCheckTypes(h,t,1))
3848       ||(pol_with_complex_coeffs==1 && iiCheckTypes(h,t2,1)) )
3849        {
3850          // convert first arg. to fmpq_poly_t
3851          fmpq_poly_t fre, fim;
3852          convSingPFlintP(fre,(poly)h->Data(),currRing); h=h->next;
3853          if (pol_with_complex_coeffs==1)
3854          { // convert second arg. to fmpq_poly_t
3855            convSingPFlintP(fim,(poly)h->Data(),currRing); h=h->next;
3856          }
3857          // convert box-center(re,im), box-size, epsilon
3858          fmpq_t center_re,center_im,boxsize,eps;
3859          convSingNFlintN(center_re,(number)h->Data(),currRing->cf); h=h->next;
3860          convSingNFlintN(center_im,(number)h->Data(),currRing->cf); h=h->next;
3861          convSingNFlintN(boxsize,(number)h->Data(),currRing->cf); h=h->next;
3862          convSingNFlintN(eps,(number)h->Data(),currRing->cf); h=h->next;
3863          // alloc arrays
3864          int n=fmpq_poly_length(fre);
3865          fmpq_t* re_part=(fmpq_t*)omAlloc(n*sizeof(fmpq_t));
3866          fmpq_t* im_part=(fmpq_t*)omAlloc(n*sizeof(fmpq_t));
3867          int *mult      =(int*)   omAlloc(n*sizeof(int));
3868          for(int i=0; i<n;i++)
3869          { fmpq_init(re_part[i]); fmpq_init(im_part[i]); }
3870          // call cccluster, adjust n
3871          int verbosity =0; //nothing is printed
3872          int strategy = 23; //default strategy
3873          int nn=0;
3874          long nb_threads = (long) feOptValue(FE_OPT_CPUS);
3875          strategy = strategy+(nb_threads<<6);
3876//       printf("nb threads: %ld\n", nb_threads);
3877//       printf("strategy: %ld\n", strategy);
3878          if (pol_with_complex_coeffs==0)
3879            nn=ccluster_interface_poly_real(re_part,im_part,mult,fre,center_re,center_im,boxsize,eps,strategy,verbosity);
3880          else
3881            nn=ccluster_interface_poly_real_imag(re_part,im_part,mult,fre,fim,center_re,center_im,boxsize,eps,strategy,verbosity);
3882          // convert to list
3883          lists l=(lists)omAlloc0Bin(slists_bin);
3884          l->Init(nn);
3885          for(int i=0; i<nn;i++)
3886          {
3887            lists ll=(lists)omAlloc0Bin(slists_bin);
3888            l->m[i].rtyp=LIST_CMD;
3889            l->m[i].data=ll;
3890            ll->Init(3);
3891            ll->m[0].rtyp=NUMBER_CMD;
3892            ll->m[1].rtyp=NUMBER_CMD;
3893            ll->m[2].rtyp=INT_CMD;
3894            ll->m[0].data=convFlintNSingN(re_part[i],currRing->cf);
3895            ll->m[1].data=convFlintNSingN(im_part[i],currRing->cf);
3896            ll->m[2].data=(void *)(long)mult[i];
3897          }
3898          //clear re, im, mults, fre, fim
3899          for(int i=n-1;i>=0;i--) { fmpq_clear(re_part[i]); fmpq_clear(im_part[i]); }
3900          omFree(re_part);
3901          omFree(im_part);
3902          omFree(mult);
3903          fmpq_clear(center_re); fmpq_clear(center_im); fmpq_clear(boxsize); fmpq_clear(eps);
3904          fmpq_poly_clear(fre);
3905          if (pol_with_complex_coeffs==1) fmpq_poly_clear(fim);
3906          // result
3907          res->rtyp=LIST_CMD;
3908          res->data=l;
3909          return FALSE;
3910        }
3911      }
3912      return TRUE;
3913    }
3914    else
3915#endif
3916/* ====== maEvalAt ============================*/
3917    if(strcmp(sys_cmd,"evaluate")==0)
3918    {
3919      extern number maEvalAt(const poly p,const number* pt, const ring r);
3920      if (h->Typ()!=POLY_CMD)
3921      {
3922        WerrorS("expected system(\"evaluate\",<poly>,..)");
3923        return TRUE;
3924      }
3925      poly p=(poly)h->Data();
3926      number *pt=(number*)omAlloc(sizeof(number)*currRing->N);
3927      for(int i=0;i<currRing->N;i++)
3928      {
3929        h=h->next;
3930        if ((h==NULL)||(h->Typ()!=NUMBER_CMD))
3931        {
3932          WerrorS("system(\"evaluate\",<poly>,<number>..) - expect number");
3933          return TRUE;
3934        }
3935        pt[i]=(number)h->Data();
3936      }
3937      res->data=maEvalAt(p,pt,currRing);
3938      res->rtyp=NUMBER_CMD;
3939      return FALSE;
3940    }
3941    else
3942/* ====== DivRem ============================*/
3943    if(strcmp(sys_cmd,"DivRem")==0)
3944    {
3945      const short t1[]={2,POLY_CMD,POLY_CMD};
3946      if (iiCheckTypes(h,t1,1))
3947      {
3948        poly p=(poly)h->CopyD();
3949        poly q=(poly)h->next->CopyD();
3950        poly rest;
3951        res->data=p_DivRem(p,q,rest,currRing);
3952        res->rtyp=POLY_CMD;
3953        Print("rest:");pWrite(rest);
3954        return FALSE;
3955      }
3956      else
3957      {
3958        WerrorS("expected system(\"DivRem\",<poly>,<poly>)");
3959        return TRUE;
3960      }
3961    }
3962    else
3963/*==================== Error =================*/
3964      Werror( "(extended) system(\"%s\",...) %s", sys_cmd, feNotImplemented );
3965  }
3966  return TRUE;
3967}
3968
3969#endif // HAVE_EXTENDED_SYSTEM
3970
3971
Note: See TracBrowser for help on using the repository browser.