source: git/Singular/extra.cc @ 0615d9

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