source: git/Singular/misc_ip.cc @ 9ba310

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