source: git/Singular/misc_ip.cc @ 2443ced

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