source: git/Singular/extra.cc @ 2c24810

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