source: git/Singular/extra.cc @ e57c8b

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