source: git/Singular/extra.cc @ 8d1432e

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