source: git/Singular/extra.cc @ 654a23

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