source: git/Singular/misc_ip.cc @ 4dc97b

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