source: git/Singular/extra.cc @ 2024f6a

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