source: git/Singular/misc_ip.cc @ a871fef

spielwiese
Last change on this file since a871fef was a871fef, checked in by Hans Schoenemann <hannes@…>, 6 years ago
add: --threads/FE_OPT_THREADS to options
  • Property mode set to 100644
File size: 36.0 KB
Line 
1/*****************************************************************************\
2 * Computer Algebra System SINGULAR
3\*****************************************************************************/
4/** @file misc_ip.cc
5 *
6 * This file provides miscellaneous functionality.
7 *
8 * For more general information, see the documentation in misc_ip.h.
9 *
10 **/
11/*****************************************************************************/
12
13// include header files
14#define PLURAL_INTERNAL_DECLARATIONS 1
15
16#include "kernel/mod2.h"
17#include "misc/sirandom.h"
18
19#include "omalloc/omalloc.h"
20#include "misc/mylimits.h"
21
22#include "reporter/si_signals.h"
23
24#include "factory/factory.h"
25
26#include "coeffs/si_gmp.h"
27#include "coeffs/coeffs.h"
28#include "coeffs/OPAE.h"
29#include "coeffs/OPAEQ.h"
30#include "coeffs/OPAEp.h"
31#include "coeffs/flintcf_Q.h"
32#include "coeffs/flintcf_Zn.h"
33
34#include "polys/ext_fields/algext.h"
35#include "polys/ext_fields/transext.h"
36#include "polys/nc/gb_hack.h"
37
38#ifdef HAVE_SIMPLEIPC
39#include "Singular/links/simpleipc.h"
40#endif
41
42#include "misc_ip.h"
43#include "ipid.h"
44#include "feOpt.h"
45#include "links/silink.h"
46#include "mod_lib.h"
47#include "Singular/distrib.h"
48
49#include "misc/options.h"
50#include "misc/intvec.h"
51
52#include "polys/monomials/ring.h"
53#include "polys/templates/p_Procs.h"
54
55#include "kernel/GBEngine/kstd1.h"
56#include "kernel/oswrapper/timer.h"
57#include "resources/feResource.h"
58#include "kernel/oswrapper/feread.h"
59
60#include "subexpr.h"
61#include "cntrlc.h"
62#include "ipshell.h"
63
64#include "fehelp.h"
65
66#ifdef HAVE_READLINE
67  #ifdef READLINE_READLINE_H_OK
68    #include <readline/readline.h>
69  #endif
70  #ifndef RL_VERSION_MAJOR
71    #define RL_VERSION_MAJOR 0
72  #endif
73#endif
74
75#ifdef HAVE_NTL
76#include<NTL/version.h>
77#include<NTL/tools.h>
78#ifdef NTL_CLIENT
79NTL_CLIENT
80#endif
81#endif
82
83
84static FORCE_INLINE void number2mpz(number n, mpz_t m){ number2mpz(n, coeffs_BIGINT, m); }
85static FORCE_INLINE number mpz2number(mpz_t m){ return mpz2number(m, coeffs_BIGINT); }
86
87
88void setListEntry(lists L, int index, mpz_t n)
89{ /* assumes n > 0 */
90  /* try to fit nn into an int: */
91  if (mpz_size1(n)<=1)
92  {
93    int ui=(int)mpz_get_si(n);
94    if ((((ui<<3)>>3)==ui)
95    && (mpz_cmp_si(n,(long)ui)==0))
96    {
97      L->m[index].rtyp = INT_CMD; L->m[index].data = (void*)(long)ui;
98      return;
99    }
100  }
101  number nn = mpz2number(n);
102  L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn;
103}
104
105void setListEntry_ui(lists L, int index, unsigned long ui)
106{ /* assumes n > 0 */
107  /* try to fit nn into an int: */
108  int i=(int)ui;
109  if ((((unsigned long)i)==ui) && (((i<<3)>>3)==i))
110  {
111    L->m[index].rtyp = INT_CMD; L->m[index].data = (void*)(long)i;
112  }
113  else
114  {
115    number nn = n_Init(ui, coeffs_BIGINT);
116    L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn;
117  }
118}
119
120/* Factoring with Pollard's rho method. stolen from GMP/demos */
121static unsigned add[] = {4, 2, 4, 2, 4, 6, 2, 6};
122
123static int factor_using_division (mpz_t t, unsigned int limit,lists primes, int *multiplicities,int &index, unsigned long bound)
124{
125  mpz_t q, r;
126  unsigned long int f;
127  int ai;
128  unsigned *addv = add;
129  unsigned int failures;
130  int bound_not_reached=1;
131
132  mpz_init (q);
133  mpz_init (r);
134
135  f = mpz_scan1 (t, 0);
136  mpz_div_2exp (t, t, f);
137  if (f>0)
138  {
139    setListEntry_ui(primes, index, 2);
140    multiplicities[index++] = f;
141  }
142
143  f=0;
144  loop
145  {
146    mpz_tdiv_qr_ui (q, r, t, 3);
147    if (mpz_sgn1 (r) != 0)
148        break;
149    mpz_set (t, q);
150    f++;
151  }
152  if (f>0)
153  {
154    setListEntry_ui(primes, index, 3);
155    multiplicities[index++] = f;
156  }
157  f=0;
158  loop
159  {
160    mpz_tdiv_qr_ui (q, r, t, 5);
161    if (mpz_sgn1 (r) != 0)
162        break;
163    mpz_set (t, q);
164    f++;
165  }
166  if (f>0)
167  {
168    setListEntry_ui(primes, index, 5);
169    multiplicities[index++] = f;
170  }
171
172  failures = 0;
173  f = 7;
174  ai = 0;
175  unsigned long last_f=0;
176  while (mpz_cmp_ui (t, 1) != 0)
177  {
178    mpz_tdiv_qr_ui (q, r, t, f);
179    if (mpz_sgn1 (r) != 0)
180    {
181      f += addv[ai];
182      if (mpz_cmp_ui (t, f) < 0)
183        break;
184      ai = (ai + 1) & 7;
185      failures++;
186      if (failures > limit)
187        break;
188      if ((bound!=0) && (f>bound))
189      {
190        bound_not_reached=0;
191        break;
192      }
193    }
194    else
195    {
196      mpz_swap (t, q);
197      if (f!=last_f)
198      {
199        setListEntry_ui(primes, index, f);
200        multiplicities[index]++;
201        index++;
202      }
203      else
204      {
205        multiplicities[index-1]++;
206      }
207      last_f=f;
208      failures = 0;
209    }
210  }
211
212  mpz_clear (q);
213  mpz_clear (r);
214  //printf("bound=%d,f=%d,failures=%d, reached=%d\n",bound,f,failures,bound_not_reached);
215  return bound_not_reached;
216}
217
218static void factor_using_pollard_rho (mpz_t n, unsigned long a, lists primes, int * multiplicities,int &index)
219{
220  mpz_t x, x1, y, P;
221  mpz_t t1, t2;
222  mpz_t last_f;
223  unsigned long long k, l, i;
224
225  mpz_init (t1);
226  mpz_init (t2);
227  mpz_init_set_ui (last_f, 0);
228  mpz_init_set_ui (y, 2);
229  mpz_init_set_ui (x, 2);
230  mpz_init_set_ui (x1, 2);
231  mpz_init_set_ui (P, 1);
232  k = 1;
233  l = 1;
234
235  while (mpz_cmp_ui (n, 1) != 0)
236  {
237    loop
238    {
239      do
240      {
241        mpz_mul (t1, x, x);
242        mpz_mod (x, t1, n);
243        mpz_add_ui (x, x, a);
244        mpz_sub (t1, x1, x);
245        mpz_mul (t2, P, t1);
246        mpz_mod (P, t2, n);
247
248        if (k % 32 == 1)
249        {
250          mpz_gcd (t1, P, n);
251          if (mpz_cmp_ui (t1, 1) != 0)
252            goto factor_found;
253          mpz_set (y, x);
254        }
255      }
256      while (--k != 0);
257
258      mpz_gcd (t1, P, n);
259      if (mpz_cmp_ui (t1, 1) != 0)
260        goto factor_found;
261
262      mpz_set (x1, x);
263      k = l;
264      l = 2 * l;
265      for (i = 0; i < k; i++)
266      {
267        mpz_mul (t1, x, x);
268        mpz_mod (x, t1, n);
269        mpz_add_ui (x, x, a);
270      }
271      mpz_set (y, x);
272    }
273
274  factor_found:
275    do
276    {
277      mpz_mul (t1, y, y);
278      mpz_mod (y, t1, n);
279      mpz_add_ui (y, y, a);
280      mpz_sub (t1, x1, y);
281      mpz_gcd (t1, t1, n);
282    }
283    while (mpz_cmp_ui (t1, 1) == 0);
284
285    mpz_divexact (n, n, t1);        /* divide by t1, before t1 is overwritten */
286
287    if (!mpz_probab_prime_p (t1, 10))
288    {
289      do
290      {
291        mp_limb_t a_limb;
292        mpn_random (&a_limb, (mp_size_t) 1);
293        a = a_limb;
294      }
295      while (a == 0);
296
297      factor_using_pollard_rho (t1, a, primes,multiplicities,index);
298    }
299    else
300    {
301      if (mpz_cmp(t1,last_f)==0)
302      {
303        multiplicities[index-1]++;
304      }
305      else
306      {
307        mpz_set(last_f,t1);
308        setListEntry(primes, index, t1);
309        multiplicities[index++] = 1;
310      }
311    }
312    mpz_mod (x, x, n);
313    mpz_mod (x1, x1, n);
314    mpz_mod (y, y, n);
315    if (mpz_probab_prime_p (n, 10))
316    {
317      if (mpz_cmp(n,last_f)==0)
318      {
319        multiplicities[index-1]++;
320      }
321      else
322      {
323        mpz_set(last_f,n);
324        setListEntry(primes, index, n);
325        multiplicities[index++] = 1;
326      }
327      mpz_set_ui(n,1);
328      break;
329    }
330  }
331
332  mpz_clear (P);
333  mpz_clear (t2);
334  mpz_clear (t1);
335  mpz_clear (x1);
336  mpz_clear (x);
337  mpz_clear (y);
338  mpz_clear (last_f);
339}
340
341static void factor_gmp (mpz_t t,lists primes,int *multiplicities,int &index,unsigned long bound)
342{
343  unsigned int division_limit;
344
345  if (mpz_sgn (t) == 0)
346    return;
347
348  /* Set the trial division limit according the size of t.  */
349  division_limit = mpz_sizeinbase (t, 2);
350  if (division_limit > 1000)
351    division_limit = 1000 * 1000;
352  else
353    division_limit = division_limit * division_limit;
354
355  if (factor_using_division (t, division_limit,primes,multiplicities,index,bound))
356  {
357    if (mpz_cmp_ui (t, 1) != 0)
358    {
359      if (mpz_probab_prime_p (t, 10))
360      {
361        setListEntry(primes, index, t);
362        multiplicities[index++] = 1;
363        mpz_set_ui(t,1);
364      }
365      else
366        factor_using_pollard_rho (t, 1L, primes,multiplicities,index);
367    }
368  }
369}
370/* n and pBound are assumed to be bigint numbers */
371lists primeFactorisation(const number n, const int pBound)
372{
373  int i;
374  int index=0;
375  mpz_t nn; number2mpz(n, nn);
376  lists primes = (lists)omAllocBin(slists_bin); primes->Init(1000);
377  int* multiplicities = (int*)omAlloc0(1000*sizeof(int));
378  int positive=1;
379
380  if (!n_IsZero(n, coeffs_BIGINT))
381  {
382    if (!n_GreaterZero(n, coeffs_BIGINT))
383    {
384      positive=-1;
385      mpz_neg(nn,nn);
386    }
387    factor_gmp(nn,primes,multiplicities,index,pBound);
388  }
389
390  lists primesL = (lists)omAllocBin(slists_bin);
391  primesL->Init(index);
392  for (i = 0; i < index; i++)
393  {
394    primesL->m[i].rtyp = primes->m[i].rtyp;
395    primesL->m[i].data = primes->m[i].data;
396    primes->m[i].rtyp=0;
397    primes->m[i].data=NULL;
398  }
399  primes->Clean(NULL);
400
401  lists multiplicitiesL = (lists)omAllocBin(slists_bin);
402  multiplicitiesL->Init(index);
403  for (i = 0; i < index; i++)
404  {
405    multiplicitiesL->m[i].rtyp = INT_CMD;
406    multiplicitiesL->m[i].data = (void*)(long)multiplicities[i];
407  }
408  omFree(multiplicities);
409
410  lists L=(lists)omAllocBin(slists_bin);
411  L->Init(3);
412  if (positive==-1) mpz_neg(nn,nn);
413  L->m[0].rtyp = LIST_CMD; L->m[0].data = (void*)primesL;
414  L->m[1].rtyp = LIST_CMD; L->m[1].data = (void*)multiplicitiesL;
415  setListEntry(L, 2, nn);
416
417  mpz_clear(nn);
418
419  return L;
420}
421
422#ifdef HAVE_STATIC
423#undef HAVE_DYN_RL
424#endif
425
426//#ifdef HAVE_LIBPARSER
427//#  include "libparse.h"
428//#endif /* HAVE_LIBPARSER */
429
430
431/*2
432* the renice routine for very large jobs
433* works only on unix machines,
434* testet on : linux, HP 9.0
435*
436*#include <sys/times.h>
437*#include <sys/resource.h>
438*extern "C" int setpriority(int,int,int);
439*void very_nice()
440*{
441*#ifndef NO_SETPRIORITY
442*  setpriority(PRIO_PROCESS,0,19);
443*#endif
444*  sleep(10);
445*}
446*/
447
448#include <string.h>
449#include <unistd.h>
450#include <stdio.h>
451#include <stddef.h>
452#include <stdlib.h>
453#include <time.h>
454
455
456void singular_example(char *str)
457{
458  assume(str!=NULL);
459  char *s=str;
460  while (*s==' ') s++;
461  char *ss=s;
462  while (*ss!='\0') ss++;
463  while (*ss<=' ')
464  {
465    *ss='\0';
466    ss--;
467  }
468  idhdl h=IDROOT->get(s,myynest);
469  if ((h!=NULL) && (IDTYP(h)==PROC_CMD))
470  {
471    char *lib=iiGetLibName(IDPROC(h));
472    if((lib!=NULL)&&(*lib!='\0'))
473    {
474      Print("// proc %s from lib %s\n",s,lib);
475      s=iiGetLibProcBuffer(IDPROC(h), 2);
476      if (s!=NULL)
477      {
478        if (strlen(s)>5)
479        {
480          iiEStart(s,IDPROC(h));
481          omFree((ADDRESS)s);
482          return;
483        }
484        else omFree((ADDRESS)s);
485      }
486    }
487  }
488  else
489  {
490    char sing_file[MAXPATHLEN];
491    FILE *fd=NULL;
492    char *res_m=feResource('m', 0);
493    if (res_m!=NULL)
494    {
495      sprintf(sing_file, "%s/%s.sing", res_m, s);
496      fd = feFopen(sing_file, "r");
497    }
498    if (fd != NULL)
499    {
500
501      int old_echo = si_echo;
502      int length, got;
503      char* s;
504
505      fseek(fd, 0, SEEK_END);
506      length = ftell(fd);
507      fseek(fd, 0, SEEK_SET);
508      s = (char*) omAlloc((length+20)*sizeof(char));
509      got = fread(s, sizeof(char), length, fd);
510      fclose(fd);
511      if (got != length)
512      {
513        Werror("Error while reading file %s", sing_file);
514      }
515      else
516      {
517        s[length] = '\0';
518        strcat(s, "\n;return();\n\n");
519        si_echo = 2;
520        iiEStart(s, NULL);
521        si_echo = old_echo;
522      }
523      omFree(s);
524    }
525    else
526    {
527      Werror("no example for %s", str);
528    }
529  }
530}
531
532
533const struct soptionStruct optionStruct[]=
534{
535  {"prot",         Sy_bit(OPT_PROT),           ~Sy_bit(OPT_PROT)   },
536  {"redSB",        Sy_bit(OPT_REDSB),          ~Sy_bit(OPT_REDSB)   },
537  {"notBuckets",   Sy_bit(OPT_NOT_BUCKETS),    ~Sy_bit(OPT_NOT_BUCKETS)   },
538  {"notSugar",     Sy_bit(OPT_NOT_SUGAR),      ~Sy_bit(OPT_NOT_SUGAR)   },
539  {"interrupt",    Sy_bit(OPT_INTERRUPT),      ~Sy_bit(OPT_INTERRUPT)   },
540  {"sugarCrit",    Sy_bit(OPT_SUGARCRIT),      ~Sy_bit(OPT_SUGARCRIT)   },
541  {"teach",        Sy_bit(OPT_DEBUG),          ~Sy_bit(OPT_DEBUG)  },
542  {"notSyzMinim",  Sy_bit(OPT_NO_SYZ_MINIM),   ~Sy_bit(OPT_NO_SYZ_MINIM)  },
543  /* 9 return SB in syz, quotient, intersect */
544  {"returnSB",     Sy_bit(OPT_RETURN_SB),      ~Sy_bit(OPT_RETURN_SB)  },
545  {"fastHC",       Sy_bit(OPT_FASTHC),         ~Sy_bit(OPT_FASTHC)  },
546  /* 11-19 sort in L/T */
547  {"staircaseBound",Sy_bit(OPT_STAIRCASEBOUND),~Sy_bit(OPT_STAIRCASEBOUND)  },
548  {"multBound",    Sy_bit(OPT_MULTBOUND),      ~Sy_bit(OPT_MULTBOUND)  },
549  {"degBound",     Sy_bit(OPT_DEGBOUND),       ~Sy_bit(OPT_DEGBOUND)  },
550  /* 25 no redTail(p)/redTail(s) */
551  {"redTail",      Sy_bit(OPT_REDTAIL),        ~Sy_bit(OPT_REDTAIL)  },
552  {"redThrough",   Sy_bit(OPT_REDTHROUGH),     ~Sy_bit(OPT_REDTHROUGH)  },
553  {"lazy",         Sy_bit(OPT_OLDSTD),         ~Sy_bit(OPT_OLDSTD)  },
554  {"intStrategy",  Sy_bit(OPT_INTSTRATEGY),    ~Sy_bit(OPT_INTSTRATEGY)  },
555  {"infRedTail",   Sy_bit(OPT_INFREDTAIL),     ~Sy_bit(OPT_INFREDTAIL)  },
556  /* 30: use not regularity for syz */
557  {"notRegularity",Sy_bit(OPT_NOTREGULARITY),  ~Sy_bit(OPT_NOTREGULARITY)  },
558  {"weightM",      Sy_bit(OPT_WEIGHTM),        ~Sy_bit(OPT_WEIGHTM)  },
559/*special for "none" and also end marker for showOption:*/
560  {"ne",           0,                          0 }
561};
562
563const struct soptionStruct verboseStruct[]=
564{
565  {"assign_none",Sy_bit(V_ASSIGN_NONE),~Sy_bit(V_ASSIGN_NONE)},
566  {"mem",      Sy_bit(V_SHOW_MEM),  ~Sy_bit(V_SHOW_MEM)   },
567  {"yacc",     Sy_bit(V_YACC),      ~Sy_bit(V_YACC)       },
568  {"redefine", Sy_bit(V_REDEFINE),  ~Sy_bit(V_REDEFINE)   },
569  {"reading",  Sy_bit(V_READING),   ~Sy_bit(V_READING)    },
570  {"loadLib",  Sy_bit(V_LOAD_LIB),  ~Sy_bit(V_LOAD_LIB)   },
571  {"debugLib", Sy_bit(V_DEBUG_LIB), ~Sy_bit(V_DEBUG_LIB)  },
572  {"loadProc", Sy_bit(V_LOAD_PROC), ~Sy_bit(V_LOAD_PROC)  },
573  {"defRes",   Sy_bit(V_DEF_RES),   ~Sy_bit(V_DEF_RES)    },
574  {"usage",    Sy_bit(V_SHOW_USE),  ~Sy_bit(V_SHOW_USE)   },
575  {"Imap",     Sy_bit(V_IMAP),      ~Sy_bit(V_IMAP)       },
576  {"prompt",   Sy_bit(V_PROMPT),    ~Sy_bit(V_PROMPT)     },
577  {"length",   Sy_bit(V_LENGTH),    ~Sy_bit(V_LENGTH)     },
578  {"notWarnSB",Sy_bit(V_NSB),       ~Sy_bit(V_NSB)        },
579  {"contentSB",Sy_bit(V_CONTENTSB), ~Sy_bit(V_CONTENTSB)  },
580  {"cancelunit",Sy_bit(V_CANCELUNIT),~Sy_bit(V_CANCELUNIT)},
581  {"modpsolve",Sy_bit(V_MODPSOLVSB),~Sy_bit(V_MODPSOLVSB)},
582  {"geometricSB",Sy_bit(V_UPTORADICAL),~Sy_bit(V_UPTORADICAL)},
583  {"findMonomials",Sy_bit(V_FINDMONOM),~Sy_bit(V_FINDMONOM)},
584  {"coefStrat",Sy_bit(V_COEFSTRAT), ~Sy_bit(V_COEFSTRAT)},
585  {"qringNF",  Sy_bit(V_QRING),     ~Sy_bit(V_QRING)},
586  {"warn",     Sy_bit(V_ALLWARN),   ~Sy_bit(V_ALLWARN)},
587  {"intersectSyz",Sy_bit(V_INTERSECT_SYZ), ~Sy_bit(V_INTERSECT_SYZ)},
588  {"intersectElim",Sy_bit(V_INTERSECT_ELIM), ~Sy_bit(V_INTERSECT_ELIM)},
589/*special for "none" and also end marker for showOption:*/
590  {"ne",         0,          0 }
591};
592
593BOOLEAN setOption(leftv res, leftv v)
594{
595  const char *n;
596  do
597  {
598    if (v->Typ()==STRING_CMD)
599    {
600      n=(const char *)v->CopyD(STRING_CMD);
601    }
602    else
603    {
604      if (v->name==NULL)
605        return TRUE;
606      if (v->rtyp==0)
607      {
608        n=v->name;
609        v->name=NULL;
610      }
611      else
612      {
613        n=omStrDup(v->name);
614      }
615    }
616
617    int i;
618
619    if(strcmp(n,"get")==0)
620    {
621      intvec *w=new intvec(2);
622      (*w)[0]=si_opt_1;
623      (*w)[1]=si_opt_2;
624      res->rtyp=INTVEC_CMD;
625      res->data=(void *)w;
626      goto okay;
627    }
628    if(strcmp(n,"set")==0)
629    {
630      if((v->next!=NULL)
631      &&(v->next->Typ()==INTVEC_CMD))
632      {
633        v=v->next;
634        intvec *w=(intvec*)v->Data();
635        si_opt_1=(*w)[0];
636        si_opt_2=(*w)[1];
637#if 0
638        if (TEST_OPT_INTSTRATEGY && (currRing!=NULL)
639        && rField_has_simple_inverse()
640        && !rField_is_Ring(currRing)
641        ) {
642          si_opt_1 &=~Sy_bit(OPT_INTSTRATEGY);
643        }
644#endif
645        goto okay;
646      }
647    }
648    if(strcmp(n,"none")==0)
649    {
650      si_opt_1=0;
651      si_opt_2=0;
652      goto okay;
653    }
654    for (i=0; (i==0) || (optionStruct[i-1].setval!=0); i++)
655    {
656      if (strcmp(n,optionStruct[i].name)==0)
657      {
658        if (optionStruct[i].setval & validOpts)
659        {
660          si_opt_1 |= optionStruct[i].setval;
661          // optOldStd disables redthrough
662          if (optionStruct[i].setval == Sy_bit(OPT_OLDSTD))
663            si_opt_1 &= ~Sy_bit(OPT_REDTHROUGH);
664        }
665        else
666          Warn("cannot set option");
667#if 0
668        if (TEST_OPT_INTSTRATEGY && (currRing!=NULL)
669        && rField_has_simple_inverse()
670        && !rField_is_Ring(currRing)
671        ) {
672          test &=~Sy_bit(OPT_INTSTRATEGY);
673        }
674#endif
675        goto okay;
676      }
677      else if ((strncmp(n,"no",2)==0)
678      && (strcmp(n+2,optionStruct[i].name)==0))
679      {
680        if (optionStruct[i].setval & validOpts)
681        {
682          si_opt_1 &= optionStruct[i].resetval;
683        }
684        else
685          Warn("cannot clear option");
686        goto okay;
687      }
688    }
689    for (i=0; (i==0) || (verboseStruct[i-1].setval!=0); i++)
690    {
691      if (strcmp(n,verboseStruct[i].name)==0)
692      {
693        si_opt_2 |= verboseStruct[i].setval;
694        #ifdef YYDEBUG
695        #if YYDEBUG
696        /*debugging the bison grammar --> grammar.cc*/
697        extern int    yydebug;
698        if (BVERBOSE(V_YACC)) yydebug=1;
699        else                  yydebug=0;
700        #endif
701        #endif
702        goto okay;
703      }
704      else if ((strncmp(n,"no",2)==0)
705      && (strcmp(n+2,verboseStruct[i].name)==0))
706      {
707        si_opt_2 &= verboseStruct[i].resetval;
708        #ifdef YYDEBUG
709        #if YYDEBUG
710        /*debugging the bison grammar --> grammar.cc*/
711        extern int    yydebug;
712        if (BVERBOSE(V_YACC)) yydebug=1;
713        else                  yydebug=0;
714        #endif
715        #endif
716        goto okay;
717      }
718    }
719    Werror("unknown option `%s`",n);
720  okay:
721    if (currRing != NULL)
722      currRing->options = si_opt_1 & TEST_RINGDEP_OPTS;
723    omFree((ADDRESS)n);
724    v=v->next;
725  } while (v!=NULL);
726
727   // set global variable to show memory usage
728  extern int om_sing_opt_show_mem;
729  if (BVERBOSE(V_SHOW_MEM)) om_sing_opt_show_mem = 1;
730  else om_sing_opt_show_mem = 0;
731
732  return FALSE;
733}
734
735char * showOption()
736{
737  int i;
738  BITSET tmp;
739
740  StringSetS("//options:");
741  if ((si_opt_1!=0)||(si_opt_2!=0))
742  {
743    tmp=si_opt_1;
744    if(tmp)
745    {
746      for (i=0; optionStruct[i].setval!=0; i++)
747      {
748        if (optionStruct[i].setval & tmp)
749        {
750          StringAppend(" %s",optionStruct[i].name);
751          tmp &=optionStruct[i].resetval;
752        }
753      }
754      for (i=0; i<32; i++)
755      {
756        if (tmp & Sy_bit(i)) StringAppend(" %d",i);
757      }
758    }
759    tmp=si_opt_2;
760    if (tmp)
761    {
762      for (i=0; verboseStruct[i].setval!=0; i++)
763      {
764        if (verboseStruct[i].setval & tmp)
765        {
766          StringAppend(" %s",verboseStruct[i].name);
767          tmp &=verboseStruct[i].resetval;
768        }
769      }
770      for (i=1; i<32; i++)
771      {
772        if (tmp & Sy_bit(i)) StringAppend(" %d",i+32);
773      }
774    }
775    return StringEndS();
776  }
777  StringAppendS(" none");
778  return StringEndS();
779}
780
781/* version strings */
782#ifdef HAVE_FLINT
783extern "C"
784{
785#ifndef __GMP_BITS_PER_MP_LIMB
786#define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS
787#endif
788#include <flint/flint.h>
789}
790#endif
791
792#ifndef MAKE_DISTRIBUTION
793const char *singular_date=__DATE__ " " __TIME__;
794#endif
795
796char * versionString(/*const bool bShowDetails = false*/ )
797{
798  StringSetS("");
799  StringAppend("Singular for %s version %s (%d, %d bit) %s #%s",
800               S_UNAME, VERSION, // SINGULAR_VERSION,
801               SINGULAR_VERSION, sizeof(void*)*8,
802#ifdef MAKE_DISTRIBUTION
803               VERSION_DATE, GIT_VERSION);
804#else
805               singular_date, GIT_VERSION);
806#endif
807  StringAppendS("\nwith\n\t");
808
809#if defined(mpir_version)
810              StringAppend("MPIR(%s)~GMP(%s),", mpir_version, gmp_version);
811#elif defined(gmp_version)
812              // #if defined (__GNU_MP_VERSION) && defined (__GNU_MP_VERSION_MINOR)
813              //              StringAppend("GMP(%d.%d),",__GNU_MP_VERSION,__GNU_MP_VERSION_MINOR);
814              StringAppend("GMP(%s),", gmp_version);
815#endif
816#ifdef HAVE_NTL
817#include <NTL/version.h>
818              StringAppend("NTL(%s),",NTL_VERSION);
819#endif
820
821#ifdef HAVE_FLINT
822              StringAppend("FLINT(%s),",version);
823#endif
824              StringAppendS("factory(" FACTORYVERSION "),\n\t");
825#if defined(HAVE_DYN_RL)
826              if (fe_fgets_stdin==fe_fgets_dummy)
827                StringAppendS("no input,");
828              else if (fe_fgets_stdin==fe_fgets)
829                StringAppendS("fgets,");
830              if (fe_fgets_stdin==fe_fgets_stdin_drl)
831                StringAppend("dynamic readline%d),",RL_VERSION_MAJOR);
832              #ifdef HAVE_FEREAD
833              else if (fe_fgets_stdin==fe_fgets_stdin_emu)
834                StringAppendS("emulated readline,");
835              #endif
836              else
837                StringAppendS("unknown fgets method,");
838#else
839  #if defined(HAVE_READLINE) && !defined(FEREAD)
840              StringAppend("static readline(%d),",RL_VERSION_MAJOR);
841  #else
842    #ifdef HAVE_FEREAD
843              StringAppendS("emulated readline,");
844    #else
845              StringAppendS("fgets,");
846    #endif
847  #endif
848#endif
849#ifdef HAVE_PLURAL
850              StringAppendS("Plural,");
851#endif
852#ifdef HAVE_DBM
853              StringAppendS("DBM,\n\t");
854#else
855              StringAppendS("\n\t");
856#endif
857#ifdef HAVE_DYNAMIC_LOADING
858              StringAppendS("dynamic modules,");
859#endif
860              if (p_procs_dynamic) StringAppendS("dynamic p_Procs,");
861#if YYDEBUG
862              StringAppendS("YYDEBUG=1,");
863#endif
864#ifdef HAVE_ASSUME
865             StringAppendS("ASSUME,");
866#endif
867#ifdef MDEBUG
868              StringAppend("MDEBUG=%d,",MDEBUG);
869#endif
870#ifdef OM_CHECK
871              StringAppend("OM_CHECK=%d,",OM_CHECK);
872#endif
873#ifdef OM_TRACK
874              StringAppend("OM_TRACK=%d,",OM_TRACK);
875#endif
876#ifdef OM_NDEBUG
877              StringAppendS("OM_NDEBUG,");
878#endif
879#ifdef SING_NDEBUG
880              StringAppendS("SING_NDEBUG,");
881#endif
882#ifdef PDEBUG
883              StringAppendS("PDEBUG,");
884#endif
885#ifdef KDEBUG
886              StringAppendS("KDEBUG,");
887#endif
888#ifdef __OPTIMIZE__
889              StringAppendS("CC:OPTIMIZE,");
890#endif
891#ifdef __OPTIMIZE_SIZE__
892              StringAppendS("CC:OPTIMIZE_SIZE,");
893#endif
894#ifdef __NO_INLINE__
895              StringAppendS("CC:NO_INLINE,");
896#endif
897#ifdef HAVE_EIGENVAL
898              StringAppendS("eigenvalues,");
899#endif
900#ifdef HAVE_GMS
901              StringAppendS("Gauss-Manin system,");
902#endif
903#ifdef HAVE_RATGRING
904              StringAppendS("ratGB,");
905#endif
906              StringAppend("random=%d\n",siRandomStart);
907
908#define SI_SHOW_BUILTIN_MODULE(name) StringAppend(" %s", #name);
909              StringAppendS("built-in modules: {");
910              SI_FOREACH_BUILTIN(SI_SHOW_BUILTIN_MODULE)
911              StringAppendS("}\n");
912#undef SI_SHOW_BUILTIN_MODULE
913
914              StringAppend("AC_CONFIGURE_ARGS = %s,\n"
915                           "CC = %s,FLAGS : %s,\n"
916                           "CXX = %s,FLAGS : %s,\n"
917                           "DEFS : %s,CPPFLAGS : %s,\n"
918                           "LDFLAGS : %s,LIBS : %s "
919#ifdef __GNUC__
920              "(ver: " __VERSION__ ")"
921#endif
922              "\n",AC_CONFIGURE_ARGS, CC,CFLAGS, CXX,CXXFLAGS,  DEFS,CPPFLAGS,  LDFLAGS,LIBS);
923              feStringAppendResources(0);
924              feStringAppendBrowsers(0);
925              StringAppendS("\n");
926              return StringEndS();
927}
928
929#ifdef PDEBUG
930#if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM)
931void p_SetRingOfLeftv(leftv l, ring r)
932{
933  switch(l->rtyp)
934  {
935    case INT_CMD:
936    case BIGINT_CMD:
937    case IDHDL:
938    case DEF_CMD:
939      break;
940    case POLY_CMD:
941    case VECTOR_CMD:
942    {
943      poly p=(poly)l->data;
944      while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); }
945      break;
946    }
947    case IDEAL_CMD:
948    case MODUL_CMD:
949    case MATRIX_CMD:
950    {
951      ideal I=(ideal)l->data;
952      int i;
953      for(i=IDELEMS(I)-1;i>=0;i--)
954      {
955        poly p=I->m[i];
956        while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); }
957      }
958      break;
959    }
960    case COMMAND:
961    {
962      command d=(command)l->data;
963      p_SetRingOfLeftv(&d->arg1, r);
964      if (d->argc>1) p_SetRingOfLeftv(&d->arg2, r);
965      if (d->argc>2) p_SetRingOfLeftv(&d->arg3, r);
966      break;
967    }
968    default:
969     printf("type %d not yet implementd in p_SetRingOfLeftv\n",l->rtyp);
970     break;
971  }
972}
973#endif
974#endif
975
976#if 0 /* debug only */
977void listall(int showproc)
978{
979      idhdl hh=basePack->idroot;
980      PrintS("====== Top ==============\n");
981      while (hh!=NULL)
982      {
983        if (showproc || (IDTYP(hh)!=PROC_CMD))
984        {
985          if (IDDATA(hh)==(void *)currRing) PrintS("(R)");
986          else if (IDDATA(hh)==(void *)currPack) PrintS("(P)");
987          else PrintS("   ");
988          Print("::%s, typ %s level %d data %lx",
989                 IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh));
990          if (IDTYP(hh)==RING_CMD)
991            Print(" ref: %d\n",IDRING(hh)->ref);
992          else
993            PrintLn();
994        }
995        hh=IDNEXT(hh);
996      }
997      hh=basePack->idroot;
998      while (hh!=NULL)
999      {
1000        if (IDDATA(hh)==(void *)basePack)
1001          Print("(T)::%s, typ %s level %d data %lx\n",
1002          IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh));
1003        else
1004        if ((IDTYP(hh)==RING_CMD)
1005        || (IDTYP(hh)==PACKAGE_CMD))
1006        {
1007          Print("====== %s ==============\n",IDID(hh));
1008          idhdl h2=IDRING(hh)->idroot;
1009          while (h2!=NULL)
1010          {
1011            if (showproc || (IDTYP(h2)!=PROC_CMD))
1012            {
1013              if ((IDDATA(h2)==(void *)currRing)
1014              && (IDTYP(h2)==RING_CMD))
1015                PrintS("(R)");
1016              else if (IDDATA(h2)==(void *)currPack) PrintS("(P)");
1017              else PrintS("   ");
1018              Print("%s::%s, typ %s level %d data %lx\n",
1019              IDID(hh),IDID(h2),Tok2Cmdname(IDTYP(h2)),IDLEV(h2),(long)IDDATA(h2));
1020            }
1021            h2=IDNEXT(h2);
1022          }
1023        }
1024        hh=IDNEXT(hh);
1025      }
1026      Print("currRing:%lx, currPack:%lx,basePack:%lx\n",(long)currRing,(long)currPack,(long)basePack);
1027      iiCheckPack(currPack);
1028}
1029#endif
1030
1031#ifndef SING_NDEBUG
1032void checkall()
1033{
1034      idhdl hh=basePack->idroot;
1035      while (hh!=NULL)
1036      {
1037        omCheckAddr(hh);
1038        omCheckAddr((ADDRESS)IDID(hh));
1039        if (RingDependend(IDTYP(hh)))
1040        {
1041          Print("%s typ %d in Top (should be in ring)\n",IDID(hh),IDTYP(hh));
1042        }
1043        hh=IDNEXT(hh);
1044      }
1045      hh=basePack->idroot;
1046      while (hh!=NULL)
1047      {
1048        if (IDTYP(hh)==PACKAGE_CMD)
1049        {
1050          idhdl h2=NULL;
1051          if (IDPACKAGE(hh)!=NULL)
1052            h2=IDPACKAGE(hh)->idroot;
1053          if (IDPACKAGE(hh)!=basePack)
1054          {
1055            while (h2!=NULL)
1056            {
1057              omCheckAddr(h2);
1058              omCheckAddr((ADDRESS)IDID(h2));
1059              if (RingDependend(IDTYP(h2)))
1060              {
1061                Print("%s typ %d in %s (should be in ring)\n",IDID(h2),IDTYP(h2),IDID(hh));
1062              }
1063              h2=IDNEXT(h2);
1064            }
1065          }
1066        }
1067        hh=IDNEXT(hh);
1068      }
1069}
1070#endif
1071
1072#include <sys/types.h>
1073#include <sys/stat.h>
1074#include <unistd.h>
1075
1076extern "C"
1077int singular_fstat(int fd, struct stat *buf)
1078{
1079  return si_fstat(fd,buf);
1080}
1081
1082/*2
1083* the global exit routine of Singular
1084*/
1085extern "C" {
1086/* Note: We cannot use a mutex here because mutexes are not async-safe, but
1087 * m2_end is called by sig_term_hdl(). Anyway, the race condition in the first
1088 * few lines of m2_end() should not matter.
1089 */
1090volatile BOOLEAN m2_end_called = FALSE;
1091
1092void m2_end(int i)
1093{
1094  if (!m2_end_called)
1095  {
1096    extern FILE* File_Profiling;
1097    if (File_Profiling!=NULL) { fclose(File_Profiling); File_Profiling=NULL; }
1098    m2_end_called = TRUE;
1099#ifdef HAVE_SIMPLEIPC
1100    for (int j = SIPC_MAX_SEMAPHORES-1; j >= 0; j--)
1101    {
1102      if (semaphore[j] != NULL)
1103      {
1104        while (sem_acquired[j] > 0)
1105        {
1106#if PORTABLE_SEMAPHORES
1107          sem_post(semaphore[j]->sig);
1108#else
1109          sem_post(semaphore[j]);
1110#endif
1111          sem_acquired[j]--;
1112        }
1113      }
1114    }
1115#endif   // HAVE_SIMPLEIPC
1116    fe_reset_input_mode();
1117    monitor(NULL,0);
1118#ifdef PAGE_TEST
1119    mmEndStat();
1120#endif
1121    fe_reset_input_mode();
1122    if (ssiToBeClosed_inactive)
1123    {
1124      link_list hh=ssiToBeClosed;
1125      while(hh!=NULL)
1126      {
1127        //Print("close %s\n",hh->l->name);
1128        slPrepClose(hh->l);
1129        hh=(link_list)hh->next;
1130      }
1131      ssiToBeClosed_inactive=FALSE;
1132
1133      idhdl h = currPack->idroot;
1134      while(h != NULL)
1135      {
1136        if(IDTYP(h) == LINK_CMD)
1137        {
1138          idhdl hh=h->next;
1139          //Print("kill %s\n",IDID(h));
1140          killhdl(h, currPack);
1141          h = hh;
1142        }
1143        else
1144        {
1145          h = h->next;
1146        }
1147      }
1148      hh=ssiToBeClosed;
1149      while(hh!=NULL)
1150      {
1151        //Print("close %s\n",hh->l->name);
1152        slClose(hh->l);
1153        hh=ssiToBeClosed;
1154      }
1155    }
1156    if (!singular_in_batchmode)
1157    {
1158      if (i<=0)
1159      {
1160        //extern long all_farey;
1161        //extern long farey_cnt;
1162        //if (all_farey!=0L) printf("farey:%ld, cnt=%ld\n",all_farey,farey_cnt);
1163        if (TEST_V_QUIET)
1164        {
1165          if (i==0)
1166            printf("Auf Wiedersehen.\n");
1167          else
1168            printf("\n$Bye.\n");
1169        }
1170        //#ifdef sun
1171        //  #ifndef __svr4__
1172        //    _cleanup();
1173        //    _exit(0);
1174        //  #endif
1175        //#endif
1176        i=0;
1177      }
1178      else
1179      {
1180        printf("\nhalt %d\n",i);
1181      }
1182    }
1183    exit(i);
1184  }
1185}
1186}
1187
1188extern "C"
1189{
1190  void omSingOutOfMemoryFunc()
1191  {
1192    fprintf(stderr, "\nSingular error: no more memory\n");
1193    omPrintStats(stderr);
1194    m2_end(14);
1195    /* should never get here */
1196    exit(1);
1197  }
1198}
1199
1200#ifdef SINGULAR_4_2
1201static n_coeffType n_pAE=n_unknown;
1202static BOOLEAN ii_pAE_init(leftv res,leftv a)
1203{
1204  if (a->Typ()!=INT_CMD)
1205  {
1206    WerrorS("`int` expected");
1207    return TRUE;
1208  }
1209  else
1210  {
1211    res->rtyp=CRING_CMD;
1212    res->data=(void*)nInitChar(n_pAE,(void*)a->Data());
1213    return FALSE;
1214  }
1215}
1216#endif
1217#ifdef HAVE_FLINT
1218static n_coeffType n_FlintZn=n_unknown;
1219static BOOLEAN ii_FlintZn_init(leftv res,leftv a)
1220{
1221  if ((a->Typ()!=INT_CMD)
1222  ||(a->next==NULL)
1223  ||(a->next->Typ()!=STRING_CMD))
1224  {
1225    WerrorS("`int`i,`string` expected");
1226    return TRUE;
1227  }
1228  else
1229  {
1230    flintZn_struct p;
1231    p.ch=(int)(long)a->Data();
1232    p.name=(char*)a->next->Data();
1233    res->rtyp=CRING_CMD;
1234    res->data=(void*)nInitChar(n_FlintZn,(void*)&p);
1235    return FALSE;
1236  }
1237}
1238#endif
1239
1240static BOOLEAN iiFloat(leftv res, leftv pnn)
1241{
1242  short float_len=3;
1243  short float_len2=SHORT_REAL_LENGTH;
1244  coeffs cf=NULL;
1245  if ((pnn!=NULL) && (pnn->Typ()==INT_CMD))
1246  {
1247    float_len=(int)(long)pnn->Data();
1248    float_len2=float_len;
1249    pnn=pnn->next;
1250    if ((pnn!=NULL) && (pnn->Typ()==INT_CMD))
1251    {
1252      float_len2=(int)(long)pnn->Data();
1253      pnn=pnn->next;
1254    }
1255  }
1256  if (float_len2 <= (short)SHORT_REAL_LENGTH)
1257       cf=nInitChar(n_R, NULL);
1258  else // longR or longC?
1259  {
1260    LongComplexInfo param;
1261    param.float_len = si_min (float_len, 32767);
1262    param.float_len2 = si_min (float_len2, 32767);
1263    cf = nInitChar(n_long_R, (void*)&param);
1264  }
1265  res->rtyp=CRING_CMD;
1266  res->data=cf;
1267  return cf==NULL;
1268}
1269static BOOLEAN iiCrossProd(leftv res, leftv args)
1270{
1271  leftv h=args;
1272  coeffs *c=NULL;
1273  coeffs cf=NULL;
1274  int i=0;
1275  if (h==NULL) goto crossprod_error;
1276  while (h!=NULL)
1277  {
1278    if (h->Typ()!=CRING_CMD) goto crossprod_error;
1279    i++;
1280    h=h->next;
1281  }
1282  c=(coeffs*)omAlloc0((i+1)*sizeof(coeffs));
1283  h=args;
1284  i=0;
1285  while (h!=NULL)
1286  {
1287    c[i]=(coeffs)h->CopyD();
1288    i++;
1289    h=h->next;
1290  }
1291  cf=nInitChar(n_nTupel,c);
1292  res->data=cf;
1293  res->rtyp=CRING_CMD;
1294  return FALSE;
1295
1296  crossprod_error:
1297    WerrorS("expected `crossprod(coeffs, ...)`");
1298    return TRUE;
1299}
1300/*2
1301* initialize components of Singular
1302*/
1303void siInit(char *name)
1304{
1305// factory default settings: -----------------------------------------------
1306  On(SW_USE_EZGCD);
1307  On(SW_USE_CHINREM_GCD);
1308  //On(SW_USE_FF_MOD_GCD);
1309  On(SW_USE_EZGCD_P);
1310  On(SW_USE_QGCD);
1311  Off(SW_USE_NTL_SORT); // may be changed by an command line option
1312  factoryError=WerrorS;
1313
1314// NTL error handling (>= 9.3.0)
1315#ifdef HAVE_NTL
1316#if (((NTL_MAJOR_VERSION==9)&&(NTL_MINOR_VERSION>=3))||(NTL_MAJOR_VERSION>=10))
1317  ErrorMsgCallback=WerrorS;
1318  ErrorCallback=HALT;
1319#endif
1320#endif
1321
1322// memory initialization: -----------------------------------------------
1323    om_Opts.OutOfMemoryFunc = omSingOutOfMemoryFunc;
1324#ifndef OM_NDEBUG
1325#ifndef __OPTIMIZE__
1326    om_Opts.ErrorHook = dErrorBreak;
1327#else
1328    om_Opts.Keep = 0; /* !OM_NDEBUG, __OPTIMIZE__*/
1329#endif
1330#else
1331    om_Opts.Keep = 0; /* OM_NDEBUG */
1332#endif
1333    omInitInfo();
1334
1335// options ---------------------------------------------------------------
1336  si_opt_1=0;
1337// interpreter tables etc.: -----------------------------------------------
1338  memset(&sLastPrinted,0,sizeof(sleftv));
1339  sLastPrinted.rtyp=NONE;
1340
1341  extern int iiInitArithmetic(); iiInitArithmetic(); // iparith.cc
1342
1343  basePack=(package)omAlloc0(sizeof(*basePack));
1344  currPack=basePack;
1345  idhdl h;
1346  h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, FALSE);
1347  IDPACKAGE(h)=basePack;
1348  IDPACKAGE(h)->language = LANG_TOP;
1349  currPackHdl=h;
1350  basePackHdl=h;
1351
1352  coeffs_BIGINT = nInitChar(n_Q,(void*)1);
1353
1354#if 1
1355   // def HAVE_POLYEXTENSIONS
1356  if(TRUE)
1357  {
1358    n_coeffType type;
1359    #ifdef SINGULAR_4_2
1360    type = nRegister(n_polyExt, n2pInitChar);
1361    assume(type == n_polyExt);
1362    #endif
1363
1364    type = nRegister(n_algExt, naInitChar);
1365    assume(type == n_algExt);
1366
1367    type = nRegister(n_transExt, ntInitChar);
1368    assume(type == n_transExt);
1369
1370    (void)type;
1371  }
1372#endif
1373
1374// random generator: -----------------------------------------------
1375  int t=initTimer();
1376  if (t==0) t=1;
1377  initRTimer();
1378  siSeed=t;
1379  factoryseed(t);
1380  siRandomStart=t;
1381  feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart);
1382
1383// ressource table: ----------------------------------------------------
1384  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
1385  // hack such that all shared' libs in the bindir are loaded correctly
1386  feInitResources(name);
1387
1388// singular links: --------------------------------------------------
1389  slStandardInit();
1390  myynest=0;
1391// how many processes ? -----------------------------------------------------
1392  int cpus=2;
1393  int cpu_n;
1394  #ifdef _SC_NPROCESSORS_ONLN
1395  if ((cpu_n=sysconf(_SC_NPROCESSORS_ONLN))>cpus) cpus=cpu_n;
1396  #elif defined(_SC_NPROCESSORS_CONF)
1397  if ((cpu_n=sysconf(_SC_NPROCESSORS_CONF))>cpus) cpus=cpu_n;
1398  #endif
1399  feSetOptValue(FE_OPT_CPUS, cpus);
1400// how many threads ? -----------------------------------------------------
1401  feSetOptValue(FE_OPT_THREADS, cpus);
1402
1403// default coeffs
1404  {
1405    idhdl h;
1406    h=enterid("QQ",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1407    IDDATA(h)=(char*)nInitChar(n_Q,NULL);
1408    h=enterid("ZZ",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1409    IDDATA(h)=(char*)nInitChar(n_Z,NULL);
1410    iiAddCproc("kernel","crossprod",FALSE,iiCrossProd);
1411    iiAddCproc("kernel","Float",FALSE,iiFloat);
1412    //h=enterid("RR",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1413    //IDDATA(h)=(char*)nInitChar(n_R,NULL);
1414    //h=enterid("CC",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1415    //IDDATA(h)=(char*)nInitChar(n_long_C,NULL);
1416    n_coeffType t;
1417#ifdef SINGULAR_4_2
1418    t=nRegister(n_unknown,n_AEInitChar);
1419    if (t!=n_unknown)
1420    {
1421      h=enterid("AE",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1422      IDDATA(h)=(char*)nInitChar(t,NULL);
1423    }
1424    t=nRegister(n_unknown,n_QAEInitChar);
1425    if (t!=n_unknown)
1426    {
1427      h=enterid("QAE",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1428      IDDATA(h)=(char*)nInitChar(t,NULL);
1429    }
1430    n_pAE=nRegister(n_unknown,n_pAEInitChar);
1431    if (n_pAE!=n_unknown)
1432    {
1433      iiAddCproc("kernel","pAE",FALSE,ii_pAE_init);
1434    }
1435#endif
1436    #ifdef HAVE_FLINT
1437    t=nRegister(n_unknown,flintQ_InitChar);
1438    if (t!=n_unknown)
1439    {
1440      h=enterid("flint_poly_Q",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1441      IDDATA(h)=(char*)nInitChar(t,NULL);
1442    }
1443    n_FlintZn=nRegister(n_unknown,flintZn_InitChar);
1444    if (n_FlintZn!=n_unknown)
1445    {
1446      iiAddCproc("kernel","flintZ",FALSE,ii_FlintZn_init);
1447    }
1448    #endif
1449  }
1450// setting routines for PLURAL QRINGS:
1451// allowing to use libpolys without libSingular(kStd)
1452#ifdef HAVE_PLURAL
1453  nc_NF=k_NF;
1454  gnc_gr_bba=k_gnc_gr_bba;
1455  gnc_gr_mora=k_gnc_gr_mora;
1456  sca_bba=k_sca_bba;
1457  sca_mora=k_sca_mora;
1458  sca_gr_bba=k_sca_gr_bba;
1459#endif
1460// loading standard.lib -----------------------------------------------
1461  if (! feOptValue(FE_OPT_NO_STDLIB))
1462  {
1463    BITSET save1,save2;
1464    SI_SAVE_OPT(save1,save2);
1465    si_opt_2 &= ~Sy_bit(V_LOAD_LIB);
1466    iiLibCmd(omStrDup("standard.lib"), TRUE,TRUE,TRUE);
1467    SI_RESTORE_OPT(save1,save2);
1468  }
1469  errorreported = 0;
1470}
Note: See TracBrowser for help on using the repository browser.