source: git/Singular/extra.cc @ 0509a99

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