source: git/Singular/misc_ip.cc @ 01bc36

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