source: git/Singular/extra.cc @ 291790

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