source: git/Singular/extra.cc @ 5d51cc6

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