source: git/Singular/extra.cc @ b38bc9

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