source: git/Singular/misc_ip.cc @ 54b24c

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