source: git/Singular/extra.cc @ a9c298

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