source: git/Singular/extra.cc @ 78a9c9

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