source: git/Singular/extra.cc @ 841a57

fieker-DuValspielwiese
Last change on this file since 841a57 was 273a2f, checked in by Hans Schoenemann <hannes@…>, 2 years ago
experimental: fq_nmod_mat_rref
  • Property mode set to 100644
File size: 116.9 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(strlen(SINGULAR_PROCS_DIR),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  /*==================== pcv ==================================*/
1241  #ifdef HAVE_PCV
1242    if(strcmp(sys_cmd,"pcvLAddL")==0)
1243    {
1244      return pcvLAddL(res,h);
1245    }
1246    else
1247    if(strcmp(sys_cmd,"pcvPMulL")==0)
1248    {
1249      return pcvPMulL(res,h);
1250    }
1251    else
1252    if(strcmp(sys_cmd,"pcvMinDeg")==0)
1253    {
1254      return pcvMinDeg(res,h);
1255    }
1256    else
1257    if(strcmp(sys_cmd,"pcvP2CV")==0)
1258    {
1259      return pcvP2CV(res,h);
1260    }
1261    else
1262    if(strcmp(sys_cmd,"pcvCV2P")==0)
1263    {
1264      return pcvCV2P(res,h);
1265    }
1266    else
1267    if(strcmp(sys_cmd,"pcvDim")==0)
1268    {
1269      return pcvDim(res,h);
1270    }
1271    else
1272    if(strcmp(sys_cmd,"pcvBasis")==0)
1273    {
1274      return pcvBasis(res,h);
1275    }
1276    else
1277  #endif
1278  /*==================== hessenberg/eigenvalues ==================================*/
1279  #ifdef HAVE_EIGENVAL
1280    if(strcmp(sys_cmd,"hessenberg")==0)
1281    {
1282      return evHessenberg(res,h);
1283    }
1284    else
1285  #endif
1286  /*==================== eigenvalues ==================================*/
1287  #ifdef HAVE_EIGENVAL
1288    if(strcmp(sys_cmd,"eigenvals")==0)
1289    {
1290      return evEigenvals(res,h);
1291    }
1292    else
1293  #endif
1294  /*==================== rowelim ==================================*/
1295  #ifdef HAVE_EIGENVAL
1296    if(strcmp(sys_cmd,"rowelim")==0)
1297    {
1298      return evRowElim(res,h);
1299    }
1300    else
1301  #endif
1302  /*==================== rowcolswap ==================================*/
1303  #ifdef HAVE_EIGENVAL
1304    if(strcmp(sys_cmd,"rowcolswap")==0)
1305    {
1306      return evSwap(res,h);
1307    }
1308    else
1309  #endif
1310  /*==================== Gauss-Manin system ==================================*/
1311  #ifdef HAVE_GMS
1312    if(strcmp(sys_cmd,"gmsnf")==0)
1313    {
1314      return gmsNF(res,h);
1315    }
1316    else
1317  #endif
1318  /*==================== contributors =============================*/
1319    if(strcmp(sys_cmd,"contributors") == 0)
1320    {
1321      res->rtyp=STRING_CMD;
1322      res->data=(void *)omStrDup(
1323         "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");
1324      return FALSE;
1325    }
1326    else
1327  /*==================== spectrum =============================*/
1328    #ifdef HAVE_SPECTRUM
1329    if(strcmp(sys_cmd,"spectrum") == 0)
1330    {
1331      if ((h==NULL) || (h->Typ()!=POLY_CMD))
1332      {
1333        WerrorS("poly expected");
1334        return TRUE;
1335      }
1336      if (h->next==NULL)
1337        return spectrumProc(res,h);
1338      if (h->next->Typ()!=INT_CMD)
1339      {
1340        WerrorS("poly,int expected");
1341        return TRUE;
1342      }
1343      if(((long)h->next->Data())==1L)
1344         return spectrumfProc(res,h);
1345      return spectrumProc(res,h);
1346    }
1347    else
1348  /*==================== semic =============================*/
1349    if(strcmp(sys_cmd,"semic") == 0)
1350    {
1351      if ((h->next!=NULL)
1352      && (h->Typ()==LIST_CMD)
1353      && (h->next->Typ()==LIST_CMD))
1354      {
1355        if (h->next->next==NULL)
1356          return semicProc(res,h,h->next);
1357        else if (h->next->next->Typ()==INT_CMD)
1358          return semicProc3(res,h,h->next,h->next->next);
1359      }
1360      return TRUE;
1361    }
1362    else
1363  /*==================== spadd =============================*/
1364    if(strcmp(sys_cmd,"spadd") == 0)
1365    {
1366      const short t[]={2,LIST_CMD,LIST_CMD};
1367      if (iiCheckTypes(h,t,1))
1368      {
1369        return spaddProc(res,h,h->next);
1370      }
1371      return TRUE;
1372    }
1373    else
1374  /*==================== spmul =============================*/
1375    if(strcmp(sys_cmd,"spmul") == 0)
1376    {
1377      const short t[]={2,LIST_CMD,INT_CMD};
1378      if (iiCheckTypes(h,t,1))
1379      {
1380        return spmulProc(res,h,h->next);
1381      }
1382      return TRUE;
1383    }
1384    else
1385  #endif
1386/*==================== tensorModuleMult ========================= */
1387  #define HAVE_SHEAFCOH_TRICKS 1
1388
1389  #ifdef HAVE_SHEAFCOH_TRICKS
1390    if(strcmp(sys_cmd,"tensorModuleMult")==0)
1391    {
1392      const short t[]={2,INT_CMD,MODUL_CMD};
1393  //      WarnS("tensorModuleMult!");
1394      if (iiCheckTypes(h,t,1))
1395      {
1396        int m = (int)( (long)h->Data() );
1397        ideal M = (ideal)h->next->Data();
1398        res->rtyp=MODUL_CMD;
1399        res->data=(void *)id_TensorModuleMult(m, M, currRing);
1400        return FALSE;
1401      }
1402      return TRUE;
1403    }
1404    else
1405  #endif
1406  /*==================== twostd  =================*/
1407  #ifdef HAVE_PLURAL
1408    if (strcmp(sys_cmd, "twostd") == 0)
1409    {
1410      ideal I;
1411      if ((h!=NULL) && (h->Typ()==IDEAL_CMD))
1412      {
1413        I=(ideal)h->CopyD();
1414        res->rtyp=IDEAL_CMD;
1415        if (rIsPluralRing(currRing)) res->data=twostd(I);
1416        else res->data=I;
1417        setFlag(res,FLAG_TWOSTD);
1418        setFlag(res,FLAG_STD);
1419      }
1420      else return TRUE;
1421      return FALSE;
1422    }
1423    else
1424  #endif
1425  /*==================== lie bracket =================*/
1426  #ifdef HAVE_PLURAL
1427    if (strcmp(sys_cmd, "bracket") == 0)
1428    {
1429      const short t[]={2,POLY_CMD,POLY_CMD};
1430      if (iiCheckTypes(h,t,1))
1431      {
1432        poly p=(poly)h->CopyD();
1433        h=h->next;
1434        poly q=(poly)h->Data();
1435        res->rtyp=POLY_CMD;
1436        if (rIsPluralRing(currRing))  res->data=nc_p_Bracket_qq(p,q, currRing);
1437        return FALSE;
1438      }
1439      return TRUE;
1440    }
1441    else
1442  #endif
1443  /*==================== env ==================================*/
1444  #ifdef HAVE_PLURAL
1445    if (strcmp(sys_cmd, "env")==0)
1446    {
1447      if ((h!=NULL) && (h->Typ()==RING_CMD))
1448      {
1449        ring r = (ring)h->Data();
1450        res->data = rEnvelope(r);
1451        res->rtyp = RING_CMD;
1452        return FALSE;
1453      }
1454      else
1455      {
1456        WerrorS("`system(\"env\",<ring>)` expected");
1457        return TRUE;
1458      }
1459    }
1460    else
1461  #endif
1462/* ============ opp ======================== */
1463  #ifdef HAVE_PLURAL
1464    if (strcmp(sys_cmd, "opp")==0)
1465    {
1466      if ((h!=NULL) && (h->Typ()==RING_CMD))
1467      {
1468        ring r=(ring)h->Data();
1469        res->data=rOpposite(r);
1470        res->rtyp=RING_CMD;
1471        return FALSE;
1472      }
1473      else
1474      {
1475        WerrorS("`system(\"opp\",<ring>)` expected");
1476        return TRUE;
1477      }
1478    }
1479    else
1480  #endif
1481  /*==================== oppose ==================================*/
1482  #ifdef HAVE_PLURAL
1483    if (strcmp(sys_cmd, "oppose")==0)
1484    {
1485      if ((h!=NULL) && (h->Typ()==RING_CMD)
1486      && (h->next!= NULL))
1487      {
1488        ring Rop = (ring)h->Data();
1489        h   = h->next;
1490        idhdl w;
1491        if ((w=Rop->idroot->get(h->Name(),myynest))!=NULL)
1492        {
1493          poly p = (poly)IDDATA(w);
1494          res->data = pOppose(Rop, p, currRing); // into CurrRing?
1495          res->rtyp = POLY_CMD;
1496          return FALSE;
1497        }
1498      }
1499      else
1500      {
1501        WerrorS("`system(\"oppose\",<ring>,<poly>)` expected");
1502        return TRUE;
1503      }
1504    }
1505    else
1506  #endif
1507  /*==================== walk stuff =================*/
1508  /*==================== walkNextWeight =================*/
1509  #ifdef HAVE_WALK
1510  #ifdef OWNW
1511    if (strcmp(sys_cmd, "walkNextWeight") == 0)
1512    {
1513      const short t[]={3,INTVEC_CMD,INTVEC_CMD,IDEAL_CMD};
1514      if (!iiCheckTypes(h,t,1)) return TRUE;
1515      if (((intvec*) h->Data())->length() != currRing->N ||
1516          ((intvec*) h->next->Data())->length() != currRing->N)
1517      {
1518        Werror("system(\"walkNextWeight\" ...) intvecs not of length %d\n",
1519               currRing->N);
1520        return TRUE;
1521      }
1522      res->data = (void*) walkNextWeight(((intvec*) h->Data()),
1523                                         ((intvec*) h->next->Data()),
1524                                         (ideal) h->next->next->Data());
1525      if (res->data == NULL || res->data == (void*) 1L)
1526      {
1527        res->rtyp = INT_CMD;
1528      }
1529      else
1530      {
1531        res->rtyp = INTVEC_CMD;
1532      }
1533      return FALSE;
1534    }
1535    else
1536  #endif
1537  #endif
1538  /*==================== walkNextWeight =================*/
1539  #ifdef HAVE_WALK
1540  #ifdef OWNW
1541    if (strcmp(sys_cmd, "walkInitials") == 0)
1542    {
1543      if (h == NULL || h->Typ() != IDEAL_CMD)
1544      {
1545        WerrorS("system(\"walkInitials\", ideal) expected");
1546        return TRUE;
1547      }
1548      res->data = (void*) walkInitials((ideal) h->Data());
1549      res->rtyp = IDEAL_CMD;
1550      return FALSE;
1551    }
1552    else
1553  #endif
1554  #endif
1555  /*==================== walkAddIntVec =================*/
1556  #ifdef HAVE_WALK
1557  #ifdef WAIV
1558    if (strcmp(sys_cmd, "walkAddIntVec") == 0)
1559    {
1560      const short t[]={2,INTVEC_CMD,INTVEC_CMD};
1561      if (!iiCheckTypes(h,t,1)) return TRUE;
1562      intvec* arg1 = (intvec*) h->Data();
1563      intvec* arg2 = (intvec*) h->next->Data();
1564      res->data = (intvec*) walkAddIntVec(arg1, arg2);
1565      res->rtyp = INTVEC_CMD;
1566      return FALSE;
1567    }
1568    else
1569  #endif
1570  #endif
1571  /*==================== MwalkNextWeight =================*/
1572  #ifdef HAVE_WALK
1573  #ifdef MwaklNextWeight
1574    if (strcmp(sys_cmd, "MwalkNextWeight") == 0)
1575    {
1576      const short t[]={3,INTVEC_CMD,INTVEC_CMD,IDEAL_CMD};
1577      if (!iiCheckTypes(h,t,1)) return TRUE;
1578      if (((intvec*) h->Data())->length() != currRing->N ||
1579        ((intvec*) h->next->Data())->length() != currRing->N)
1580      {
1581        Werror("system(\"MwalkNextWeight\" ...) intvecs not of length %d\n",
1582               currRing->N);
1583        return TRUE;
1584      }
1585      intvec* arg1 = (intvec*) h->Data();
1586      intvec* arg2 = (intvec*) h->next->Data();
1587      ideal arg3   =   (ideal) h->next->next->Data();
1588      intvec* result = (intvec*) MwalkNextWeight(arg1, arg2, arg3);
1589      res->rtyp = INTVEC_CMD;
1590      res->data =  result;
1591      return FALSE;
1592    }
1593    else
1594  #endif //MWalkNextWeight
1595  #endif
1596  /*==================== Mivdp =================*/
1597  #ifdef HAVE_WALK
1598    if(strcmp(sys_cmd, "Mivdp") == 0)
1599    {
1600      if (h == NULL || h->Typ() != INT_CMD)
1601      {
1602        WerrorS("system(\"Mivdp\", int) expected");
1603        return TRUE;
1604      }
1605      if ((int) ((long)(h->Data())) != currRing->N)
1606      {
1607        Werror("system(\"Mivdp\" ...) intvecs not of length %d\n",
1608               currRing->N);
1609        return TRUE;
1610      }
1611      int arg1 = (int) ((long)(h->Data()));
1612      intvec* result = (intvec*) Mivdp(arg1);
1613      res->rtyp = INTVEC_CMD;
1614      res->data =  result;
1615      return FALSE;
1616    }
1617    else
1618  #endif
1619  /*==================== Mivlp =================*/
1620  #ifdef HAVE_WALK
1621    if(strcmp(sys_cmd, "Mivlp") == 0)
1622    {
1623      if (h == NULL || h->Typ() != INT_CMD)
1624      {
1625        WerrorS("system(\"Mivlp\", int) expected");
1626        return TRUE;
1627      }
1628      if ((int) ((long)(h->Data())) != currRing->N)
1629      {
1630        Werror("system(\"Mivlp\" ...) intvecs not of length %d\n",
1631               currRing->N);
1632        return TRUE;
1633      }
1634      int arg1 = (int) ((long)(h->Data()));
1635      intvec* result = (intvec*) Mivlp(arg1);
1636      res->rtyp = INTVEC_CMD;
1637      res->data =  result;
1638      return FALSE;
1639    }
1640    else
1641  #endif
1642  /*==================== MpDiv =================*/
1643  #ifdef HAVE_WALK
1644  #ifdef MpDiv
1645    if(strcmp(sys_cmd, "MpDiv") == 0)
1646    {
1647      const short t[]={2,POLY_CMD,POLY_CMD};
1648      if (!iiCheckTypes(h,t,1)) return TRUE;
1649      poly arg1 = (poly) h->Data();
1650      poly arg2 = (poly) h->next->Data();
1651      poly result = MpDiv(arg1, arg2);
1652      res->rtyp = POLY_CMD;
1653      res->data = result;
1654      return FALSE;
1655    }
1656    else
1657  #endif
1658  #endif
1659  /*==================== MpMult =================*/
1660  #ifdef HAVE_WALK
1661  #ifdef MpMult
1662    if(strcmp(sys_cmd, "MpMult") == 0)
1663    {
1664      const short t[]={2,POLY_CMD,POLY_CMD};
1665      if (!iiCheckTypes(h,t,1)) return TRUE;
1666      poly arg1 = (poly) h->Data();
1667      poly arg2 = (poly) h->next->Data();
1668      poly result = MpMult(arg1, arg2);
1669      res->rtyp = POLY_CMD;
1670      res->data = result;
1671      return FALSE;
1672    }
1673    else
1674  #endif
1675  #endif
1676  /*==================== MivSame =================*/
1677  #ifdef HAVE_WALK
1678    if (strcmp(sys_cmd, "MivSame") == 0)
1679    {
1680      const short t[]={2,INTVEC_CMD,INTVEC_CMD};
1681      if (!iiCheckTypes(h,t,1)) return TRUE;
1682      /*
1683      if (((intvec*) h->Data())->length() != currRing->N ||
1684      ((intvec*) h->next->Data())->length() != currRing->N)
1685      {
1686        Werror("system(\"MivSame\" ...) intvecs not of length %d\n",
1687               currRing->N);
1688        return TRUE;
1689      }
1690      */
1691      intvec* arg1 = (intvec*) h->Data();
1692      intvec* arg2 = (intvec*) h->next->Data();
1693      /*
1694      poly result = (poly) MivSame(arg1, arg2);
1695      res->rtyp = POLY_CMD;
1696      res->data =  (poly) result;
1697      */
1698      res->rtyp = INT_CMD;
1699      res->data = (void*)(long) MivSame(arg1, arg2);
1700      return FALSE;
1701    }
1702    else
1703  #endif
1704  /*==================== M3ivSame =================*/
1705  #ifdef HAVE_WALK
1706    if (strcmp(sys_cmd, "M3ivSame") == 0)
1707    {
1708      const short t[]={3,INTVEC_CMD,INTVEC_CMD,INTVEC_CMD};
1709      if (!iiCheckTypes(h,t,1)) return TRUE;
1710      /*
1711      if (((intvec*) h->Data())->length() != currRing->N ||
1712        ((intvec*) h->next->Data())->length() != currRing->N ||
1713        ((intvec*) h->next->next->Data())->length() != currRing->N )
1714      {
1715        Werror("system(\"M3ivSame\" ...) intvecs not of length %d\n",
1716              currRing->N);
1717        return TRUE;
1718      }
1719      */
1720      intvec* arg1 = (intvec*) h->Data();
1721      intvec* arg2 = (intvec*) h->next->Data();
1722      intvec* arg3 = (intvec*) h->next->next->Data();
1723      /*
1724      poly result = (poly) M3ivSame(arg1, arg2, arg3);
1725      res->rtyp = POLY_CMD;
1726      res->data =  (poly) result;
1727      */
1728      res->rtyp = INT_CMD;
1729      res->data = (void*)(long) M3ivSame(arg1, arg2, arg3);
1730      return FALSE;
1731    }
1732    else
1733  #endif
1734  /*==================== MwalkInitialForm =================*/
1735  #ifdef HAVE_WALK
1736    if(strcmp(sys_cmd, "MwalkInitialForm") == 0)
1737    {
1738      const short t[]={2,IDEAL_CMD,INTVEC_CMD};
1739      if (!iiCheckTypes(h,t,1)) return TRUE;
1740      if(((intvec*) h->next->Data())->length() != currRing->N)
1741      {
1742        Werror("system \"MwalkInitialForm\"...) intvec not of length %d\n",
1743               currRing->N);
1744        return TRUE;
1745      }
1746      ideal id      = (ideal) h->Data();
1747      intvec* int_w = (intvec*) h->next->Data();
1748      ideal result  = (ideal) MwalkInitialForm(id, int_w);
1749      res->rtyp = IDEAL_CMD;
1750      res->data = result;
1751      return FALSE;
1752    }
1753    else
1754  #endif
1755  /*==================== MivMatrixOrder =================*/
1756  #ifdef HAVE_WALK
1757    /************** Perturbation walk **********/
1758    if(strcmp(sys_cmd, "MivMatrixOrder") == 0)
1759    {
1760      if(h==NULL || h->Typ() != INTVEC_CMD)
1761      {
1762        WerrorS("system(\"MivMatrixOrder\",intvec) expected");
1763        return TRUE;
1764      }
1765      intvec* arg1 = (intvec*) h->Data();
1766      intvec* result = MivMatrixOrder(arg1);
1767      res->rtyp = INTVEC_CMD;
1768      res->data =  result;
1769      return FALSE;
1770    }
1771    else
1772  #endif
1773  /*==================== MivMatrixOrderdp =================*/
1774  #ifdef HAVE_WALK
1775    if(strcmp(sys_cmd, "MivMatrixOrderdp") == 0)
1776    {
1777      if(h==NULL || h->Typ() != INT_CMD)
1778      {
1779        WerrorS("system(\"MivMatrixOrderdp\",intvec) expected");
1780        return TRUE;
1781      }
1782      int arg1 = (int) ((long)(h->Data()));
1783      intvec* result = (intvec*) MivMatrixOrderdp(arg1);
1784      res->rtyp = INTVEC_CMD;
1785      res->data =  result;
1786      return FALSE;
1787    }
1788    else
1789  #endif
1790  /*==================== MPertVectors =================*/
1791  #ifdef HAVE_WALK
1792    if(strcmp(sys_cmd, "MPertVectors") == 0)
1793    {
1794      const short t[]={3,IDEAL_CMD,INTVEC_CMD,INT_CMD};
1795      if (!iiCheckTypes(h,t,1)) return TRUE;
1796      ideal arg1 = (ideal) h->Data();
1797      intvec* arg2 = (intvec*) h->next->Data();
1798      int arg3 = (int) ((long)(h->next->next->Data()));
1799      intvec* result = (intvec*) MPertVectors(arg1, arg2, arg3);
1800      res->rtyp = INTVEC_CMD;
1801      res->data =  result;
1802      return FALSE;
1803    }
1804    else
1805  #endif
1806  /*==================== MPertVectorslp =================*/
1807  #ifdef HAVE_WALK
1808    if(strcmp(sys_cmd, "MPertVectorslp") == 0)
1809    {
1810      const short t[]={3,IDEAL_CMD,INTVEC_CMD,INT_CMD};
1811      if (!iiCheckTypes(h,t,1)) return TRUE;
1812      ideal arg1 = (ideal) h->Data();
1813      intvec* arg2 = (intvec*) h->next->Data();
1814      int arg3 = (int) ((long)(h->next->next->Data()));
1815      intvec* result = (intvec*) MPertVectorslp(arg1, arg2, arg3);
1816      res->rtyp = INTVEC_CMD;
1817      res->data =  result;
1818      return FALSE;
1819    }
1820    else
1821  #endif
1822    /************** fractal walk **********/
1823  #ifdef HAVE_WALK
1824    if(strcmp(sys_cmd, "Mfpertvector") == 0)
1825    {
1826      const short t[]={2,IDEAL_CMD,INTVEC_CMD};
1827      if (!iiCheckTypes(h,t,1)) return TRUE;
1828      ideal arg1 = (ideal) h->Data();
1829      intvec* arg2 = (intvec*) h->next->Data();
1830      intvec* result = Mfpertvector(arg1, arg2);
1831      res->rtyp = INTVEC_CMD;
1832      res->data =  result;
1833      return FALSE;
1834    }
1835    else
1836  #endif
1837  /*==================== MivUnit =================*/
1838  #ifdef HAVE_WALK
1839    if(strcmp(sys_cmd, "MivUnit") == 0)
1840    {
1841      const short t[]={1,INT_CMD};
1842      if (!iiCheckTypes(h,t,1)) return TRUE;
1843      int arg1 = (int) ((long)(h->Data()));
1844      intvec* result = (intvec*) MivUnit(arg1);
1845      res->rtyp = INTVEC_CMD;
1846      res->data =  result;
1847      return FALSE;
1848    }
1849    else
1850  #endif
1851  /*==================== MivWeightOrderlp =================*/
1852  #ifdef HAVE_WALK
1853    if(strcmp(sys_cmd, "MivWeightOrderlp") == 0)
1854    {
1855      const short t[]={1,INTVEC_CMD};
1856      if (!iiCheckTypes(h,t,1)) return TRUE;
1857      intvec* arg1 = (intvec*) h->Data();
1858      intvec* result = MivWeightOrderlp(arg1);
1859      res->rtyp = INTVEC_CMD;
1860      res->data =  result;
1861      return FALSE;
1862    }
1863    else
1864  #endif
1865  /*==================== MivWeightOrderdp =================*/
1866  #ifdef HAVE_WALK
1867    if(strcmp(sys_cmd, "MivWeightOrderdp") == 0)
1868    {
1869      if(h==NULL || h->Typ() != INTVEC_CMD)
1870      {
1871        WerrorS("system(\"MivWeightOrderdp\",intvec) expected");
1872        return TRUE;
1873      }
1874      intvec* arg1 = (intvec*) h->Data();
1875      //int arg2 = (int) h->next->Data();
1876      intvec* result = MivWeightOrderdp(arg1);
1877      res->rtyp = INTVEC_CMD;
1878      res->data =  result;
1879      return FALSE;
1880    }
1881    else
1882  #endif
1883  /*==================== MivMatrixOrderlp =================*/
1884  #ifdef HAVE_WALK
1885    if(strcmp(sys_cmd, "MivMatrixOrderlp") == 0)
1886    {
1887      if(h==NULL || h->Typ() != INT_CMD)
1888      {
1889        WerrorS("system(\"MivMatrixOrderlp\",int) expected");
1890        return TRUE;
1891      }
1892      int arg1 = (int) ((long)(h->Data()));
1893      intvec* result = (intvec*) MivMatrixOrderlp(arg1);
1894      res->rtyp = INTVEC_CMD;
1895      res->data =  result;
1896      return FALSE;
1897    }
1898    else
1899  #endif
1900  /*==================== MkInterRedNextWeight =================*/
1901  #ifdef HAVE_WALK
1902    if (strcmp(sys_cmd, "MkInterRedNextWeight") == 0)
1903    {
1904      const short t[]={3,INTVEC_CMD,INTVEC_CMD,IDEAL_CMD};
1905      if (!iiCheckTypes(h,t,1)) return TRUE;
1906      if (((intvec*) h->Data())->length() != currRing->N ||
1907        ((intvec*) h->next->Data())->length() != currRing->N)
1908      {
1909        Werror("system(\"MkInterRedNextWeight\" ...) intvecs not of length %d\n",
1910                 currRing->N);
1911        return TRUE;
1912      }
1913      intvec* arg1 = (intvec*) h->Data();
1914      intvec* arg2 = (intvec*) h->next->Data();
1915      ideal arg3   =   (ideal) h->next->next->Data();
1916      intvec* result = (intvec*) MkInterRedNextWeight(arg1, arg2, arg3);
1917      res->rtyp = INTVEC_CMD;
1918      res->data =  result;
1919      return FALSE;
1920    }
1921    else
1922  #endif
1923  /*==================== MPertNextWeight =================*/
1924  #ifdef HAVE_WALK
1925  #ifdef MPertNextWeight
1926    if (strcmp(sys_cmd, "MPertNextWeight") == 0)
1927    {
1928      const short t[]={3,INTVEC_CMD,IDEAL_CMD,INT_CMD};
1929      if (!iiCheckTypes(h,t,1)) return TRUE;
1930      if (((intvec*) h->Data())->length() != currRing->N)
1931      {
1932        Werror("system(\"MPertNextWeight\" ...) intvecs not of length %d\n",
1933                 currRing->N);
1934        return TRUE;
1935      }
1936      intvec* arg1 = (intvec*) h->Data();
1937      ideal arg2 = (ideal) h->next->Data();
1938      int arg3   =   (int) h->next->next->Data();
1939      intvec* result = (intvec*) MPertNextWeight(arg1, arg2, arg3);
1940      res->rtyp = INTVEC_CMD;
1941      res->data =  result;
1942      return FALSE;
1943    }
1944    else
1945  #endif //MPertNextWeight
1946  #endif
1947  /*==================== Mivperttarget =================*/
1948  #ifdef HAVE_WALK
1949  #ifdef Mivperttarget
1950    if (strcmp(sys_cmd, "Mivperttarget") == 0)
1951    {
1952      const short t[]={2,IDEAL_CMD,INT_CMD};
1953      if (!iiCheckTypes(h,t,1)) return TRUE;
1954      ideal arg1 = (ideal) h->Data();
1955      int arg2 = (int) h->next->Data();
1956      intvec* result = (intvec*) Mivperttarget(arg1, arg2);
1957      res->rtyp = INTVEC_CMD;
1958      res->data =  result;
1959      return FALSE;
1960    }
1961    else
1962  #endif //Mivperttarget
1963  #endif
1964  /*==================== Mwalk =================*/
1965  #ifdef HAVE_WALK
1966    if (strcmp(sys_cmd, "Mwalk") == 0)
1967    {
1968      const short t[]={6,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,RING_CMD,INT_CMD,INT_CMD};
1969      if (!iiCheckTypes(h,t,1)) return TRUE;
1970      if (((intvec*) h->next->Data())->length() != currRing->N &&
1971        ((intvec*) h->next->next->Data())->length() != currRing->N )
1972      {
1973        Werror("system(\"Mwalk\" ...) intvecs not of length %d\n",
1974           currRing->N);
1975        return TRUE;
1976      }
1977      ideal arg1 = (ideal) h->CopyD();
1978      intvec* arg2 = (intvec*) h->next->Data();
1979      intvec* arg3 = (intvec*) h->next->next->Data();
1980      ring arg4 = (ring) h->next->next->next->Data();
1981      int arg5 = (int) (long) h->next->next->next->next->Data();
1982      int arg6 = (int) (long) h->next->next->next->next->next->Data();
1983      ideal result = (ideal) Mwalk(arg1, arg2, arg3, arg4, arg5, arg6);
1984      res->rtyp = IDEAL_CMD;
1985      res->data =  result;
1986      return FALSE;
1987    }
1988    else
1989  #endif
1990  /*==================== Mpwalk =================*/
1991  #ifdef HAVE_WALK
1992  #ifdef MPWALK_ORIG
1993    if (strcmp(sys_cmd, "Mwalk") == 0)
1994    {
1995      const short t[]={4,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,RING_CMD};
1996      if (!iiCheckTypes(h,t,1)) return TRUE;
1997      if ((((intvec*) h->next->Data())->length() != currRing->N &&
1998          ((intvec*) h->next->next->Data())->length() != currRing->N ) &&
1999          (((intvec*) h->next->Data())->length() != (currRing->N)*(currRing->N) &&
2000          ((intvec*) h->next->next->Data())->length() != (currRing->N)*(currRing->N)))
2001      {
2002        Werror("system(\"Mwalk\" ...) intvecs not of length %d or %d\n",
2003               currRing->N,(currRing->N)*(currRing->N));
2004        return TRUE;
2005      }
2006      ideal arg1 = (ideal) h->Data();
2007      intvec* arg2 = (intvec*) h->next->Data();
2008      intvec* arg3   =  (intvec*) h->next->next->Data();
2009      ring arg4 = (ring) h->next->next->next->Data();
2010      ideal result = (ideal) Mwalk(arg1, arg2, arg3,arg4);
2011      res->rtyp = IDEAL_CMD;
2012      res->data =  result;
2013      return FALSE;
2014    }
2015    else
2016  #else
2017    if (strcmp(sys_cmd, "Mpwalk") == 0)
2018    {
2019      const short t[]={8,IDEAL_CMD,INT_CMD,INT_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD,INT_CMD};
2020      if (!iiCheckTypes(h,t,1)) return TRUE;
2021      if(((intvec*) h->next->next->next->Data())->length() != currRing->N &&
2022         ((intvec*) h->next->next->next->next->Data())->length()!=currRing->N)
2023      {
2024        Werror("system(\"Mpwalk\" ...) intvecs not of length %d\n",currRing->N);
2025        return TRUE;
2026      }
2027      ideal arg1 = (ideal) h->Data();
2028      int arg2 = (int) (long) h->next->Data();
2029      int arg3 = (int) (long) h->next->next->Data();
2030      intvec* arg4 = (intvec*) h->next->next->next->Data();
2031      intvec* arg5 = (intvec*) h->next->next->next->next->Data();
2032      int arg6 = (int) (long) h->next->next->next->next->next->Data();
2033      int arg7 = (int) (long) h->next->next->next->next->next->next->Data();
2034      int arg8 = (int) (long) h->next->next->next->next->next->next->next->Data();
2035      ideal result = (ideal) Mpwalk(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
2036      res->rtyp = IDEAL_CMD;
2037      res->data =  result;
2038      return FALSE;
2039    }
2040    else
2041    #endif
2042  #endif
2043  /*==================== Mrwalk =================*/
2044  #ifdef HAVE_WALK
2045    if (strcmp(sys_cmd, "Mrwalk") == 0)
2046    {
2047      const short t[]={7,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD,INT_CMD,INT_CMD};
2048      if (!iiCheckTypes(h,t,1)) return TRUE;
2049      if(((intvec*) h->next->Data())->length() != currRing->N &&
2050         ((intvec*) h->next->Data())->length() != (currRing->N)*(currRing->N) &&
2051         ((intvec*) h->next->next->Data())->length() != currRing->N &&
2052         ((intvec*) h->next->next->Data())->length() != (currRing->N)*(currRing->N) )
2053      {
2054        Werror("system(\"Mrwalk\" ...) intvecs not of length %d or %d\n",
2055               currRing->N,(currRing->N)*(currRing->N));
2056        return TRUE;
2057      }
2058      ideal arg1 = (ideal) h->Data();
2059      intvec* arg2 = (intvec*) h->next->Data();
2060      intvec* arg3 =  (intvec*) h->next->next->Data();
2061      int arg4 = (int)(long) h->next->next->next->Data();
2062      int arg5 = (int)(long) h->next->next->next->next->Data();
2063      int arg6 = (int)(long) h->next->next->next->next->next->Data();
2064      int arg7 = (int)(long) h->next->next->next->next->next->next->Data();
2065      ideal result = (ideal) Mrwalk(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
2066      res->rtyp = IDEAL_CMD;
2067      res->data =  result;
2068      return FALSE;
2069    }
2070    else
2071  #endif
2072  /*==================== MAltwalk1 =================*/
2073  #ifdef HAVE_WALK
2074    if (strcmp(sys_cmd, "MAltwalk1") == 0)
2075    {
2076      const short t[]={5,IDEAL_CMD,INT_CMD,INT_CMD,INTVEC_CMD,INTVEC_CMD};
2077      if (!iiCheckTypes(h,t,1)) return TRUE;
2078      if (((intvec*) h->next->next->next->Data())->length() != currRing->N &&
2079        ((intvec*) h->next->next->next->next->Data())->length()!=currRing->N)
2080      {
2081        Werror("system(\"MAltwalk1\" ...) intvecs not of length %d\n",
2082                 currRing->N);
2083        return TRUE;
2084      }
2085      ideal arg1 = (ideal) h->Data();
2086      int arg2 = (int) ((long)(h->next->Data()));
2087      int arg3 = (int) ((long)(h->next->next->Data()));
2088      intvec* arg4 = (intvec*) h->next->next->next->Data();
2089      intvec* arg5   =  (intvec*) h->next->next->next->next->Data();
2090      ideal result = (ideal) MAltwalk1(arg1, arg2, arg3, arg4, arg5);
2091      res->rtyp = IDEAL_CMD;
2092      res->data =  result;
2093      return FALSE;
2094    }
2095    else
2096  #endif
2097  /*==================== MAltwalk1 =================*/
2098  #ifdef HAVE_WALK
2099  #ifdef MFWALK_ALT
2100    if (strcmp(sys_cmd, "Mfwalk_alt") == 0)
2101    {
2102      const short t[]={4,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD};
2103      if (!iiCheckTypes(h,t,1)) return TRUE;
2104      if (((intvec*) h->next->Data())->length() != currRing->N &&
2105        ((intvec*) h->next->next->Data())->length() != currRing->N )
2106      {
2107        Werror("system(\"Mfwalk\" ...) intvecs not of length %d\n",
2108              currRing->N);
2109        return TRUE;
2110      }
2111      ideal arg1 = (ideal) h->Data();
2112      intvec* arg2 = (intvec*) h->next->Data();
2113      intvec* arg3   =  (intvec*) h->next->next->Data();
2114      int arg4 = (int) h->next->next->next->Data();
2115      ideal result = (ideal) Mfwalk_alt(arg1, arg2, arg3, arg4);
2116      res->rtyp = IDEAL_CMD;
2117      res->data =  result;
2118      return FALSE;
2119    }
2120    else
2121  #endif
2122  #endif
2123  /*==================== Mfwalk =================*/
2124  #ifdef HAVE_WALK
2125    if (strcmp(sys_cmd, "Mfwalk") == 0)
2126    {
2127      const short t[]={5,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD};
2128      if (!iiCheckTypes(h,t,1)) return TRUE;
2129      if (((intvec*) h->next->Data())->length() != currRing->N &&
2130        ((intvec*) h->next->next->Data())->length() != currRing->N )
2131      {
2132        Werror("system(\"Mfwalk\" ...) intvecs not of length %d\n",
2133                 currRing->N);
2134        return TRUE;
2135      }
2136      ideal arg1 = (ideal) h->Data();
2137      intvec* arg2 = (intvec*) h->next->Data();
2138      intvec* arg3 = (intvec*) h->next->next->Data();
2139      int arg4 = (int)(long) h->next->next->next->Data();
2140      int arg5 = (int)(long) h->next->next->next->next->Data();
2141      ideal result = (ideal) Mfwalk(arg1, arg2, arg3, arg4, arg5);
2142      res->rtyp = IDEAL_CMD;
2143      res->data =  result;
2144      return FALSE;
2145    }
2146    else
2147  #endif
2148  /*==================== Mfrwalk =================*/
2149  #ifdef HAVE_WALK
2150    if (strcmp(sys_cmd, "Mfrwalk") == 0)
2151    {
2152      const short t[]={6,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD,INT_CMD};
2153      if (!iiCheckTypes(h,t,1)) return TRUE;
2154/*
2155      if (((intvec*) h->next->Data())->length() != currRing->N &&
2156          ((intvec*) h->next->next->Data())->length() != currRing->N)
2157      {
2158        Werror("system(\"Mfrwalk\" ...) intvecs not of length %d\n",currRing->N);
2159        return TRUE;
2160      }
2161*/
2162      if((((intvec*) h->next->Data())->length() != currRing->N &&
2163         ((intvec*) h->next->next->Data())->length() != currRing->N ) &&
2164         (((intvec*) h->next->Data())->length() != (currRing->N)*(currRing->N) &&
2165         ((intvec*) h->next->next->Data())->length() != (currRing->N)*(currRing->N) ))
2166      {
2167        Werror("system(\"Mfrwalk\" ...) intvecs not of length %d or %d\n",
2168               currRing->N,(currRing->N)*(currRing->N));
2169        return TRUE;
2170      }
2171
2172      ideal arg1 = (ideal) h->Data();
2173      intvec* arg2 = (intvec*) h->next->Data();
2174      intvec* arg3 = (intvec*) h->next->next->Data();
2175      int arg4 = (int)(long) h->next->next->next->Data();
2176      int arg5 = (int)(long) h->next->next->next->next->Data();
2177      int arg6 = (int)(long) h->next->next->next->next->next->Data();
2178      ideal result = (ideal) Mfrwalk(arg1, arg2, arg3, arg4, arg5, arg6);
2179      res->rtyp = IDEAL_CMD;
2180      res->data =  result;
2181      return FALSE;
2182    }
2183    else
2184  /*==================== Mprwalk =================*/
2185    if (strcmp(sys_cmd, "Mprwalk") == 0)
2186    {
2187      const short t[]={9,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD,INT_CMD,INT_CMD,INT_CMD,INT_CMD};
2188      if (!iiCheckTypes(h,t,1)) return TRUE;
2189      if((((intvec*) h->next->Data())->length() != currRing->N &&
2190         ((intvec*) h->next->next->Data())->length() != currRing->N ) &&
2191         (((intvec*) h->next->Data())->length() != (currRing->N)*(currRing->N) &&
2192         ((intvec*) h->next->next->Data())->length() != (currRing->N)*(currRing->N) ))
2193      {
2194        Werror("system(\"Mrwalk\" ...) intvecs not of length %d or %d\n",
2195               currRing->N,(currRing->N)*(currRing->N));
2196        return TRUE;
2197      }
2198      ideal arg1 = (ideal) h->Data();
2199      intvec* arg2 = (intvec*) h->next->Data();
2200      intvec* arg3 =  (intvec*) h->next->next->Data();
2201      int arg4 = (int)(long) h->next->next->next->Data();
2202      int arg5 = (int)(long) h->next->next->next->next->Data();
2203      int arg6 = (int)(long) h->next->next->next->next->next->Data();
2204      int arg7 = (int)(long) h->next->next->next->next->next->next->Data();
2205      int arg8 = (int)(long) h->next->next->next->next->next->next->next->Data();
2206      int arg9 = (int)(long) h->next->next->next->next->next->next->next->next->Data();
2207      ideal result = (ideal) Mprwalk(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
2208      res->rtyp = IDEAL_CMD;
2209      res->data =  result;
2210      return FALSE;
2211    }
2212    else
2213  #endif
2214  /*==================== TranMImprovwalk =================*/
2215  #ifdef HAVE_WALK
2216  #ifdef TRAN_Orig
2217    if (strcmp(sys_cmd, "TranMImprovwalk") == 0)
2218    {
2219      const short t[]={3,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD};
2220      if (!iiCheckTypes(h,t,1)) return TRUE;
2221      if (((intvec*) h->next->Data())->length() != currRing->N &&
2222        ((intvec*) h->next->next->Data())->length() != currRing->N )
2223      {
2224        Werror("system(\"TranMImprovwalk\" ...) intvecs not of length %d\n",
2225              currRing->N);
2226        return TRUE;
2227      }
2228      ideal arg1 = (ideal) h->Data();
2229      intvec* arg2 = (intvec*) h->next->Data();
2230      intvec* arg3   =  (intvec*) h->next->next->Data();
2231      ideal result = (ideal) TranMImprovwalk(arg1, arg2, arg3);
2232      res->rtyp = IDEAL_CMD;
2233      res->data =  result;
2234      return FALSE;
2235    }
2236    else
2237  #endif
2238  #endif
2239  /*==================== MAltwalk2 =================*/
2240  #ifdef HAVE_WALK
2241    if (strcmp(sys_cmd, "MAltwalk2") == 0)
2242    {
2243      const short t[]={3,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD};
2244      if (!iiCheckTypes(h,t,1)) return TRUE;
2245      if (((intvec*) h->next->Data())->length() != currRing->N &&
2246        ((intvec*) h->next->next->Data())->length() != currRing->N )
2247      {
2248        Werror("system(\"MAltwalk2\" ...) intvecs not of length %d\n",
2249                 currRing->N);
2250        return TRUE;
2251      }
2252      ideal arg1 = (ideal) h->Data();
2253      intvec* arg2 = (intvec*) h->next->Data();
2254      intvec* arg3   =  (intvec*) h->next->next->Data();
2255      ideal result = (ideal) MAltwalk2(arg1, arg2, arg3);
2256      res->rtyp = IDEAL_CMD;
2257      res->data =  result;
2258      return FALSE;
2259    }
2260    else
2261  #endif
2262  /*==================== MAltwalk2 =================*/
2263  #ifdef HAVE_WALK
2264    if (strcmp(sys_cmd, "TranMImprovwalk") == 0)
2265    {
2266      const short t[]={4,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD};
2267      if (!iiCheckTypes(h,t,1)) return TRUE;
2268      if (((intvec*) h->next->Data())->length() != currRing->N &&
2269        ((intvec*) h->next->next->Data())->length() != currRing->N )
2270      {
2271        Werror("system(\"TranMImprovwalk\" ...) intvecs not of length %d\n",
2272                 currRing->N);
2273        return TRUE;
2274      }
2275      ideal arg1 = (ideal) h->Data();
2276      intvec* arg2 = (intvec*) h->next->Data();
2277      intvec* arg3   =  (intvec*) h->next->next->Data();
2278      int arg4   =  (int) ((long)(h->next->next->next->Data()));
2279      ideal result = (ideal) TranMImprovwalk(arg1, arg2, arg3, arg4);
2280      res->rtyp = IDEAL_CMD;
2281      res->data =  result;
2282      return FALSE;
2283    }
2284    else
2285  #endif
2286  /*==================== TranMrImprovwalk =================*/
2287  #if 0
2288  #ifdef HAVE_WALK
2289    if (strcmp(sys_cmd, "TranMrImprovwalk") == 0)
2290    {
2291      if (h == NULL || h->Typ() != IDEAL_CMD ||
2292        h->next == NULL || h->next->Typ() != INTVEC_CMD ||
2293        h->next->next == NULL || h->next->next->Typ() != INTVEC_CMD ||
2294        h->next->next->next == NULL || h->next->next->next->Typ() != INT_CMD ||
2295        h->next->next->next == NULL || h->next->next->next->next->Typ() != INT_CMD ||
2296        h->next->next->next == NULL || h->next->next->next->next->next->Typ() != INT_CMD)
2297      {
2298        WerrorS("system(\"TranMrImprovwalk\", ideal, intvec, intvec) expected");
2299        return TRUE;
2300      }
2301      if (((intvec*) h->next->Data())->length() != currRing->N &&
2302        ((intvec*) h->next->next->Data())->length() != currRing->N )
2303      {
2304        Werror("system(\"TranMrImprovwalk\" ...) intvecs not of length %d\n", currRing->N);
2305        return TRUE;
2306      }
2307      ideal arg1 = (ideal) h->Data();
2308      intvec* arg2 = (intvec*) h->next->Data();
2309      intvec* arg3 = (intvec*) h->next->next->Data();
2310      int arg4 = (int)(long) h->next->next->next->Data();
2311      int arg5 = (int)(long) h->next->next->next->next->Data();
2312      int arg6 = (int)(long) h->next->next->next->next->next->Data();
2313      ideal result = (ideal) TranMrImprovwalk(arg1, arg2, arg3, arg4, arg5, arg6);
2314      res->rtyp = IDEAL_CMD;
2315      res->data =  result;
2316      return FALSE;
2317    }
2318    else
2319  #endif
2320  #endif
2321  /*================= Extended system call ========================*/
2322    {
2323       #ifndef MAKE_DISTRIBUTION
2324       return(jjEXTENDED_SYSTEM(res, args));
2325       #else
2326       Werror( "system(\"%s\",...) %s", sys_cmd, feNotImplemented );
2327       #endif
2328    }
2329  } /* typ==string */
2330  return TRUE;
2331}
2332
2333
2334#ifdef HAVE_EXTENDED_SYSTEM
2335  // You can put your own system calls here
2336#  include "kernel/fglm/fglm.h"
2337#  ifdef HAVE_NEWTON
2338#    include "hc_newton.h"
2339#  endif
2340
2341static BOOLEAN jjEXTENDED_SYSTEM(leftv res, leftv h)
2342{
2343    if(h->Typ() == STRING_CMD)
2344    {
2345      char *sys_cmd=(char *)(h->Data());
2346      h=h->next;
2347  /*==================== test syz strat =================*/
2348      if (strcmp(sys_cmd, "syz") == 0)
2349      {
2350         if ((h!=NULL) && (h->Typ()==STRING_CMD))
2351         {
2352           const char *s=(const char *)h->Data();
2353           if (strcmp(s,"posInT_EcartFDegpLength")==0)
2354             test_PosInT=posInT_EcartFDegpLength;
2355           else if (strcmp(s,"posInT_FDegpLength")==0)
2356             test_PosInT=posInT_FDegpLength;
2357           else if (strcmp(s,"posInT_pLength")==0)
2358             test_PosInT=posInT_pLength;
2359           else if (strcmp(s,"posInT0")==0)
2360             test_PosInT=posInT0;
2361           else if (strcmp(s,"posInT1")==0)
2362             test_PosInT=posInT1;
2363           else if (strcmp(s,"posInT2")==0)
2364             test_PosInT=posInT2;
2365           else if (strcmp(s,"posInT11")==0)
2366             test_PosInT=posInT11;
2367           else if (strcmp(s,"posInT110")==0)
2368             test_PosInT=posInT110;
2369           else if (strcmp(s,"posInT13")==0)
2370             test_PosInT=posInT13;
2371           else if (strcmp(s,"posInT15")==0)
2372             test_PosInT=posInT15;
2373           else if (strcmp(s,"posInT17")==0)
2374             test_PosInT=posInT17;
2375           else if (strcmp(s,"posInT17_c")==0)
2376             test_PosInT=posInT17_c;
2377           else if (strcmp(s,"posInT19")==0)
2378             test_PosInT=posInT19;
2379           else PrintS("valid posInT:0,1,2,11,110,13,15,17,17_c,19,_EcartFDegpLength,_FDegpLength,_pLength,_EcartpLength\n");
2380         }
2381         else
2382         {
2383           test_PosInT=NULL;
2384           test_PosInL=NULL;
2385         }
2386         si_opt_2|=Sy_bit(23);
2387         return FALSE;
2388      }
2389      else
2390  /*==================== locNF ======================================*/
2391      if(strcmp(sys_cmd,"locNF")==0)
2392      {
2393        const short t[]={4,VECTOR_CMD,MODUL_CMD,INT_CMD,INTVEC_CMD};
2394        if (iiCheckTypes(h,t,1))
2395        {
2396          poly f=(poly)h->Data();
2397          h=h->next;
2398          ideal m=(ideal)h->Data();
2399          assumeStdFlag(h);
2400          h=h->next;
2401          int n=(int)((long)h->Data());
2402          h=h->next;
2403          intvec *v=(intvec *)h->Data();
2404
2405          /* == now the work starts == */
2406
2407          int * iv=iv2array(v, currRing);
2408          poly r=0;
2409          poly hp=ppJetW(f,n,iv);
2410          int s=MATCOLS(m);
2411          int j=0;
2412          matrix T=mp_InitI(s,1,0, currRing);
2413
2414          while (hp != NULL)
2415          {
2416            if (pDivisibleBy(m->m[j],hp))
2417            {
2418              if (MATELEM(T,j+1,1)==0)
2419              {
2420                MATELEM(T,j+1,1)=pDivideM(pHead(hp),pHead(m->m[j]));
2421              }
2422              else
2423              {
2424                pAdd(MATELEM(T,j+1,1),pDivideM(pHead(hp),pHead(m->m[j])));
2425              }
2426              hp=ppJetW(ksOldSpolyRed(m->m[j],hp,0),n,iv);
2427              j=0;
2428            }
2429            else
2430            {
2431              if (j==s-1)
2432              {
2433                r=pAdd(r,pHead(hp));
2434                hp=pLmDeleteAndNext(hp); /* hp=pSub(hp,pHead(hp));*/
2435                j=0;
2436              }
2437              else
2438              {
2439                j++;
2440              }
2441            }
2442          }
2443
2444          matrix Temp=mp_Transp((matrix) id_Vec2Ideal(r, currRing), currRing);
2445          matrix R=mpNew(MATCOLS((matrix) id_Vec2Ideal(f, currRing)),1);
2446          for (int k=1;k<=MATROWS(Temp);k++)
2447          {
2448            MATELEM(R,k,1)=MATELEM(Temp,k,1);
2449          }
2450
2451          lists L=(lists)omAllocBin(slists_bin);
2452          L->Init(2);
2453          L->m[0].rtyp=MATRIX_CMD;   L->m[0].data=(void *)R;
2454          L->m[1].rtyp=MATRIX_CMD;   L->m[1].data=(void *)T;
2455          res->data=L;
2456          res->rtyp=LIST_CMD;
2457          // iv aufraeumen
2458          omFree(iv);
2459          return FALSE;
2460        }
2461        else
2462          return TRUE;
2463      }
2464      else
2465  /*==================== poly debug ==================================*/
2466        if(strcmp(sys_cmd,"p")==0)
2467        {
2468#  ifdef RDEBUG
2469          p_DebugPrint((poly)h->Data(), currRing);
2470#  else
2471          WarnS("Sorry: not available for release build!");
2472#  endif
2473          return FALSE;
2474        }
2475        else
2476  /*==================== setsyzcomp ==================================*/
2477      if(strcmp(sys_cmd,"setsyzcomp")==0)
2478      {
2479        if ((h!=NULL) && (h->Typ()==INT_CMD))
2480        {
2481          int k = (int)(long)h->Data();
2482          if ( currRing->order[0] == ringorder_s )
2483          {
2484            rSetSyzComp(k, currRing);
2485          }
2486        }
2487      }
2488  /*==================== ring debug ==================================*/
2489        if(strcmp(sys_cmd,"r")==0)
2490        {
2491#  ifdef RDEBUG
2492          rDebugPrint((ring)h->Data());
2493#  else
2494          WarnS("Sorry: not available for release build!");
2495#  endif
2496          return FALSE;
2497        }
2498        else
2499  /*==================== changeRing ========================*/
2500        /* The following code changes the names of the variables in the
2501           current ring to "x1", "x2", ..., "xN", where N is the number
2502           of variables in the current ring.
2503           The purpose of this rewriting is to eliminate indexed variables,
2504           as they may cause problems when generating scripts for Magma,
2505           Maple, or Macaulay2. */
2506        if(strcmp(sys_cmd,"changeRing")==0)
2507        {
2508          int varN = currRing->N;
2509          char h[10];
2510          for (int i = 1; i <= varN; i++)
2511          {
2512            omFree(currRing->names[i - 1]);
2513            sprintf(h, "x%d", i);
2514            currRing->names[i - 1] = omStrDup(h);
2515          }
2516          rComplete(currRing);
2517          res->rtyp = INT_CMD;
2518          res->data = (void*)0L;
2519          return FALSE;
2520        }
2521        else
2522  /*==================== mtrack ==================================*/
2523      if(strcmp(sys_cmd,"mtrack")==0)
2524      {
2525  #ifdef OM_TRACK
2526        om_Opts.MarkAsStatic = 1;
2527        FILE *fd = NULL;
2528        int max = 5;
2529        while (h != NULL)
2530        {
2531          omMarkAsStaticAddr(h);
2532          if (fd == NULL && h->Typ()==STRING_CMD)
2533          {
2534            char *fn=(char*) h->Data();
2535            fd = fopen(fn, "w");
2536            if (fd == NULL)
2537              Warn("Can not open %s for writing og mtrack. Using stdout",fn);
2538          }
2539          else if (h->Typ() == INT_CMD)
2540          {
2541            max = (int)(long)h->Data();
2542          }
2543          h = h->Next();
2544        }
2545        omPrintUsedTrackAddrs((fd == NULL ? stdout : fd), max);
2546        if (fd != NULL) fclose(fd);
2547        om_Opts.MarkAsStatic = 0;
2548        return FALSE;
2549  #else
2550        WerrorS("system(\"mtrack\",..) is not implemented in this version");
2551        return TRUE;
2552  #endif
2553      }
2554      else
2555  /*==================== backtrace ==================================*/
2556  #ifndef OM_NDEBUG
2557      if(strcmp(sys_cmd,"backtrace")==0)
2558      {
2559        omPrintCurrentBackTrace(stdout);
2560        return FALSE;
2561      }
2562      else
2563  #endif
2564
2565#if !defined(OM_NDEBUG)
2566  /*==================== omMemoryTest ==================================*/
2567      if (strcmp(sys_cmd,"omMemoryTest")==0)
2568      {
2569
2570#ifdef OM_STATS_H
2571        PrintS("\n[om_Info]: \n");
2572        omUpdateInfo();
2573#define OM_PRINT(name) Print(" %-22s : %10ld \n", #name, om_Info . name)
2574        OM_PRINT(MaxBytesSystem);
2575        OM_PRINT(CurrentBytesSystem);
2576        OM_PRINT(MaxBytesSbrk);
2577        OM_PRINT(CurrentBytesSbrk);
2578        OM_PRINT(MaxBytesMmap);
2579        OM_PRINT(CurrentBytesMmap);
2580        OM_PRINT(UsedBytes);
2581        OM_PRINT(AvailBytes);
2582        OM_PRINT(UsedBytesMalloc);
2583        OM_PRINT(AvailBytesMalloc);
2584        OM_PRINT(MaxBytesFromMalloc);
2585        OM_PRINT(CurrentBytesFromMalloc);
2586        OM_PRINT(MaxBytesFromValloc);
2587        OM_PRINT(CurrentBytesFromValloc);
2588        OM_PRINT(UsedBytesFromValloc);
2589        OM_PRINT(AvailBytesFromValloc);
2590        OM_PRINT(MaxPages);
2591        OM_PRINT(UsedPages);
2592        OM_PRINT(AvailPages);
2593        OM_PRINT(MaxRegionsAlloc);
2594        OM_PRINT(CurrentRegionsAlloc);
2595#undef OM_PRINT
2596#endif
2597
2598#ifdef OM_OPTS_H
2599        PrintS("\n[om_Opts]: \n");
2600#define OM_PRINT(format, name) Print(" %-22s : %10" format"\n", #name, om_Opts . name)
2601        OM_PRINT("d", MinTrack);
2602        OM_PRINT("d", MinCheck);
2603        OM_PRINT("d", MaxTrack);
2604        OM_PRINT("d", MaxCheck);
2605        OM_PRINT("d", Keep);
2606        OM_PRINT("d", HowToReportErrors);
2607        OM_PRINT("d", MarkAsStatic);
2608        OM_PRINT("u", PagesPerRegion);
2609        OM_PRINT("p", OutOfMemoryFunc);
2610        OM_PRINT("p", MemoryLowFunc);
2611        OM_PRINT("p", ErrorHook);
2612#undef OM_PRINT
2613#endif
2614
2615#ifdef OM_ERROR_H
2616        Print("\n\n[om_ErrorStatus]        : '%s' (%s)\n",
2617                omError2String(om_ErrorStatus),
2618                omError2Serror(om_ErrorStatus));
2619        Print("[om_InternalErrorStatus]: '%s' (%s)\n",
2620                omError2String(om_InternalErrorStatus),
2621                omError2Serror(om_InternalErrorStatus));
2622
2623#endif
2624
2625//        omTestMemory(1);
2626//        omtTestErrors();
2627        return FALSE;
2628      }
2629      else
2630#endif
2631  /*==================== pDivStat =============================*/
2632  #if defined(PDEBUG) || defined(PDIV_DEBUG)
2633      if(strcmp(sys_cmd,"pDivStat")==0)
2634      {
2635        extern void pPrintDivisbleByStat();
2636        pPrintDivisbleByStat();
2637        return FALSE;
2638      }
2639      else
2640  #endif
2641  /*==================== red =============================*/
2642  #if 0
2643      if(strcmp(sys_cmd,"red")==0)
2644      {
2645        if ((h!=NULL) &&(h->Typ()==IDEAL_CMD))
2646        {
2647          res->rtyp=IDEAL_CMD;
2648          res->data=(void *)kStdred((ideal)h->Data(),NULL,testHomog,NULL);
2649          setFlag(res,FLAG_STD);
2650          return FALSE;
2651        }
2652        else
2653          WerrorS("ideal expected");
2654      }
2655      else
2656  #endif
2657  /*==================== fastcomb =============================*/
2658      if(strcmp(sys_cmd,"fastcomb")==0)
2659      {
2660        if ((h!=NULL) &&(h->Typ()==IDEAL_CMD))
2661        {
2662          if (h->next!=NULL)
2663          {
2664            if (h->next->Typ()!=POLY_CMD)
2665            {
2666              WarnS("Wrong types for poly= comb(ideal,poly)");
2667            }
2668          }
2669          res->rtyp=POLY_CMD;
2670          res->data=(void *) fglmLinearCombination(
2671                             (ideal)h->Data(),(poly)h->next->Data());
2672          return FALSE;
2673        }
2674        else
2675          WerrorS("ideal expected");
2676      }
2677      else
2678  /*==================== comb =============================*/
2679      if(strcmp(sys_cmd,"comb")==0)
2680      {
2681        if ((h!=NULL) &&(h->Typ()==IDEAL_CMD))
2682        {
2683          if (h->next!=NULL)
2684          {
2685            if (h->next->Typ()!=POLY_CMD)
2686            {
2687                WarnS("Wrong types for poly= comb(ideal,poly)");
2688            }
2689          }
2690          res->rtyp=POLY_CMD;
2691          res->data=(void *)fglmNewLinearCombination(
2692                              (ideal)h->Data(),(poly)h->next->Data());
2693          return FALSE;
2694        }
2695        else
2696          WerrorS("ideal expected");
2697      }
2698      else
2699  #if 0 /* debug only */
2700  /*==================== listall ===================================*/
2701      if(strcmp(sys_cmd,"listall")==0)
2702      {
2703        void listall(int showproc);
2704        int showproc=0;
2705        if ((h!=NULL) && (h->Typ()==INT_CMD)) showproc=(int)((long)h->Data());
2706        listall(showproc);
2707        return FALSE;
2708      }
2709      else
2710  #endif
2711  #if 0 /* debug only */
2712  /*==================== proclist =================================*/
2713      if(strcmp(sys_cmd,"proclist")==0)
2714      {
2715        void piShowProcList();
2716        piShowProcList();
2717        return FALSE;
2718      }
2719      else
2720  #endif
2721  /* ==================== newton ================================*/
2722  #ifdef HAVE_NEWTON
2723      if(strcmp(sys_cmd,"newton")==0)
2724      {
2725        if ((h->Typ()!=POLY_CMD)
2726        || (h->next->Typ()!=INT_CMD)
2727        || (h->next->next->Typ()!=INT_CMD))
2728        {
2729          WerrorS("system(\"newton\",<poly>,<int>,<int>) expected");
2730          return TRUE;
2731        }
2732        poly  p=(poly)(h->Data());
2733        int l=pLength(p);
2734        short *points=(short *)omAlloc(currRing->N*l*sizeof(short));
2735        int i,j,k;
2736        k=0;
2737        poly pp=p;
2738        for (i=0;pp!=NULL;i++)
2739        {
2740          for(j=1;j<=currRing->N;j++)
2741          {
2742            points[k]=pGetExp(pp,j);
2743            k++;
2744          }
2745          pIter(pp);
2746        }
2747        hc_ERG r=hc_KOENIG(currRing->N,      // dimension
2748                  l,      // number of points
2749                  (short*) points,   // points: x_1, y_1,z_1, x_2,y_2,z2,...
2750                  currRing->OrdSgn==-1,
2751                  (int) (h->next->Data()),      // 1: Milnor, 0: Newton
2752                  (int) (h->next->next->Data()) // debug
2753                 );
2754        //----<>---Output-----------------------
2755
2756
2757  //  PrintS("Bin jetzt in extra.cc bei der Auswertung.\n"); // **********
2758
2759
2760        lists L=(lists)omAllocBin(slists_bin);
2761        L->Init(6);
2762        L->m[0].rtyp=STRING_CMD;               // newtonnumber;
2763        L->m[0].data=(void *)omStrDup(r.nZahl);
2764        L->m[1].rtyp=INT_CMD;
2765        L->m[1].data=(void *)(long)r.achse;          // flag for unoccupied axes
2766        L->m[2].rtyp=INT_CMD;
2767        L->m[2].data=(void *)(long)r.deg;            // #degenerations
2768        if ( r.deg != 0)              // only if degenerations exist
2769        {
2770          L->m[3].rtyp=INT_CMD;
2771          L->m[3].data=(void *)(long)r.anz_punkte;     // #points
2772          //---<>--number of points------
2773          int anz = r.anz_punkte;    // number of points
2774          int dim = (currRing->N);     // dimension
2775          intvec* v = new intvec( anz*dim );
2776          for (i=0; i<anz*dim; i++)    // copy points
2777            (*v)[i] = r.pu[i];
2778          L->m[4].rtyp=INTVEC_CMD;
2779          L->m[4].data=(void *)v;
2780          //---<>--degenerations---------
2781          int deg = r.deg;    // number of points
2782          intvec* w = new intvec( r.speicher );  // necessary memory
2783          i=0;               // start copying
2784          do
2785          {
2786            (*w)[i] = r.deg_tab[i];
2787            i++;
2788          }
2789          while (r.deg_tab[i-1] != -2);   // mark for end of list
2790          L->m[5].rtyp=INTVEC_CMD;
2791          L->m[5].data=(void *)w;
2792        }
2793        else
2794        {
2795          L->m[3].rtyp=INT_CMD; L->m[3].data=(char *)0;
2796          L->m[4].rtyp=DEF_CMD;
2797          L->m[5].rtyp=DEF_CMD;
2798        }
2799
2800        res->data=(void *)L;
2801        res->rtyp=LIST_CMD;
2802        // free all pointer in r:
2803        delete[] r.nZahl;
2804        delete[] r.pu;
2805        delete[] r.deg_tab;      // Ist das ein Problem??
2806
2807        omFreeSize((ADDRESS)points,currRing->N*l*sizeof(short));
2808        return FALSE;
2809      }
2810      else
2811  #endif
2812  /*==== connection to Sebastian Jambor's code ======*/
2813  /* This code connects Sebastian Jambor's code for
2814     computing the minimal polynomial of an (n x n) matrix
2815     with entries in F_p to SINGULAR. Two conversion methods
2816     are needed; see further up in this file:
2817        (1) conversion of a matrix with long entries to
2818            a SINGULAR matrix with number entries, where
2819            the numbers are coefficients in currRing;
2820        (2) conversion of an array of longs (encoding the
2821            coefficients of the minimal polynomial) to a
2822            SINGULAR poly living in currRing. */
2823      if (strcmp(sys_cmd, "minpoly") == 0)
2824      {
2825        if ((h == NULL) || (h->Typ() != MATRIX_CMD) || h->next != NULL)
2826        {
2827          Werror("expected exactly one argument: %s",
2828                 "a square matrix with number entries");
2829          return TRUE;
2830        }
2831        else
2832        {
2833          matrix m = (matrix)h->Data();
2834          int n = m->rows();
2835          unsigned long p = (unsigned long)n_GetChar(currRing->cf);
2836          if (n != m->cols())
2837          {
2838            WerrorS("expected exactly one argument: "
2839                   "a square matrix with number entries");
2840            return TRUE;
2841          }
2842          unsigned long** ml = singularMatrixToLongMatrix(m);
2843          unsigned long* polyCoeffs = computeMinimalPolynomial(ml, n, p);
2844          poly theMinPoly = longCoeffsToSingularPoly(polyCoeffs, n);
2845          res->rtyp = POLY_CMD;
2846          res->data = (void *)theMinPoly;
2847          for (int i = 0; i < n; i++) delete[] ml[i];
2848          delete[] ml;
2849          delete[] polyCoeffs;
2850          return FALSE;
2851        }
2852      }
2853      else
2854  /*==================== sdb_flags =================*/
2855  #ifdef HAVE_SDB
2856      if (strcmp(sys_cmd, "sdb_flags") == 0)
2857      {
2858        if ((h!=NULL) && (h->Typ()==INT_CMD))
2859        {
2860          sdb_flags=(int)((long)h->Data());
2861        }
2862        else
2863        {
2864          WerrorS("system(\"sdb_flags\",`int`) expected");
2865          return TRUE;
2866        }
2867        return FALSE;
2868      }
2869      else
2870  #endif
2871  /*==================== sdb_edit =================*/
2872  #ifdef HAVE_SDB
2873      if (strcmp(sys_cmd, "sdb_edit") == 0)
2874      {
2875        if ((h!=NULL) && (h->Typ()==PROC_CMD))
2876        {
2877          procinfov p=(procinfov)h->Data();
2878          sdb_edit(p);
2879        }
2880        else
2881        {
2882          WerrorS("system(\"sdb_edit\",`proc`) expected");
2883          return TRUE;
2884        }
2885        return FALSE;
2886      }
2887      else
2888  #endif
2889  /*==================== GF =================*/
2890  #if 0 // for testing only
2891      if (strcmp(sys_cmd, "GF") == 0)
2892      {
2893        if ((h!=NULL) && (h->Typ()==POLY_CMD))
2894        {
2895          int c=rChar(currRing);
2896          setCharacteristic( c,nfMinPoly[0], currRing->parameter[0][0] );
2897          CanonicalForm F( convSingGFFactoryGF( (poly)h->Data(), currRing ) );
2898          res->rtyp=POLY_CMD;
2899          res->data=convFactoryGFSingGF( F, currRing );
2900          return FALSE;
2901        }
2902        else { WerrorS("wrong typ"); return TRUE;}
2903      }
2904      else
2905  #endif
2906  /*==================== SVD =================*/
2907  #ifdef HAVE_SVD
2908       if (strcmp(sys_cmd, "svd") == 0)
2909       {
2910            extern lists testsvd(matrix M);
2911              res->rtyp=LIST_CMD;
2912            res->data=(char*)(testsvd((matrix)h->Data()));
2913            return FALSE;
2914       }
2915       else
2916  #endif
2917  /*==================== redNF_ring =================*/
2918  #ifdef HAVE_RINGS
2919      if (strcmp(sys_cmd, "redNF_ring")==0)
2920      {
2921        ring r = currRing;
2922        poly f = (poly) h->Data();
2923        h = h->next;
2924        ideal G = (ideal) h->Data();
2925        res->rtyp=POLY_CMD;
2926        res->data=(poly) ringRedNF(f, G, r);
2927        return(FALSE);
2928      }
2929      else
2930  #endif
2931  /*==================== Roune Hilb  =================*/
2932       if (strcmp(sys_cmd, "hilbroune") == 0)
2933       {
2934         if ((h!=NULL) && (h->Typ()==IDEAL_CMD))
2935         {
2936           slicehilb((ideal)h->Data());
2937         }
2938         else return TRUE;
2939         return FALSE;
2940       }
2941      else
2942  /*==================== F5 Implementation =================*/
2943  #ifdef HAVE_F5
2944      if (strcmp(sys_cmd, "f5")==0)
2945      {
2946        if (h->Typ()!=IDEAL_CMD)
2947        {
2948          WerrorS("ideal expected");
2949          return TRUE;
2950        }
2951
2952        ring r = currRing;
2953        ideal G = (ideal) h->Data();
2954        h = h->next;
2955        int opt;
2956        if(h != NULL) {
2957          opt = (int) (long) h->Data();
2958        }
2959        else {
2960          opt = 2;
2961        }
2962        h = h->next;
2963        int plus;
2964        if(h != NULL) {
2965          plus = (int) (long) h->Data();
2966        }
2967        else {
2968          plus = 0;
2969        }
2970        h = h->next;
2971        int termination;
2972        if(h != NULL) {
2973          termination = (int) (long) h->Data();
2974        }
2975        else {
2976          termination = 0;
2977        }
2978        res->rtyp=IDEAL_CMD;
2979        res->data=(ideal) F5main(G,r,opt,plus,termination);
2980        return FALSE;
2981      }
2982      else
2983  #endif
2984  /*==================== Testing groebner basis =================*/
2985  #ifdef HAVE_RINGS
2986      if (strcmp(sys_cmd, "NF_ring")==0)
2987      {
2988        ring r = currRing;
2989        poly f = (poly) h->Data();
2990        h = h->next;
2991        ideal G = (ideal) h->Data();
2992        res->rtyp=POLY_CMD;
2993        res->data=(poly) ringNF(f, G, r);
2994        return(FALSE);
2995      }
2996      else
2997      if (strcmp(sys_cmd, "spoly")==0)
2998      {
2999        poly f = pCopy((poly) h->Data());
3000        h = h->next;
3001        poly g = pCopy((poly) h->Data());
3002
3003        res->rtyp=POLY_CMD;
3004        res->data=(poly) plain_spoly(f,g);
3005        return(FALSE);
3006      }
3007      else
3008      if (strcmp(sys_cmd, "testGB")==0)
3009      {
3010        ideal I = (ideal) h->Data();
3011        h = h->next;
3012        ideal GI = (ideal) h->Data();
3013        res->rtyp = INT_CMD;
3014        res->data = (void *)(long) testGB(I, GI);
3015        return(FALSE);
3016      }
3017      else
3018  #endif
3019    /*==================== sca:AltVar ==================================*/
3020  #ifdef HAVE_PLURAL
3021      if ( (strcmp(sys_cmd, "AltVarStart") == 0) || (strcmp(sys_cmd, "AltVarEnd") == 0) )
3022      {
3023        ring r = currRing;
3024
3025        if((h!=NULL) && (h->Typ()==RING_CMD)) r = (ring)h->Data(); else
3026        {
3027          WerrorS("`system(\"AltVarStart/End\"[,<ring>])` expected");
3028          return TRUE;
3029        }
3030
3031        res->rtyp=INT_CMD;
3032
3033        if (rIsSCA(r))
3034        {
3035          if(strcmp(sys_cmd, "AltVarStart") == 0)
3036            res->data = (void*)(long)scaFirstAltVar(r);
3037          else
3038            res->data = (void*)(long)scaLastAltVar(r);
3039          return FALSE;
3040        }
3041
3042        WerrorS("`system(\"AltVarStart/End\",<ring>) requires a SCA ring");
3043        return TRUE;
3044      }
3045      else
3046  #endif
3047  /*==================== RatNF, noncomm rational coeffs =================*/
3048  #ifdef HAVE_RATGRING
3049      if (strcmp(sys_cmd, "intratNF") == 0)
3050      {
3051        poly p;
3052        poly *q;
3053        ideal I;
3054        int is, k, id;
3055        if ((h!=NULL) && (h->Typ()==POLY_CMD))
3056        {
3057          p=(poly)h->CopyD();
3058          h=h->next;
3059          //        PrintS("poly is done\n");
3060        }
3061        else return TRUE;
3062        if ((h!=NULL) && (h->Typ()==IDEAL_CMD))
3063        {
3064          I=(ideal)h->CopyD();
3065          q = I->m;
3066          h=h->next;
3067          //        PrintS("ideal is done\n");
3068        }
3069        else return TRUE;
3070        if ((h!=NULL) && (h->Typ()==INT_CMD))
3071        {
3072          is=(int)((long)(h->Data()));
3073          //        res->rtyp=INT_CMD;
3074          //        PrintS("int is done\n");
3075          //        res->rtyp=IDEAL_CMD;
3076          if (rIsPluralRing(currRing))
3077          {
3078            id = IDELEMS(I);
3079                   int *pl=(int*)omAlloc0(IDELEMS(I)*sizeof(int));
3080            for(k=0; k < id; k++)
3081            {
3082              pl[k] = pLength(I->m[k]);
3083            }
3084            PrintS("starting redRat\n");
3085            //res->data = (char *)
3086            redRat(&p, q, pl, (int)IDELEMS(I),is,currRing);
3087            res->data=p;
3088            res->rtyp=POLY_CMD;
3089            //        res->data = ncGCD(p,q,currRing);
3090          }
3091          else
3092          {
3093            res->rtyp=POLY_CMD;
3094            res->data=p;
3095          }
3096        }
3097        else return TRUE;
3098        return FALSE;
3099      }
3100      else
3101  /*==================== RatNF, noncomm rational coeffs =================*/
3102      if (strcmp(sys_cmd, "ratNF") == 0)
3103      {
3104        poly p,q;
3105        int is, htype;
3106        if ((h!=NULL) && ( (h->Typ()==POLY_CMD) || (h->Typ()==VECTOR_CMD) ) )
3107        {
3108          p=(poly)h->CopyD();
3109          h=h->next;
3110          htype = h->Typ();
3111        }
3112        else return TRUE;
3113        if ((h!=NULL) && ( (h->Typ()==POLY_CMD) || (h->Typ()==VECTOR_CMD) ) )
3114        {
3115          q=(poly)h->CopyD();
3116          h=h->next;
3117        }
3118        else return TRUE;
3119        if ((h!=NULL) && (h->Typ()==INT_CMD))
3120        {
3121          is=(int)((long)(h->Data()));
3122          res->rtyp=htype;
3123          //        res->rtyp=IDEAL_CMD;
3124          if (rIsPluralRing(currRing))
3125          {
3126            res->data = nc_rat_ReduceSpolyNew(q,p,is, currRing);
3127            //        res->data = ncGCD(p,q,currRing);
3128          }
3129          else res->data=p;
3130        }
3131        else return TRUE;
3132        return FALSE;
3133      }
3134      else
3135        /*==================== RatSpoly, noncomm rational coeffs =================*/
3136      if (strcmp(sys_cmd, "ratSpoly") == 0)
3137      {
3138        poly p,q;
3139        int is;
3140        if ((h!=NULL) && (h->Typ()==POLY_CMD))
3141        {
3142          p=(poly)h->CopyD();
3143          h=h->next;
3144        }
3145        else return TRUE;
3146        if ((h!=NULL) && (h->Typ()==POLY_CMD))
3147        {
3148          q=(poly)h->CopyD();
3149          h=h->next;
3150        }
3151        else return TRUE;
3152        if ((h!=NULL) && (h->Typ()==INT_CMD))
3153        {
3154          is=(int)((long)(h->Data()));
3155          res->rtyp=POLY_CMD;
3156          //        res->rtyp=IDEAL_CMD;
3157          if (rIsPluralRing(currRing))
3158          {
3159            res->data = nc_rat_CreateSpoly(p,q,is,currRing);
3160            //        res->data = ncGCD(p,q,currRing);
3161          }
3162          else res->data=p;
3163        }
3164        else return TRUE;
3165        return FALSE;
3166      }
3167      else
3168  #endif // HAVE_RATGRING
3169  /*==================== Rat def =================*/
3170      if (strcmp(sys_cmd, "ratVar") == 0)
3171      {
3172        int start,end;
3173        if ((h!=NULL) && (h->Typ()==POLY_CMD))
3174        {
3175          start=pIsPurePower((poly)h->Data());
3176          h=h->next;
3177        }
3178        else return TRUE;
3179        if ((h!=NULL) && (h->Typ()==POLY_CMD))
3180        {
3181          end=pIsPurePower((poly)h->Data());
3182          h=h->next;
3183        }
3184        else return TRUE;
3185        currRing->real_var_start=start;
3186        currRing->real_var_end=end;
3187        return (start==0)||(end==0)||(start>end);
3188      }
3189      else
3190  /*==================== t-rep-GB ==================================*/
3191      if (strcmp(sys_cmd, "unifastmult")==0)
3192      {
3193        poly f = (poly)h->Data();
3194        h=h->next;
3195        poly g=(poly)h->Data();
3196        res->rtyp=POLY_CMD;
3197        res->data=unifastmult(f,g,currRing);
3198        return(FALSE);
3199      }
3200      else
3201      if (strcmp(sys_cmd, "multifastmult")==0)
3202      {
3203        poly f = (poly)h->Data();
3204        h=h->next;
3205        poly g=(poly)h->Data();
3206        res->rtyp=POLY_CMD;
3207        res->data=multifastmult(f,g,currRing);
3208        return(FALSE);
3209      }
3210      else
3211      if (strcmp(sys_cmd, "mults")==0)
3212      {
3213        res->rtyp=INT_CMD ;
3214        res->data=(void*)(long) Mults();
3215        return(FALSE);
3216      }
3217      else
3218      if (strcmp(sys_cmd, "fastpower")==0)
3219      {
3220        ring r = currRing;
3221        poly f = (poly)h->Data();
3222        h=h->next;
3223        int n=(int)((long)h->Data());
3224        res->rtyp=POLY_CMD ;
3225        res->data=(void*) pFastPower(f,n,r);
3226        return(FALSE);
3227      }
3228      else
3229      if (strcmp(sys_cmd, "normalpower")==0)
3230      {
3231        poly f = (poly)h->Data();
3232        h=h->next;
3233        int n=(int)((long)h->Data());
3234        res->rtyp=POLY_CMD ;
3235        res->data=(void*) pPower(pCopy(f),n);
3236        return(FALSE);
3237      }
3238      else
3239      if (strcmp(sys_cmd, "MCpower")==0)
3240      {
3241        ring r = currRing;
3242        poly f = (poly)h->Data();
3243        h=h->next;
3244        int n=(int)((long)h->Data());
3245        res->rtyp=POLY_CMD ;
3246        res->data=(void*) pFastPowerMC(f,n,r);
3247        return(FALSE);
3248      }
3249      else
3250      if (strcmp(sys_cmd, "bit_subst")==0)
3251      {
3252        ring r = currRing;
3253        poly outer = (poly)h->Data();
3254        h=h->next;
3255        poly inner=(poly)h->Data();
3256        res->rtyp=POLY_CMD ;
3257        res->data=(void*) uni_subst_bits(outer, inner,r);
3258        return(FALSE);
3259      }
3260      else
3261  /*==================== gcd-varianten =================*/
3262      if (strcmp(sys_cmd, "gcd") == 0)
3263      {
3264        if (h==NULL)
3265        {
3266        #if 0
3267          Print("FLINT_P:%d (use Flints gcd for polynomials in char p)\n",isOn(SW_USE_FL_GCD_P));
3268          Print("FLINT_0:%d (use Flints gcd for polynomials in char 0)\n",isOn(SW_USE_FL_GCD_0));
3269        #endif
3270          Print("EZGCD:%d (use EZGCD for gcd of polynomials in char 0)\n",isOn(SW_USE_EZGCD));
3271          Print("EZGCD_P:%d (use EZGCD_P for gcd of polynomials in char p)\n",isOn(SW_USE_EZGCD_P));
3272          Print("CRGCD:%d (use chinese Remainder for gcd of polynomials in char 0)\n",isOn(SW_USE_CHINREM_GCD));
3273          #ifndef __CYGWIN__
3274          Print("homog:%d (use homog. test for factorization of polynomials)\n",singular_homog_flag);
3275          #endif
3276          return FALSE;
3277        }
3278        else
3279        if ((h!=NULL) && (h->Typ()==STRING_CMD)
3280        && (h->next!=NULL) && (h->next->Typ()==INT_CMD))
3281        {
3282          int d=(int)(long)h->next->Data();
3283          char *s=(char *)h->Data();
3284        #if 0
3285          if (strcmp(s,"FLINT_P")==0) { if (d) On(SW_USE_FL_GCD_P); else Off(SW_USE_FL_GCD_P); } else
3286          if (strcmp(s,"FLINT_0")==0) { if (d) On(SW_USE_FL_GCD_0); else Off(SW_USE_FL_GCD_0); } else
3287        #endif
3288          if (strcmp(s,"EZGCD")==0) { if (d) On(SW_USE_EZGCD); else Off(SW_USE_EZGCD); } else
3289          if (strcmp(s,"EZGCD_P")==0) { if (d) On(SW_USE_EZGCD_P); else Off(SW_USE_EZGCD_P); } else
3290          if (strcmp(s,"CRGCD")==0) { if (d) On(SW_USE_CHINREM_GCD); else Off(SW_USE_CHINREM_GCD); } else
3291          #ifndef __CYGWIN__
3292          if (strcmp(s,"homog")==0) { if (d) singular_homog_flag=1; else singular_homog_flag=0; } else
3293          #endif
3294          return TRUE;
3295          return FALSE;
3296        }
3297        else return TRUE;
3298      }
3299      else
3300  /*==================== subring =================*/
3301      if (strcmp(sys_cmd, "subring") == 0)
3302      {
3303        if (h!=NULL)
3304        {
3305          extern ring rSubring(ring r,leftv v); /* ipshell.cc*/
3306          res->data=(char *)rSubring(currRing,h);
3307          res->rtyp=RING_CMD;
3308          return res->data==NULL;
3309        }
3310        else return TRUE;
3311      }
3312      else
3313  /*==================== HNF =================*/
3314  #ifdef HAVE_NTL
3315      if (strcmp(sys_cmd, "HNF") == 0)
3316      {
3317        if (h!=NULL)
3318        {
3319          res->rtyp=h->Typ();
3320          if (h->Typ()==MATRIX_CMD)
3321          {
3322            res->data=(char *)singntl_HNF((matrix)h->Data(), currRing);
3323            return FALSE;
3324          }
3325          else if (h->Typ()==INTMAT_CMD)
3326          {
3327            res->data=(char *)singntl_HNF((intvec*)h->Data());
3328            return FALSE;
3329          }
3330          else if (h->Typ()==INTMAT_CMD)
3331          {
3332            res->data=(char *)singntl_HNF((intvec*)h->Data());
3333            return FALSE;
3334          }
3335          else
3336          {
3337            WerrorS("expected `system(\"HNF\",<matrix|intmat|bigintmat>)`");
3338            return TRUE;
3339          }
3340        }
3341        else return TRUE;
3342      }
3343      else
3344  /*================= probIrredTest ======================*/
3345      if (strcmp (sys_cmd, "probIrredTest") == 0)
3346      {
3347        if (h!=NULL && (h->Typ()== POLY_CMD) && ((h->next != NULL) && h->next->Typ() == STRING_CMD))
3348        {
3349          CanonicalForm F= convSingPFactoryP((poly)(h->Data()), currRing);
3350          char *s=(char *)h->next->Data();
3351          double error= atof (s);
3352          int irred= probIrredTest (F, error);
3353          res->rtyp= INT_CMD;
3354          res->data= (void*)(long)irred;
3355          return FALSE;
3356        }
3357        else return TRUE;
3358      }
3359      else
3360  #endif
3361  /*==================== mpz_t loader ======================*/
3362    if(strcmp(sys_cmd, "GNUmpLoad")==0)
3363    {
3364      if ((h != NULL) && (h->Typ() == STRING_CMD))
3365      {
3366        char* filename = (char*)h->Data();
3367        FILE* f = fopen(filename, "r");
3368        if (f == NULL)
3369        {
3370          WerrorS( "invalid file name (in paths use '/')");
3371          return FALSE;
3372        }
3373        mpz_t m; mpz_init(m);
3374        mpz_inp_str(m, f, 10);
3375        fclose(f);
3376        number n = n_InitMPZ(m, coeffs_BIGINT);
3377        res->rtyp = BIGINT_CMD;
3378        res->data = (void*)n;
3379        return FALSE;
3380      }
3381      else
3382      {
3383        WerrorS( "expected valid file name as a string");
3384        return TRUE;
3385      }
3386    }
3387    else
3388  /*==================== intvec matching ======================*/
3389    /* Given two non-empty intvecs, the call
3390            'system("intvecMatchingSegments", ivec, jvec);'
3391         computes all occurences of jvec in ivec, i.e., it returns
3392         a list of int indices k such that ivec[k..size(jvec)+k-1] = jvec.
3393         If no such k exists (e.g. when ivec is shorter than jvec), an
3394         intvec with the single entry 0 is being returned. */
3395    if(strcmp(sys_cmd, "intvecMatchingSegments")==0)
3396    {
3397      if ((h       != NULL) && (h->Typ()       == INTVEC_CMD) &&
3398          (h->next != NULL) && (h->next->Typ() == INTVEC_CMD) &&
3399          (h->next->next == NULL))
3400      {
3401        intvec* ivec = (intvec*)h->Data();
3402        intvec* jvec = (intvec*)h->next->Data();
3403        intvec* r = new intvec(1); (*r)[0] = 0;
3404        int validEntries = 0;
3405        for (int k = 0; k <= ivec->rows() - jvec->rows(); k++)
3406        {
3407          if (memcmp(&(*ivec)[k], &(*jvec)[0],
3408                       sizeof(int) * jvec->rows()) == 0)
3409          {
3410            if (validEntries == 0)
3411              (*r)[0] = k + 1;
3412            else
3413            {
3414              r->resize(validEntries + 1);
3415              (*r)[validEntries] = k + 1;
3416            }
3417            validEntries++;
3418          }
3419        }
3420        res->rtyp = INTVEC_CMD;
3421        res->data = (void*)r;
3422        return FALSE;
3423      }
3424      else
3425      {
3426        WerrorS("expected two non-empty intvecs as arguments");
3427        return TRUE;
3428      }
3429    }
3430    else
3431  /* ================== intvecOverlap ======================= */
3432    /* Given two non-empty intvecs, the call
3433            'system("intvecOverlap", ivec, jvec);'
3434         computes the longest intvec kvec such that ivec ends with kvec
3435         and jvec starts with kvec. The length of this overlap is being
3436         returned. If there is no overlap at all, then 0 is being returned. */
3437    if(strcmp(sys_cmd, "intvecOverlap")==0)
3438    {
3439      if ((h       != NULL) && (h->Typ()       == INTVEC_CMD) &&
3440            (h->next != NULL) && (h->next->Typ() == INTVEC_CMD) &&
3441            (h->next->next == NULL))
3442      {
3443        intvec* ivec = (intvec*)h->Data();
3444        intvec* jvec = (intvec*)h->next->Data();
3445        int ir = ivec->rows(); int jr = jvec->rows();
3446        int r = jr; if (ir < jr) r = ir;   /* r = min{ir, jr} */
3447        while ((r >= 1) && (memcmp(&(*ivec)[ir - r], &(*jvec)[0],
3448                                     sizeof(int) * r) != 0))
3449          r--;
3450        res->rtyp = INT_CMD;
3451        res->data = (void*)(long)r;
3452        return FALSE;
3453      }
3454      else
3455      {
3456        WerrorS("expected two non-empty intvecs as arguments");
3457        return TRUE;
3458      }
3459    }
3460    else
3461  /*==================== Hensel's lemma ======================*/
3462    if(strcmp(sys_cmd, "henselfactors")==0)
3463    {
3464      if ((h != NULL) && (h->Typ() == INT_CMD) &&
3465        (h->next != NULL) && (h->next->Typ() == INT_CMD) &&
3466        (h->next->next != NULL) && (h->next->next->Typ() == POLY_CMD) &&
3467        (h->next->next->next != NULL) &&
3468        (h->next->next->next->Typ() == POLY_CMD) &&
3469        (h->next->next->next->next != NULL) &&
3470        (h->next->next->next->next->Typ() == POLY_CMD) &&
3471        (h->next->next->next->next->next != NULL) &&
3472        (h->next->next->next->next->next->Typ() == INT_CMD) &&
3473        (h->next->next->next->next->next->next == NULL))
3474      {
3475        int xIndex = (int)(long)h->Data();
3476        int yIndex = (int)(long)h->next->Data();
3477        poly hh    = (poly)h->next->next->Data();
3478        poly f0    = (poly)h->next->next->next->Data();
3479        poly g0    = (poly)h->next->next->next->next->Data();
3480        int d      = (int)(long)h->next->next->next->next->next->Data();
3481        poly f; poly g;
3482        henselFactors(xIndex, yIndex, hh, f0, g0, d, f, g);
3483        lists L = (lists)omAllocBin(slists_bin);
3484        L->Init(2);
3485        L->m[0].rtyp = POLY_CMD; L->m[0].data=(void*)f;
3486        L->m[1].rtyp = POLY_CMD; L->m[1].data=(void*)g;
3487        res->rtyp = LIST_CMD;
3488        res->data = (char *)L;
3489        return FALSE;
3490      }
3491      else
3492      {
3493        WerrorS( "expected argument list (int, int, poly, poly, poly, int)");
3494        return TRUE;
3495      }
3496    }
3497    else
3498  /*==================== Approx_Step  =================*/
3499  #ifdef HAVE_PLURAL
3500    if (strcmp(sys_cmd, "astep") == 0)
3501    {
3502      ideal I;
3503      if ((h!=NULL) && (h->Typ()==IDEAL_CMD))
3504      {
3505        I=(ideal)h->CopyD();
3506        res->rtyp=IDEAL_CMD;
3507        if (rIsPluralRing(currRing)) res->data=Approx_Step(I);
3508        else res->data=I;
3509        setFlag(res,FLAG_STD);
3510      }
3511      else return TRUE;
3512      return FALSE;
3513    }
3514    else
3515  #endif
3516  /*==================== PrintMat  =================*/
3517  #ifdef HAVE_PLURAL
3518    if (strcmp(sys_cmd, "PrintMat") == 0)
3519    {
3520      int a;
3521      int b;
3522      ring r;
3523      int metric;
3524      if (h!=NULL)
3525      {
3526        if (h->Typ()==INT_CMD)
3527        {
3528          a=(int)((long)(h->Data()));
3529          h=h->next;
3530        }
3531        else if (h->Typ()==INT_CMD)
3532        {
3533          b=(int)((long)(h->Data()));
3534          h=h->next;
3535        }
3536        else if (h->Typ()==RING_CMD)
3537        {
3538          r=(ring)h->Data();
3539          h=h->next;
3540        }
3541        else
3542          return TRUE;
3543      }
3544      else
3545        return TRUE;
3546      if ((h!=NULL) && (h->Typ()==INT_CMD))
3547      {
3548        metric=(int)((long)(h->Data()));
3549      }
3550      res->rtyp=MATRIX_CMD;
3551      if (rIsPluralRing(r)) res->data=nc_PrintMat(a,b,r,metric);
3552      else res->data=NULL;
3553      return FALSE;
3554    }
3555    else
3556  #endif
3557/* ============ NCUseExtensions ======================== */
3558  #ifdef HAVE_PLURAL
3559    if(strcmp(sys_cmd,"NCUseExtensions")==0)
3560    {
3561      if ((h!=NULL) && (h->Typ()==INT_CMD))
3562        res->data=(void *)(long)setNCExtensions( (int)((long)(h->Data())) );
3563      else
3564        res->data=(void *)(long)getNCExtensions();
3565      res->rtyp=INT_CMD;
3566      return FALSE;
3567    }
3568    else
3569  #endif
3570/* ============ NCGetType ======================== */
3571  #ifdef HAVE_PLURAL
3572    if(strcmp(sys_cmd,"NCGetType")==0)
3573    {
3574      res->rtyp=INT_CMD;
3575      if( rIsPluralRing(currRing) )
3576        res->data=(void *)(long)ncRingType(currRing);
3577      else
3578        res->data=(void *)(-1L);
3579      return FALSE;
3580    }
3581    else
3582  #endif
3583/* ============ ForceSCA ======================== */
3584  #ifdef HAVE_PLURAL
3585    if(strcmp(sys_cmd,"ForceSCA")==0)
3586    {
3587      if( !rIsPluralRing(currRing) )
3588        return TRUE;
3589      int b, e;
3590      if ((h!=NULL) && (h->Typ()==INT_CMD))
3591      {
3592        b = (int)((long)(h->Data()));
3593        h=h->next;
3594      }
3595      else return TRUE;
3596      if ((h!=NULL) && (h->Typ()==INT_CMD))
3597      {
3598        e = (int)((long)(h->Data()));
3599      }
3600      else return TRUE;
3601      if( !sca_Force(currRing, b, e) )
3602        return TRUE;
3603      return FALSE;
3604    }
3605    else
3606  #endif
3607/* ============ ForceNewNCMultiplication ======================== */
3608  #ifdef HAVE_PLURAL
3609    if(strcmp(sys_cmd,"ForceNewNCMultiplication")==0)
3610    {
3611      if( !rIsPluralRing(currRing) )
3612        return TRUE;
3613      if( !ncInitSpecialPairMultiplication(currRing) ) // No Plural!
3614        return TRUE;
3615      return FALSE;
3616    }
3617    else
3618  #endif
3619/* ============ ForceNewOldNCMultiplication ======================== */
3620  #ifdef HAVE_PLURAL
3621    if(strcmp(sys_cmd,"ForceNewOldNCMultiplication")==0)
3622    {
3623      if( !rIsPluralRing(currRing) )
3624        return TRUE;
3625      if( !ncInitSpecialPowersMultiplication(currRing) ) // Enable Formula for Plural (depends on swiches)!
3626        return TRUE;
3627      return FALSE;
3628    }
3629    else
3630  #endif
3631/*==================== test64 =================*/
3632  #if 0
3633    if(strcmp(sys_cmd,"test64")==0)
3634    {
3635      long l=8;int i;
3636      for(i=1;i<62;i++)
3637      {
3638        l=l<<1;
3639        number n=n_Init(l,coeffs_BIGINT);
3640        Print("%ld= ",l);n_Print(n,coeffs_BIGINT);
3641        CanonicalForm nn=n_convSingNFactoryN(n,TRUE,coeffs_BIGINT);
3642        n_Delete(&n,coeffs_BIGINT);
3643        n=n_convFactoryNSingN(nn,coeffs_BIGINT);
3644        PrintS(" F:");
3645        n_Print(n,coeffs_BIGINT);
3646        PrintLn();
3647        n_Delete(&n,coeffs_BIGINT);
3648      }
3649      Print("SIZEOF_LONG=%d\n",SIZEOF_LONG);
3650      return FALSE;
3651    }
3652    else
3653   #endif
3654/*==================== n_SwitchChinRem =================*/
3655    if(strcmp(sys_cmd,"cache_chinrem")==0)
3656    {
3657      EXTERN_VAR int n_SwitchChinRem;
3658      Print("caching inverse in chines remainder:%d\n",n_SwitchChinRem);
3659      if ((h!=NULL)&&(h->Typ()==INT_CMD))
3660        n_SwitchChinRem=(int)(long)h->Data();
3661      return FALSE;
3662    }
3663    else
3664/*==================== LU for bigintmat =================*/
3665#ifdef SINGULAR_4_2
3666    if(strcmp(sys_cmd,"LU")==0)
3667    {
3668      if ((h!=NULL) && (h->Typ()==CMATRIX_CMD))
3669      {
3670        // get the argument:
3671        bigintmat *b=(bigintmat *)h->Data();
3672        // just for tests: simply transpose
3673        bigintmat *bb=b->transpose();
3674        // return the result:
3675        res->rtyp=CMATRIX_CMD;
3676        res->data=(char*)bb;
3677        return FALSE;
3678      }
3679      else
3680      {
3681        WerrorS("system(\"LU\",<cmatrix>) expected");
3682        return TRUE;
3683      }
3684    }
3685    else
3686#endif
3687/*==================== sort =================*/
3688    if(strcmp(sys_cmd,"sort")==0)
3689    {
3690      extern BOOLEAN jjSORTLIST(leftv,leftv);
3691      if (h->Typ()==LIST_CMD)
3692        return jjSORTLIST(res,h);
3693      else
3694        return TRUE;
3695    }
3696    else
3697/*==================== uniq =================*/
3698    if(strcmp(sys_cmd,"uniq")==0)
3699    {
3700      extern BOOLEAN jjUNIQLIST(leftv, leftv);
3701      if (h->Typ()==LIST_CMD)
3702        return jjUNIQLIST(res,h);
3703      else
3704        return TRUE;
3705    }
3706    else
3707/*==================== GF(p,n) ==================================*/
3708    if(strcmp(sys_cmd,"GF")==0)
3709    {
3710      const short t[]={3,INT_CMD,INT_CMD,STRING_CMD};
3711      if (iiCheckTypes(h,t,1))
3712      {
3713        int p=(int)(long)h->Data();
3714        int n=(int)(long)h->next->Data();
3715        char *v=(char*)h->next->next->CopyD();
3716        GFInfo param;
3717        param.GFChar = p;
3718        param.GFDegree = n;
3719        param.GFPar_name = v;
3720        coeffs cf= nInitChar(n_GF, &param);
3721        res->rtyp=CRING_CMD;
3722        res->data=cf;
3723        return FALSE;
3724      }
3725      else
3726        return TRUE;
3727    }
3728    else
3729/*==================== power* ==================================*/
3730    #if 0
3731    if(strcmp(sys_cmd,"power1")==0)
3732    {
3733      res->rtyp=POLY_CMD;
3734      poly f=(poly)h->CopyD();
3735      poly g=pPower(f,2000);
3736      res->data=(void *)g;
3737      return FALSE;
3738    }
3739    else
3740    if(strcmp(sys_cmd,"power2")==0)
3741    {
3742      res->rtyp=POLY_CMD;
3743      poly f=(poly)h->Data();
3744      poly g=pOne();
3745      for(int i=0;i<2000;i++)
3746        g=pMult(g,pCopy(f));
3747      res->data=(void *)g;
3748      return FALSE;
3749    }
3750    if(strcmp(sys_cmd,"power3")==0)
3751    {
3752      res->rtyp=POLY_CMD;
3753      poly f=(poly)h->Data();
3754      poly p2=pMult(pCopy(f),pCopy(f));
3755      poly p4=pMult(pCopy(p2),pCopy(p2));
3756      poly p8=pMult(pCopy(p4),pCopy(p4));
3757      poly p16=pMult(pCopy(p8),pCopy(p8));
3758      poly p32=pMult(pCopy(p16),pCopy(p16));
3759      poly p64=pMult(pCopy(p32),pCopy(p32));
3760      poly p128=pMult(pCopy(p64),pCopy(p64));
3761      poly p256=pMult(pCopy(p128),pCopy(p128));
3762      poly p512=pMult(pCopy(p256),pCopy(p256));
3763      poly p1024=pMult(pCopy(p512),pCopy(p512));
3764      poly p1536=pMult(p1024,p512);
3765      poly p1792=pMult(p1536,p256);
3766      poly p1920=pMult(p1792,p128);
3767      poly p1984=pMult(p1920,p64);
3768      poly p2000=pMult(p1984,p16);
3769      res->data=(void *)p2000;
3770      pDelete(&p2);
3771      pDelete(&p4);
3772      pDelete(&p8);
3773      //pDelete(&p16);
3774      pDelete(&p32);
3775      //pDelete(&p64);
3776      //pDelete(&p128);
3777      //pDelete(&p256);
3778      //pDelete(&p512);
3779      //pDelete(&p1024);
3780      //pDelete(&p1536);
3781      //pDelete(&p1792);
3782      //pDelete(&p1920);
3783      //pDelete(&p1984);
3784      return FALSE;
3785    }
3786    else
3787    #endif
3788/* ccluster --------------------------------------------------------------*/
3789#ifdef HAVE_CCLUSTER
3790    if(strcmp(sys_cmd,"ccluster")==0)
3791    {
3792      if ((currRing!=NULL)
3793      && (rField_is_Q(currRing) || rField_is_R(currRing) || rField_is_long_R(currRing)))
3794      {
3795        const short t[]={5,POLY_CMD,NUMBER_CMD,NUMBER_CMD,NUMBER_CMD,NUMBER_CMD};
3796        const short t2[]={6,POLY_CMD,POLY_CMD,NUMBER_CMD,NUMBER_CMD,NUMBER_CMD,NUMBER_CMD};
3797
3798//         printf("test t : %d\n", h->Typ()==POLY_CMD);
3799//         printf("test t : %d\n", h->next->Typ()==POLY_CMD);
3800        int pol_with_complex_coeffs=0;
3801        if (h->next->Typ()==POLY_CMD)
3802            pol_with_complex_coeffs=1;
3803
3804        if ( (pol_with_complex_coeffs==0 && iiCheckTypes(h,t,1))
3805       ||(pol_with_complex_coeffs==1 && iiCheckTypes(h,t2,1)) )
3806        {
3807          // convert first arg. to fmpq_poly_t
3808          fmpq_poly_t fre, fim;
3809          convSingPFlintP(fre,(poly)h->Data(),currRing); h=h->next;
3810          if (pol_with_complex_coeffs==1)
3811          { // convert second arg. to fmpq_poly_t
3812            convSingPFlintP(fim,(poly)h->Data(),currRing); h=h->next;
3813          }
3814          // convert box-center(re,im), box-size, epsilon
3815          fmpq_t center_re,center_im,boxsize,eps;
3816          convSingNFlintN(center_re,(number)h->Data(),currRing->cf); h=h->next;
3817          convSingNFlintN(center_im,(number)h->Data(),currRing->cf); h=h->next;
3818          convSingNFlintN(boxsize,(number)h->Data(),currRing->cf); h=h->next;
3819          convSingNFlintN(eps,(number)h->Data(),currRing->cf); h=h->next;
3820          // alloc arrays
3821          int n=fmpq_poly_length(fre);
3822          fmpq_t* re_part=(fmpq_t*)omAlloc(n*sizeof(fmpq_t));
3823          fmpq_t* im_part=(fmpq_t*)omAlloc(n*sizeof(fmpq_t));
3824          int *mult      =(int*)   omAlloc(n*sizeof(int));
3825          for(int i=0; i<n;i++)
3826          { fmpq_init(re_part[i]); fmpq_init(im_part[i]); }
3827          // call cccluster, adjust n
3828          int verbosity =0; //nothing is printed
3829          int strategy = 23; //default strategy
3830          int nn=0;
3831          long nb_threads = (long) feOptValue(FE_OPT_CPUS);
3832          strategy = strategy+(nb_threads<<6);
3833//       printf("nb threads: %ld\n", nb_threads);
3834//       printf("strategy: %ld\n", strategy);
3835          if (pol_with_complex_coeffs==0)
3836            nn=ccluster_interface_poly_real(re_part,im_part,mult,fre,center_re,center_im,boxsize,eps,strategy,verbosity);
3837          else
3838            nn=ccluster_interface_poly_real_imag(re_part,im_part,mult,fre,fim,center_re,center_im,boxsize,eps,strategy,verbosity);
3839          // convert to list
3840          lists l=(lists)omAlloc0Bin(slists_bin);
3841          l->Init(nn);
3842          for(int i=0; i<nn;i++)
3843          {
3844            lists ll=(lists)omAlloc0Bin(slists_bin);
3845            l->m[i].rtyp=LIST_CMD;
3846            l->m[i].data=ll;
3847            ll->Init(3);
3848            ll->m[0].rtyp=NUMBER_CMD;
3849            ll->m[1].rtyp=NUMBER_CMD;
3850            ll->m[2].rtyp=INT_CMD;
3851            ll->m[0].data=convFlintNSingN(re_part[i],currRing->cf);
3852            ll->m[1].data=convFlintNSingN(im_part[i],currRing->cf);
3853            ll->m[2].data=(void *)(long)mult[i];
3854          }
3855          //clear re, im, mults, fre, fim
3856          for(int i=n-1;i>=0;i--) { fmpq_clear(re_part[i]); fmpq_clear(im_part[i]); }
3857          omFree(re_part);
3858          omFree(im_part);
3859          omFree(mult);
3860          fmpq_clear(center_re); fmpq_clear(center_im); fmpq_clear(boxsize); fmpq_clear(eps);
3861          fmpq_poly_clear(fre);
3862          if (pol_with_complex_coeffs==1) fmpq_poly_clear(fim);
3863          // result
3864          res->rtyp=LIST_CMD;
3865          res->data=l;
3866          return FALSE;
3867        }
3868      }
3869      return TRUE;
3870    }
3871    else
3872#endif
3873/* ====== maEvalAt ============================*/
3874    if(strcmp(sys_cmd,"evaluate")==0)
3875    {
3876      extern number maEvalAt(const poly p,const number* pt, const ring r);
3877      if (h->Typ()!=POLY_CMD)
3878      {
3879        WerrorS("expected system(\"evaluate\",<poly>,..)");
3880        return TRUE;
3881      }
3882      poly p=(poly)h->Data();
3883      number *pt=(number*)omAlloc(sizeof(number)*currRing->N);
3884      for(int i=0;i<currRing->N;i++)
3885      {
3886        h=h->next;
3887        if ((h==NULL)||(h->Typ()!=NUMBER_CMD))
3888        {
3889          WerrorS("system(\"evaluate\",<poly>,<number>..) - expect number");
3890          return TRUE;
3891        }
3892        pt[i]=(number)h->Data();
3893      }
3894      res->data=maEvalAt(p,pt,currRing);
3895      res->rtyp=NUMBER_CMD;
3896      return FALSE;
3897    }
3898    else
3899/* ====== DivRem ============================*/
3900    if(strcmp(sys_cmd,"DivRem")==0)
3901    {
3902      const short t1[]={2,POLY_CMD,POLY_CMD};
3903      if (iiCheckTypes(h,t1,1))
3904      {
3905        poly p=(poly)h->CopyD();
3906        poly q=(poly)h->next->CopyD();
3907        poly rest;
3908        res->data=p_DivRem(p,q,rest,currRing);
3909        res->rtyp=POLY_CMD;
3910        Print("rest:");pWrite(rest);
3911        return FALSE;
3912      }
3913      else
3914      {
3915        WerrorS("expected system(\"DivRem\",<poly>,<poly>)");
3916        return TRUE;
3917      }
3918    }
3919    else
3920/* ====== fq_nmod_mat_rref ============================*/
3921    #ifdef HAVE_FLINT
3922    if(strcmp(sys_cmd,"fq_nmod_mat_rref")==0)
3923    {
3924      const short t1[]={1,MATRIX_CMD};
3925      if (iiCheckTypes(h,t1,1))
3926      {
3927        matrix M=(matrix)h->Data();
3928        fq_nmod_ctx_t ctx;
3929        fmpz_t p;
3930        convSingIFlintI(p,rChar(currRing));
3931        fq_nmod_ctx_init(ctx,p,1,"t");
3932        fq_nmod_mat_t FLINTM;
3933        // convert matrix
3934        convSingMFlintFq_nmod_mat(M,FLINTM,ctx,currRing);
3935        // rank
3936        long rk= fq_nmod_mat_rref (FLINTM,ctx);
3937        res->data=(void*)convFlintFq_nmod_matSingM(FLINTM,ctx,currRing);
3938        // clean up
3939        fq_nmod_mat_clear (FLINTM,ctx);
3940        fq_nmod_ctx_clear(ctx);
3941        fmpz_clear(p);
3942        res->rtyp=MATRIX_CMD;
3943        Print("rank:%ld\n",rk);
3944        return FALSE;
3945      }
3946      else
3947      {
3948        WerrorS("expected system(\"fq_nmod_mat_rref\",<matrix>)");
3949        return TRUE;
3950      }
3951    }
3952    else
3953    #endif
3954/*==================== Error =================*/
3955      Werror( "(extended) system(\"%s\",...) %s", sys_cmd, feNotImplemented );
3956  }
3957  return TRUE;
3958}
3959
3960#endif // HAVE_EXTENDED_SYSTEM
3961
3962
Note: See TracBrowser for help on using the repository browser.