source: git/Singular/extra.cc @ 4154bb

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