source: git/Singular/extra.cc @ b5f5444

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