source: git/Singular/extra.cc @ 9e269a0

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