source: git/Singular/extra.cc @ 3a7e239

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