source: git/Singular/extra.cc @ 53b247

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