source: git/Singular/extra.cc @ 206e202

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