source: git/Singular/extra.cc @ a054302

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