source: git/Singular/extra.cc @ 72a01e

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