misc_ip.cc
Go to the documentation of this file.
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 
36 #include "polys/nc/gb_hack.h"
37 
38 #ifdef HAVE_SIMPLEIPC
40 #endif
41 
42 #include "misc_ip.h"
43 #include "ipid.h"
44 #include "feOpt.h"
45 #include "links/silink.h"
46 #include "mod_lib.h"
47 #include "Singular/distrib.h"
48 
49 #include "misc/options.h"
50 #include "misc/intvec.h"
51 
52 #include "polys/monomials/ring.h"
54 
55 #include "kernel/GBEngine/kstd1.h"
56 #include "kernel/oswrapper/timer.h"
57 #include "resources/feResource.h"
59 
60 #include "subexpr.h"
61 #include "cntrlc.h"
62 #include "ipshell.h"
63 
64 #include "fehelp.h"
65 
66 #ifdef HAVE_READLINE
67  #ifdef READLINE_READLINE_H_OK
68  #include <readline/readline.h>
69  #endif
70  #ifndef RL_VERSION_MAJOR
71  #define RL_VERSION_MAJOR 0
72  #endif
73 #endif
74 
75 #ifdef HAVE_NTL
76 #include <NTL/version.h>
77 #include <NTL/tools.h>
78 #ifdef NTL_CLIENT
79 NTL_CLIENT
80 #endif
81 #endif
82 
83 
84 static FORCE_INLINE void number2mpz(number n, mpz_t m){ number2mpz(n, coeffs_BIGINT, m); }
85 static FORCE_INLINE number mpz2number(mpz_t m){ return mpz2number(m, coeffs_BIGINT); }
86 
87 
88 void setListEntry(lists L, int index, mpz_t n)
89 { /* assumes n > 0 */
90  /* try to fit nn into an int: */
91  if (mpz_size1(n)<=1)
92  {
93  int ui=(int)mpz_get_si(n);
94  if ((((ui<<3)>>3)==ui)
95  && (mpz_cmp_si(n,(long)ui)==0))
96  {
97  L->m[index].rtyp = INT_CMD; L->m[index].data = (void*)(long)ui;
98  return;
99  }
100  }
101  number nn = mpz2number(n);
102  L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn;
103 }
104 
105 void setListEntry_ui(lists L, int index, unsigned long ui)
106 { /* assumes n > 0 */
107  /* try to fit nn into an int: */
108  int i=(int)ui;
109  if ((((unsigned long)i)==ui) && (((i<<3)>>3)==i))
110  {
111  L->m[index].rtyp = INT_CMD; L->m[index].data = (void*)(long)i;
112  }
113  else
114  {
115  number nn = n_Init(ui, coeffs_BIGINT);
116  L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn;
117  }
118 }
119 
120 /* Factoring with Pollard's rho method. stolen from GMP/demos */
121 static unsigned add[] = {4, 2, 4, 2, 4, 6, 2, 6};
122 
123 static int factor_using_division (mpz_t t, unsigned int limit,lists primes, int *multiplicities,int &index, unsigned long bound)
124 {
125  mpz_t q, r;
126  unsigned long int f;
127  int ai;
128  unsigned *addv = add;
129  unsigned int failures;
130  int bound_not_reached=1;
131 
132  mpz_init (q);
133  mpz_init (r);
134 
135  f = mpz_scan1 (t, 0);
136  mpz_div_2exp (t, t, f);
137  if (f>0)
138  {
139  setListEntry_ui(primes, index, 2);
140  multiplicities[index++] = f;
141  }
142 
143  f=0;
144  loop
145  {
146  mpz_tdiv_qr_ui (q, r, t, 3);
147  if (mpz_sgn1 (r) != 0)
148  break;
149  mpz_set (t, q);
150  f++;
151  }
152  if (f>0)
153  {
154  setListEntry_ui(primes, index, 3);
155  multiplicities[index++] = f;
156  }
157  f=0;
158  loop
159  {
160  mpz_tdiv_qr_ui (q, r, t, 5);
161  if (mpz_sgn1 (r) != 0)
162  break;
163  mpz_set (t, q);
164  f++;
165  }
166  if (f>0)
167  {
168  setListEntry_ui(primes, index, 5);
169  multiplicities[index++] = f;
170  }
171 
172  failures = 0;
173  f = 7;
174  ai = 0;
175  unsigned long last_f=0;
176  while (mpz_cmp_ui (t, 1) != 0)
177  {
178  mpz_tdiv_qr_ui (q, r, t, f);
179  if (mpz_sgn1 (r) != 0)
180  {
181  f += addv[ai];
182  if (mpz_cmp_ui (t, f) < 0)
183  break;
184  ai = (ai + 1) & 7;
185  failures++;
186  if (failures > limit)
187  break;
188  if ((bound!=0) && (f>bound))
189  {
190  bound_not_reached=0;
191  break;
192  }
193  }
194  else
195  {
196  mpz_swap (t, q);
197  if (f!=last_f)
198  {
199  setListEntry_ui(primes, index, f);
200  multiplicities[index]++;
201  index++;
202  }
203  else
204  {
205  multiplicities[index-1]++;
206  }
207  last_f=f;
208  failures = 0;
209  }
210  }
211 
212  mpz_clear (q);
213  mpz_clear (r);
214  //printf("bound=%d,f=%d,failures=%d, reached=%d\n",bound,f,failures,bound_not_reached);
215  return bound_not_reached;
216 }
217 
218 static void factor_using_pollard_rho (mpz_t n, unsigned long a, lists primes, int * multiplicities,int &index)
219 {
220  mpz_t x, x1, y, P;
221  mpz_t t1, t2;
222  mpz_t last_f;
223  unsigned long long k, l, i;
224 
225  mpz_init (t1);
226  mpz_init (t2);
227  mpz_init_set_ui (last_f, 0);
228  mpz_init_set_ui (y, 2);
229  mpz_init_set_ui (x, 2);
230  mpz_init_set_ui (x1, 2);
231  mpz_init_set_ui (P, 1);
232  k = 1;
233  l = 1;
234 
235  while (mpz_cmp_ui (n, 1) != 0)
236  {
237  loop
238  {
239  do
240  {
241  mpz_mul (t1, x, x);
242  mpz_mod (x, t1, n);
243  mpz_add_ui (x, x, a);
244  mpz_sub (t1, x1, x);
245  mpz_mul (t2, P, t1);
246  mpz_mod (P, t2, n);
247 
248  if (k % 32 == 1)
249  {
250  mpz_gcd (t1, P, n);
251  if (mpz_cmp_ui (t1, 1) != 0)
252  goto factor_found;
253  mpz_set (y, x);
254  }
255  }
256  while (--k != 0);
257 
258  mpz_gcd (t1, P, n);
259  if (mpz_cmp_ui (t1, 1) != 0)
260  goto factor_found;
261 
262  mpz_set (x1, x);
263  k = l;
264  l = 2 * l;
265  for (i = 0; i < k; i++)
266  {
267  mpz_mul (t1, x, x);
268  mpz_mod (x, t1, n);
269  mpz_add_ui (x, x, a);
270  }
271  mpz_set (y, x);
272  }
273 
274  factor_found:
275  do
276  {
277  mpz_mul (t1, y, y);
278  mpz_mod (y, t1, n);
279  mpz_add_ui (y, y, a);
280  mpz_sub (t1, x1, y);
281  mpz_gcd (t1, t1, n);
282  }
283  while (mpz_cmp_ui (t1, 1) == 0);
284 
285  mpz_divexact (n, n, t1); /* divide by t1, before t1 is overwritten */
286 
287  if (!mpz_probab_prime_p (t1, 10))
288  {
289  do
290  {
291  mp_limb_t a_limb;
292  mpn_random (&a_limb, (mp_size_t) 1);
293  a = a_limb;
294  }
295  while (a == 0);
296 
297  factor_using_pollard_rho (t1, a, primes,multiplicities,index);
298  }
299  else
300  {
301  if (mpz_cmp(t1,last_f)==0)
302  {
303  multiplicities[index-1]++;
304  }
305  else
306  {
307  mpz_set(last_f,t1);
308  setListEntry(primes, index, t1);
309  multiplicities[index++] = 1;
310  }
311  }
312  mpz_mod (x, x, n);
313  mpz_mod (x1, x1, n);
314  mpz_mod (y, y, n);
315  if (mpz_probab_prime_p (n, 10))
316  {
317  if (mpz_cmp(n,last_f)==0)
318  {
319  multiplicities[index-1]++;
320  }
321  else
322  {
323  mpz_set(last_f,n);
324  setListEntry(primes, index, n);
325  multiplicities[index++] = 1;
326  }
327  mpz_set_ui(n,1);
328  break;
329  }
330  }
331 
332  mpz_clear (P);
333  mpz_clear (t2);
334  mpz_clear (t1);
335  mpz_clear (x1);
336  mpz_clear (x);
337  mpz_clear (y);
338  mpz_clear (last_f);
339 }
340 
341 static void factor_gmp (mpz_t t,lists primes,int *multiplicities,int &index,unsigned long bound)
342 {
343  unsigned int division_limit;
344 
345  if (mpz_sgn (t) == 0)
346  return;
347 
348  /* Set the trial division limit according the size of t. */
349  division_limit = mpz_sizeinbase (t, 2);
350  if (division_limit > 1000)
351  division_limit = 1000 * 1000;
352  else
353  division_limit = division_limit * division_limit;
354 
355  if (factor_using_division (t, division_limit,primes,multiplicities,index,bound))
356  {
357  if (mpz_cmp_ui (t, 1) != 0)
358  {
359  if (mpz_probab_prime_p (t, 10))
360  {
361  setListEntry(primes, index, t);
362  multiplicities[index++] = 1;
363  mpz_set_ui(t,1);
364  }
365  else
366  factor_using_pollard_rho (t, 1L, primes,multiplicities,index);
367  }
368  }
369 }
370 /* n and pBound are assumed to be bigint numbers */
371 lists primeFactorisation(const number n, const int pBound)
372 {
373  int i;
374  int index=0;
375  mpz_t nn; number2mpz(n, nn);
376  lists primes = (lists)omAllocBin(slists_bin); primes->Init(1000);
377  int* multiplicities = (int*)omAlloc0(1000*sizeof(int));
378  int positive=1;
379 
380  if (!n_IsZero(n, coeffs_BIGINT))
381  {
382  if (!n_GreaterZero(n, coeffs_BIGINT))
383  {
384  positive=-1;
385  mpz_neg(nn,nn);
386  }
387  factor_gmp(nn,primes,multiplicities,index,pBound);
388  }
389 
390  lists primesL = (lists)omAllocBin(slists_bin);
391  primesL->Init(index);
392  for (i = 0; i < index; i++)
393  {
394  primesL->m[i].rtyp = primes->m[i].rtyp;
395  primesL->m[i].data = primes->m[i].data;
396  primes->m[i].rtyp=0;
397  primes->m[i].data=NULL;
398  }
399  primes->Clean(NULL);
400 
401  lists multiplicitiesL = (lists)omAllocBin(slists_bin);
402  multiplicitiesL->Init(index);
403  for (i = 0; i < index; i++)
404  {
405  multiplicitiesL->m[i].rtyp = INT_CMD;
406  multiplicitiesL->m[i].data = (void*)(long)multiplicities[i];
407  }
408  omFree(multiplicities);
409 
411  L->Init(3);
412  if (positive==-1) mpz_neg(nn,nn);
413  L->m[0].rtyp = LIST_CMD; L->m[0].data = (void*)primesL;
414  L->m[1].rtyp = LIST_CMD; L->m[1].data = (void*)multiplicitiesL;
415  setListEntry(L, 2, nn);
416 
417  mpz_clear(nn);
418 
419  return L;
420 }
421 
422 #ifdef HAVE_STATIC
423 #undef HAVE_DYN_RL
424 #endif
425 
426 //#ifdef HAVE_LIBPARSER
427 //# include "libparse.h"
428 //#endif /* HAVE_LIBPARSER */
429 
430 
431 /*2
432 * the renice routine for very large jobs
433 * works only on unix machines,
434 * testet on : linux, HP 9.0
435 *
436 *#include <sys/times.h>
437 *#include <sys/resource.h>
438 *extern "C" int setpriority(int,int,int);
439 *void very_nice()
440 *{
441 *#ifndef NO_SETPRIORITY
442 * setpriority(PRIO_PROCESS,0,19);
443 *#endif
444 * sleep(10);
445 *}
446 */
447 
448 void singular_example(char *str)
449 {
450  assume(str!=NULL);
451  char *s=str;
452  while (*s==' ') s++;
453  char *ss=s;
454  while (*ss!='\0') ss++;
455  while (*ss<=' ')
456  {
457  *ss='\0';
458  ss--;
459  }
460  idhdl h=IDROOT->get(s,myynest);
461  if ((h!=NULL) && (IDTYP(h)==PROC_CMD))
462  {
463  char *lib=iiGetLibName(IDPROC(h));
464  if((lib!=NULL)&&(*lib!='\0'))
465  {
466  Print("// proc %s from lib %s\n",s,lib);
467  s=iiGetLibProcBuffer(IDPROC(h), 2);
468  if (s!=NULL)
469  {
470  if (strlen(s)>5)
471  {
472  iiEStart(s,IDPROC(h));
473  omFree((ADDRESS)s);
474  return;
475  }
476  else omFree((ADDRESS)s);
477  }
478  }
479  }
480  else
481  {
482  char sing_file[MAXPATHLEN];
483  FILE *fd=NULL;
484  char *res_m=feResource('m', 0);
485  if (res_m!=NULL)
486  {
487  sprintf(sing_file, "%s/%s.sing", res_m, s);
488  fd = feFopen(sing_file, "r");
489  }
490  if (fd != NULL)
491  {
492 
493  int old_echo = si_echo;
494  int length, got;
495  char* s;
496 
497  fseek(fd, 0, SEEK_END);
498  length = ftell(fd);
499  fseek(fd, 0, SEEK_SET);
500  s = (char*) omAlloc((length+20)*sizeof(char));
501  got = fread(s, sizeof(char), length, fd);
502  fclose(fd);
503  if (got != length)
504  {
505  Werror("Error while reading file %s", sing_file);
506  }
507  else
508  {
509  s[length] = '\0';
510  strcat(s, "\n;return();\n\n");
511  si_echo = 2;
512  iiEStart(s, NULL);
513  si_echo = old_echo;
514  }
515  omFree(s);
516  }
517  else
518  {
519  Werror("no example for %s", str);
520  }
521  }
522 }
523 
524 
526 {
527  {"prot", Sy_bit(OPT_PROT), ~Sy_bit(OPT_PROT) },
528  {"redSB", Sy_bit(OPT_REDSB), ~Sy_bit(OPT_REDSB) },
529  {"notBuckets", Sy_bit(OPT_NOT_BUCKETS), ~Sy_bit(OPT_NOT_BUCKETS) },
530  {"notSugar", Sy_bit(OPT_NOT_SUGAR), ~Sy_bit(OPT_NOT_SUGAR) },
531  {"interrupt", Sy_bit(OPT_INTERRUPT), ~Sy_bit(OPT_INTERRUPT) },
532  {"sugarCrit", Sy_bit(OPT_SUGARCRIT), ~Sy_bit(OPT_SUGARCRIT) },
533  {"teach", Sy_bit(OPT_DEBUG), ~Sy_bit(OPT_DEBUG) },
534  {"notSyzMinim", Sy_bit(OPT_NO_SYZ_MINIM), ~Sy_bit(OPT_NO_SYZ_MINIM) },
535  /* 9 return SB in syz, quotient, intersect */
536  {"returnSB", Sy_bit(OPT_RETURN_SB), ~Sy_bit(OPT_RETURN_SB) },
537  {"fastHC", Sy_bit(OPT_FASTHC), ~Sy_bit(OPT_FASTHC) },
538  /* 11-19 sort in L/T */
539  {"staircaseBound",Sy_bit(OPT_STAIRCASEBOUND),~Sy_bit(OPT_STAIRCASEBOUND) },
540  {"multBound", Sy_bit(OPT_MULTBOUND), ~Sy_bit(OPT_MULTBOUND) },
541  {"degBound", Sy_bit(OPT_DEGBOUND), ~Sy_bit(OPT_DEGBOUND) },
542  /* 25 no redTail(p)/redTail(s) */
543  {"redTail", Sy_bit(OPT_REDTAIL), ~Sy_bit(OPT_REDTAIL) },
544  {"redThrough", Sy_bit(OPT_REDTHROUGH), ~Sy_bit(OPT_REDTHROUGH) },
545  {"lazy", Sy_bit(OPT_OLDSTD), ~Sy_bit(OPT_OLDSTD) },
546  {"intStrategy", Sy_bit(OPT_INTSTRATEGY), ~Sy_bit(OPT_INTSTRATEGY) },
547  {"infRedTail", Sy_bit(OPT_INFREDTAIL), ~Sy_bit(OPT_INFREDTAIL) },
548  /* 30: use not regularity for syz */
549  {"notRegularity",Sy_bit(OPT_NOTREGULARITY), ~Sy_bit(OPT_NOTREGULARITY) },
550  {"weightM", Sy_bit(OPT_WEIGHTM), ~Sy_bit(OPT_WEIGHTM) },
551 /*special for "none" and also end marker for showOption:*/
552  {"ne", 0, 0 }
553 };
554 
556 {
557  {"assign_none",Sy_bit(V_ASSIGN_NONE),~Sy_bit(V_ASSIGN_NONE)},
558  {"mem", Sy_bit(V_SHOW_MEM), ~Sy_bit(V_SHOW_MEM) },
559  {"yacc", Sy_bit(V_YACC), ~Sy_bit(V_YACC) },
560  {"redefine", Sy_bit(V_REDEFINE), ~Sy_bit(V_REDEFINE) },
561  {"reading", Sy_bit(V_READING), ~Sy_bit(V_READING) },
562  {"loadLib", Sy_bit(V_LOAD_LIB), ~Sy_bit(V_LOAD_LIB) },
563  {"debugLib", Sy_bit(V_DEBUG_LIB), ~Sy_bit(V_DEBUG_LIB) },
564  {"loadProc", Sy_bit(V_LOAD_PROC), ~Sy_bit(V_LOAD_PROC) },
565  {"defRes", Sy_bit(V_DEF_RES), ~Sy_bit(V_DEF_RES) },
566  {"usage", Sy_bit(V_SHOW_USE), ~Sy_bit(V_SHOW_USE) },
567  {"Imap", Sy_bit(V_IMAP), ~Sy_bit(V_IMAP) },
568  {"prompt", Sy_bit(V_PROMPT), ~Sy_bit(V_PROMPT) },
569  {"length", Sy_bit(V_LENGTH), ~Sy_bit(V_LENGTH) },
570  {"notWarnSB",Sy_bit(V_NSB), ~Sy_bit(V_NSB) },
571  {"contentSB",Sy_bit(V_CONTENTSB), ~Sy_bit(V_CONTENTSB) },
572  {"cancelunit",Sy_bit(V_CANCELUNIT),~Sy_bit(V_CANCELUNIT)},
573  {"modpsolve",Sy_bit(V_MODPSOLVSB),~Sy_bit(V_MODPSOLVSB)},
574  {"geometricSB",Sy_bit(V_UPTORADICAL),~Sy_bit(V_UPTORADICAL)},
575  {"findMonomials",Sy_bit(V_FINDMONOM),~Sy_bit(V_FINDMONOM)},
576  {"coefStrat",Sy_bit(V_COEFSTRAT), ~Sy_bit(V_COEFSTRAT)},
577  {"qringNF", Sy_bit(V_QRING), ~Sy_bit(V_QRING)},
578  {"warn", Sy_bit(V_ALLWARN), ~Sy_bit(V_ALLWARN)},
579  {"intersectSyz",Sy_bit(V_INTERSECT_SYZ), ~Sy_bit(V_INTERSECT_SYZ)},
580  {"intersectElim",Sy_bit(V_INTERSECT_ELIM), ~Sy_bit(V_INTERSECT_ELIM)},
581 /*special for "none" and also end marker for showOption:*/
582  {"ne", 0, 0 }
583 };
584 
586 {
587  const char *n;
588  do
589  {
590  if (v->Typ()==STRING_CMD)
591  {
592  n=(const char *)v->CopyD(STRING_CMD);
593  }
594  else
595  {
596  if (v->name==NULL)
597  return TRUE;
598  if (v->rtyp==0)
599  {
600  n=v->name;
601  v->name=NULL;
602  }
603  else
604  {
605  n=omStrDup(v->name);
606  }
607  }
608 
609  int i;
610 
611  if(strcmp(n,"get")==0)
612  {
613  intvec *w=new intvec(2);
614  (*w)[0]=si_opt_1;
615  (*w)[1]=si_opt_2;
616  res->rtyp=INTVEC_CMD;
617  res->data=(void *)w;
618  goto okay;
619  }
620  if(strcmp(n,"set")==0)
621  {
622  if((v->next!=NULL)
623  &&(v->next->Typ()==INTVEC_CMD))
624  {
625  v=v->next;
626  intvec *w=(intvec*)v->Data();
627  si_opt_1=(*w)[0];
628  si_opt_2=(*w)[1];
629 #if 0
633  ) {
635  }
636 #endif
637  goto okay;
638  }
639  }
640  if(strcmp(n,"none")==0)
641  {
642  si_opt_1=0;
643  si_opt_2=0;
644  goto okay;
645  }
646  for (i=0; (i==0) || (optionStruct[i-1].setval!=0); i++)
647  {
648  if (strcmp(n,optionStruct[i].name)==0)
649  {
650  if (optionStruct[i].setval & validOpts)
651  {
652  si_opt_1 |= optionStruct[i].setval;
653  // optOldStd disables redthrough
654  if (optionStruct[i].setval == Sy_bit(OPT_OLDSTD))
656  }
657  else
658  WarnS("cannot set option");
659 #if 0
663  ) {
665  }
666 #endif
667  goto okay;
668  }
669  else if ((strncmp(n,"no",2)==0)
670  && (strcmp(n+2,optionStruct[i].name)==0))
671  {
672  if (optionStruct[i].setval & validOpts)
673  {
674  si_opt_1 &= optionStruct[i].resetval;
675  }
676  else
677  WarnS("cannot clear option");
678  goto okay;
679  }
680  }
681  for (i=0; (i==0) || (verboseStruct[i-1].setval!=0); i++)
682  {
683  if (strcmp(n,verboseStruct[i].name)==0)
684  {
685  si_opt_2 |= verboseStruct[i].setval;
686  #ifdef YYDEBUG
687  #if YYDEBUG
688  /*debugging the bison grammar --> grammar.cc*/
689  extern int yydebug;
690  if (BVERBOSE(V_YACC)) yydebug=1;
691  else yydebug=0;
692  #endif
693  #endif
694  goto okay;
695  }
696  else if ((strncmp(n,"no",2)==0)
697  && (strcmp(n+2,verboseStruct[i].name)==0))
698  {
699  si_opt_2 &= verboseStruct[i].resetval;
700  #ifdef YYDEBUG
701  #if YYDEBUG
702  /*debugging the bison grammar --> grammar.cc*/
703  extern int yydebug;
704  if (BVERBOSE(V_YACC)) yydebug=1;
705  else yydebug=0;
706  #endif
707  #endif
708  goto okay;
709  }
710  }
711  Werror("unknown option `%s`",n);
712  okay:
713  if (currRing != NULL)
714  currRing->options = si_opt_1 & TEST_RINGDEP_OPTS;
715  omFree((ADDRESS)n);
716  v=v->next;
717  } while (v!=NULL);
718 
719  // set global variable to show memory usage
720  extern int om_sing_opt_show_mem;
721  if (BVERBOSE(V_SHOW_MEM)) om_sing_opt_show_mem = 1;
722  else om_sing_opt_show_mem = 0;
723 
724  return FALSE;
725 }
726 
727 char * showOption()
728 {
729  int i;
730  BITSET tmp;
731 
732  StringSetS("//options:");
733  if ((si_opt_1!=0)||(si_opt_2!=0))
734  {
735  tmp=si_opt_1;
736  if(tmp)
737  {
738  for (i=0; optionStruct[i].setval!=0; i++)
739  {
740  if (optionStruct[i].setval & tmp)
741  {
742  StringAppend(" %s",optionStruct[i].name);
743  tmp &=optionStruct[i].resetval;
744  }
745  }
746  for (i=0; i<32; i++)
747  {
748  if (tmp & Sy_bit(i)) StringAppend(" %d",i);
749  }
750  }
751  tmp=si_opt_2;
752  if (tmp)
753  {
754  for (i=0; verboseStruct[i].setval!=0; i++)
755  {
756  if (verboseStruct[i].setval & tmp)
757  {
758  StringAppend(" %s",verboseStruct[i].name);
759  tmp &=verboseStruct[i].resetval;
760  }
761  }
762  for (i=1; i<32; i++)
763  {
764  if (tmp & Sy_bit(i)) StringAppend(" %d",i+32);
765  }
766  }
767  return StringEndS();
768  }
769  StringAppendS(" none");
770  return StringEndS();
771 }
772 
773 /* version strings */
774 #ifdef HAVE_FLINT
775 extern "C"
776 {
777 #ifndef __GMP_BITS_PER_MP_LIMB
778 #define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS
779 #endif
780 #include <flint/flint.h>
781 }
782 #endif
783 
784 #ifndef MAKE_DISTRIBUTION
785 const char *singular_date=__DATE__ " " __TIME__;
786 #endif
787 
788 char * versionString(/*const bool bShowDetails = false*/ )
789 {
790  StringSetS("");
791  StringAppend("Singular for %s version %s (%d, %d bit) %s #%s",
792  S_UNAME, VERSION, // SINGULAR_VERSION,
793  SINGULAR_VERSION, sizeof(void*)*8,
794 #ifdef MAKE_DISTRIBUTION
795  VERSION_DATE, GIT_VERSION);
796 #else
797  singular_date, GIT_VERSION);
798 #endif
799  StringAppendS("\nwith\n\t");
800 
801 #if defined(mpir_version)
802  StringAppend("MPIR(%s)~GMP(%s),", mpir_version, gmp_version);
803 #elif defined(gmp_version)
804  // #if defined (__GNU_MP_VERSION) && defined (__GNU_MP_VERSION_MINOR)
805  // StringAppend("GMP(%d.%d),",__GNU_MP_VERSION,__GNU_MP_VERSION_MINOR);
806  StringAppend("GMP(%s),", gmp_version);
807 #endif
808 #ifdef HAVE_NTL
809 #include <NTL/version.h>
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)
824  StringAppendS("no input,");
825  else if (fe_fgets_stdin==fe_fgets)
826  StringAppendS("fgets,");
828  StringAppend("dynamic readline%d),",RL_VERSION_MAJOR);
829  #ifdef HAVE_FEREAD
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: {");
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);
936  StringAppendS("\n");
937  return StringEndS();
938 }
939 
940 #ifdef PDEBUG
941 #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM)
942 void 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 */
988 void 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
1043 void 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 
1083 extern "C"
1084 int 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 */
1092 extern "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  */
1098 
1099 void 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
1124  monitor(NULL,0);
1125 #ifdef PAGE_TEST
1126  mmEndStat();
1127 #endif
1130  {
1132  while(hh!=NULL)
1133  {
1134  //Print("close %s\n",hh->l->name);
1135  slPrepClose(hh->l);
1136  hh=(link_list)hh->next;
1137  }
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 
1195 extern "C"
1196 {
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
1208 static n_coeffType n_pAE=n_unknown;
1209 static 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
1227 {
1228  if ((a->Typ()!=INT_CMD)
1229  ||(a->next==NULL)
1230  ||(a->next->Typ()!=STRING_CMD))
1231  {
1232  WerrorS("`int`i,`string` expected");
1233  return TRUE;
1234  }
1235  else
1236  {
1237  flintZn_struct p;
1238  p.ch=(int)(long)a->Data();
1239  p.name=(char*)a->next->Data();
1240  res->rtyp=CRING_CMD;
1241  res->data=(void*)nInitChar(n_FlintZn,(void*)&p);
1242  return FALSE;
1243  }
1244 }
1245 #endif
1246 
1247 static BOOLEAN iiFloat(leftv res, leftv pnn)
1248 {
1249  short float_len=3;
1250  short float_len2=SHORT_REAL_LENGTH;
1251  coeffs cf=NULL;
1252  if ((pnn!=NULL) && (pnn->Typ()==INT_CMD))
1253  {
1254  float_len=(int)(long)pnn->Data();
1255  float_len2=float_len;
1256  pnn=pnn->next;
1257  if ((pnn!=NULL) && (pnn->Typ()==INT_CMD))
1258  {
1259  float_len2=(int)(long)pnn->Data();
1260  pnn=pnn->next;
1261  }
1262  }
1263  if (float_len2 <= (short)SHORT_REAL_LENGTH)
1264  cf=nInitChar(n_R, NULL);
1265  else // longR or longC?
1266  {
1267  LongComplexInfo param;
1268  param.float_len = si_min (float_len, 32767);
1269  param.float_len2 = si_min (float_len2, 32767);
1270  cf = nInitChar(n_long_R, (void*)&param);
1271  }
1272  res->rtyp=CRING_CMD;
1273  res->data=cf;
1274  return cf==NULL;
1275 }
1276 static BOOLEAN iiCrossProd(leftv res, leftv args)
1277 {
1278  leftv h=args;
1279  coeffs *c=NULL;
1280  coeffs cf=NULL;
1281  int i=0;
1282  if (h==NULL) goto crossprod_error;
1283  while (h!=NULL)
1284  {
1285  if (h->Typ()!=CRING_CMD) goto crossprod_error;
1286  i++;
1287  h=h->next;
1288  }
1289  c=(coeffs*)omAlloc0((i+1)*sizeof(coeffs));
1290  h=args;
1291  i=0;
1292  while (h!=NULL)
1293  {
1294  c[i]=(coeffs)h->CopyD();
1295  i++;
1296  h=h->next;
1297  }
1298  cf=nInitChar(n_nTupel,c);
1299  res->data=cf;
1300  res->rtyp=CRING_CMD;
1301  return FALSE;
1302 
1303  crossprod_error:
1304  WerrorS("expected `crossprod(coeffs, ...)`");
1305  return TRUE;
1306 }
1307 /*2
1308 * initialize components of Singular
1309 */
1310 void siInit(char *name)
1311 {
1312 // factory default settings: -----------------------------------------------
1313  On(SW_USE_EZGCD);
1315  //On(SW_USE_FF_MOD_GCD);
1316  On(SW_USE_EZGCD_P);
1317  On(SW_USE_QGCD);
1318  Off(SW_USE_NTL_SORT); // may be changed by an command line option
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));
1337 
1338  extern int iiInitArithmetic(); iiInitArithmetic(); // iparith.cc
1339 
1340  basePack=(package)omAlloc0(sizeof(*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  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
1435  if (t!=n_unknown)
1436  {
1437  h=enterid("flint_poly_Q",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1438  IDDATA(h)=(char*)nInitChar(t,NULL);
1439  }
1441  if (n_FlintZn!=n_unknown)
1442  {
1443  iiAddCproc("kernel","flintZ",FALSE,ii_FlintZn_init);
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;
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 }
#define OPT_REDSB
Definition: options.h:75
BBA_Proc sca_mora
Definition: old.gring.cc:70
int iiInitArithmetic()
initialisation of arithmetic structured data
Definition: iparith.cc:8894
void m2_end(int i)
Definition: misc_ip.cc:1099
int status int fd
Definition: si_signals.h:59
BOOLEAN flintQ_InitChar(coeffs cf, void *infoStruct)
Definition: flintcf_Q.cc:560
#define TEST_V_QUIET
Definition: options.h:131
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
static void factor_gmp(mpz_t t, lists primes, int *multiplicities, int &index, unsigned long bound)
Definition: misc_ip.cc:341
poly k_NF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce, const ring _currRing)
NOTE: this is just a wrapper which sets currRing for the actual kNF call.
Definition: kstd1.cc:3006
ip_package * package
Definition: structs.h:46
void omSingOutOfMemoryFunc()
Definition: misc_ip.cc:1197
const CanonicalForm int s
Definition: facAbsFact.cc:55
unsigned si_opt_1
Definition: options.c:5
This file provides miscellaneous functionality.
sleftv * m
Definition: lists.h:45
#define OM_CHECK
Definition: omalloc_debug.c:15
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition: feread.cc:34
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
int j
Definition: facHensel.cc:105
#define OPT_PROT
Definition: options.h:74
void factoryseed(int s)
random seed initializer
Definition: cf_random.cc:176
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
ideal k_gnc_gr_bba(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
Definition: gr_kstd2.cc:1045
void singular_example(char *str)
Definition: misc_ip.cc:448
#define MAXPATHLEN
Definition: omRet2Info.c:22
ip_command * command
Definition: ipid.h:22
static char * iiGetLibName(const procinfov pi)
find the library of an proc
Definition: ipshell.h:66
#define V_COEFSTRAT
Definition: options.h:61
static FORCE_INLINE void number2mpz(number n, mpz_t m)
Definition: misc_ip.cc:84
void PrintLn()
Definition: reporter.cc:310
static CanonicalForm bound(const CFMatrix &M)
Definition: cf_linsys.cc:460
#define Print
Definition: emacs.cc:80
void feStringAppendResources(int warn)
Definition: reporter.cc:398
Definition: tok.h:96
const BOOLEAN p_procs_dynamic
#define SHORT_REAL_LENGTH
Definition: numbers.h:58
ideal k_sca_bba(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
Modified modern Sinuglar Buchberger&#39;s algorithm.
Definition: sca.cc:368
ideal k_sca_gr_bba(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
Modified Plural&#39;s Buchberger&#39;s algorithmus.
Definition: sca.cc:95
#define OPT_INFREDTAIL
Definition: options.h:93
static void * feOptValue(feOptIndex opt)
Definition: feOpt.h:40
void Off(int sw)
switches
idhdl currPackHdl
Definition: ipid.cc:57
#define mpz_sgn1(A)
Definition: si_gmp.h:13
#define V_LENGTH
Definition: options.h:63
Definition: lists.h:22
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition: algext.cc:1395
ideal k_sca_mora(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
Modified modern Sinuglar Mora&#39;s algorithm.
Definition: sca.cc:885
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition: coeffs.h:39
#define IDID(a)
Definition: ipid.h:117
static int si_min(const int a, const int b)
Definition: auxiliary.h:139
volatile BOOLEAN m2_end_called
Definition: misc_ip.cc:1097
#define FALSE
Definition: auxiliary.h:94
Definition: tok.h:38
static n_coeffType n_FlintZn
Definition: misc_ip.cc:1225
sipc_sem_t * semaphore[SIPC_MAX_SEMAPHORES]
Definition: semaphore.c:24
static void factor_using_pollard_rho(mpz_t n, unsigned long a, lists primes, int *multiplicities, int &index)
Definition: misc_ip.cc:218
void siInit(char *name)
Definition: misc_ip.cc:1310
void setListEntry(lists L, int index, mpz_t n)
Definition: misc_ip.cc:88
#define V_LOAD_LIB
Definition: options.h:47
#define SINGULAR_VERSION
Definition: mod2.h:88
static unsigned add[]
Definition: misc_ip.cc:121
static char * feResource(feResourceConfig config, int warn)
Definition: feResource.cc:258
#define OPT_MULTBOUND
Definition: options.h:88
const struct soptionStruct optionStruct[]
Definition: misc_ip.cc:525
char * fe_fgets(const char *pr, char *s, int size)
Definition: feread.cc:310
static const int SW_USE_EZGCD_P
set to 1 to use EZGCD over F_q
Definition: cf_defs.h:34
rational (GMP) numbers
Definition: coeffs.h:31
#define V_DEF_RES
Definition: options.h:50
#define OPT_NO_SYZ_MINIM
Definition: options.h:82
char * showOption()
Definition: misc_ip.cc:727
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:539
int singular_fstat(int fd, struct stat *buf)
Definition: misc_ip.cc:1084
#define IDNEXT(a)
Definition: ipid.h:113
#define V_FINDMONOM
Definition: options.h:60
#define IDROOT
Definition: ipid.h:18
char * fe_fgets_dummy(const char *, char *, int)
Definition: feread.cc:451
#define OPT_OLDSTD
Definition: options.h:85
int siRandomStart
Definition: cntrlc.cc:98
static const int SW_USE_NTL_SORT
set to 1 to sort factors in a factorization
Definition: cf_defs.h:36
#define TRUE
Definition: auxiliary.h:98
#define FORCE_INLINE
Definition: auxiliary.h:343
static unsigned short primes[]
primes, primes_len: used to step through possible extensions
void * ADDRESS
Definition: auxiliary.h:133
FILE * File_Profiling
Definition: fevoices.cc:33
unsigned setval
Definition: ipid.h:148
unsigned resetval
Definition: ipid.h:149
void * value
Definition: fegetopt.h:93
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition: feOpt.cc:150
void feInitResources(const char *argv0)
Definition: feResource.cc:170
void WerrorS(const char *s)
Definition: feFopen.cc:24
void initRTimer()
Definition: timer.cc:158
void omPrintStats(FILE *fd)
Definition: omStats.c:115
int k
Definition: cfEzgcd.cc:92
char * StringEndS()
Definition: reporter.cc:151
idhdl basePackHdl
Definition: ipid.cc:58
#define loop
Definition: structs.h:78
#define V_DEBUG_LIB
Definition: options.h:48
#define WarnS
Definition: emacs.cc:78
#define V_INTERSECT_ELIM
Definition: options.h:67
#define BITSET
Definition: structs.h:18
coeffs coeffs_BIGINT
Definition: ipid.cc:52
int Typ()
Definition: subexpr.cc:992
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define Sy_bit(x)
Definition: options.h:32
static BOOLEAN iiFloat(leftv res, leftv pnn)
Definition: misc_ip.cc:1247
static FORCE_INLINE number mpz2number(mpz_t m)
Definition: misc_ip.cc:85
BOOLEAN iiLibCmd(char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition: iplib.cc:826
BOOLEAN n2pInitChar(coeffs cf, void *infoStruct)
Definition: algext.cc:1679
Definition: idrec.h:34
#define IDHDL
Definition: tok.h:31
char * versionString()
Definition: misc_ip.cc:788
real floating point (GMP) numbers
Definition: coeffs.h:34
void monitor(void *F, int mode)
Definition: febase.cc:67
BITSET validOpts
Definition: kstd1.cc:59
short float_len2
additional char-flags, rInit
Definition: coeffs.h:103
omOpts_t om_Opts
Definition: omOpts.c:11
BBA_Proc gnc_gr_bba
Definition: old.gring.cc:67
static BOOLEAN rField_has_simple_inverse(const ring r)
Definition: ring.h:540
void * data
Definition: subexpr.h:88
void feStringAppendBrowsers(int warn)
Definition: fehelp.cc:344
void setListEntry_ui(lists L, int index, unsigned long ui)
Definition: misc_ip.cc:105
#define pIter(p)
Definition: monomials.h:44
#define V_QRING
Definition: options.h:42
static BOOLEAN iiCrossProd(leftv res, leftv args)
Definition: misc_ip.cc:1276
#define IDPACKAGE(a)
Definition: ipid.h:134
int myynest
Definition: febase.cc:41
#define V_SHOW_USE
Definition: options.h:52
#define IDTYP(a)
Definition: ipid.h:114
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define FACTORYVERSION
Definition: factoryconf.h:52
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:257
#define V_SHOW_MEM
Definition: options.h:43
Definition: tok.h:56
int RingDependend(int t)
Definition: gentable.cc:29
short float_len
additional char-flags, rInit
Definition: coeffs.h:102
#define SI_RESTORE_OPT(A, B)
Definition: options.h:24
BOOLEAN singular_in_batchmode
Definition: cntrlc.cc:67
#define MDEBUG
Definition: mod2.h:181
Coefficient rings, fields and other domains suitable for Singular polynomials.
void omInitInfo()
Definition: omStats.c:17
#define TEST_OPT_INTSTRATEGY
Definition: options.h:109
Definition: intvec.h:17
CanonicalForm res
Definition: facAbsFact.cc:64
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
Definition: numbers.cc:538
#define OPT_REDTAIL
Definition: options.h:90
#define OPT_NOT_BUCKETS
Definition: options.h:76
Definition: tok.h:58
const char * name
Definition: subexpr.h:87
BBA_Proc sca_bba
Definition: old.gring.cc:69
#define omFree(addr)
Definition: omAllocDecl.h:261
#define p_SetRingOfLm(p, r)
Definition: monomials.h:151
BBA_Proc gnc_gr_mora
Definition: old.gring.cc:68
#define assume(x)
Definition: mod2.h:390
The main handler for Singular numbers which are suitable for Singular polynomials.
char * fe_fgets_stdin_emu(const char *pr, char *s, int size)
Definition: feread.cc:254
void StringSetS(const char *st)
Definition: reporter.cc:128
int status int void * buf
Definition: si_signals.h:59
void StringAppendS(const char *st)
Definition: reporter.cc:107
static BOOLEAN ii_FlintZn_init(leftv res, leftv a)
Definition: misc_ip.cc:1226
struct fe_option feOptSpec[]
#define OPT_NOT_SUGAR
Definition: options.h:77
void fe_reset_input_mode()
Definition: fereadl.c:825
SI_FOREACH_BUILTIN(SI_GET_BUILTIN_MOD_INIT0) }
#define V_CONTENTSB
Definition: options.h:56
#define V_UPTORADICAL
Definition: options.h:59
int m
Definition: cfEzgcd.cc:121
#define OPT_STAIRCASEBOUND
Definition: options.h:87
only used if HAVE_RINGS is defined
Definition: coeffs.h:44
void On(int sw)
switches
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:47
#define StringAppend
Definition: emacs.cc:79
FILE * f
Definition: checklibs.c:9
int i
Definition: cfEzgcd.cc:125
void PrintS(const char *s)
Definition: reporter.cc:284
ideal k_gnc_gr_mora(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
Definition: gr_kstd2.cc:1307
const struct soptionStruct verboseStruct[]
Definition: misc_ip.cc:555
idhdl next
Definition: idrec.h:38
#define version
Definition: libparse.cc:1260
char name(const Variable &v)
Definition: factory.h:180
static const int SW_USE_CHINREM_GCD
set to 1 to use modular gcd over Z
Definition: cf_defs.h:38
#define IDELEMS(i)
Definition: simpleideals.h:24
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff &#39;n&#39; represents the zero element.
Definition: coeffs.h:465
BOOLEAN iiEStart(char *example, procinfo *pi)
Definition: iplib.cc:699
#define IDLEV(a)
Definition: ipid.h:116
n-tupel of cf: ZZ/p1,...
Definition: coeffs.h:43
#define V_READING
Definition: options.h:46
short errorreported
Definition: feFopen.cc:23
leftv next
Definition: subexpr.h:86
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:592
#define OPT_SUGARCRIT
Definition: options.h:79
#define OPT_INTSTRATEGY
Definition: options.h:91
#define BVERBOSE(a)
Definition: options.h:35
INLINE_THIS void Init(int l=0)
CanonicalForm test
Definition: cfModGcd.cc:4037
#define V_LOAD_PROC
Definition: options.h:49
#define IDPROC(a)
Definition: ipid.h:135
#define V_ALLWARN
Definition: options.h:66
#define OPT_DEBUG
Definition: options.h:80
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
BOOLEAN flintZn_InitChar(coeffs cf, void *infoStruct)
Definition: flintcf_Zn.cc:465
#define mpz_size1(A)
Definition: si_gmp.h:12
n_coeffType
Definition: coeffs.h:27
#define V_YACC
Definition: options.h:44
CanonicalForm cf
Definition: cfModGcd.cc:4024
#define SEEK_END
Definition: mod2.h:112
Definition: tok.h:117
#define OM_TRACK
Definition: omalloc_debug.c:10
#define V_PROMPT
Definition: options.h:54
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:477
#define NULL
Definition: omList.c:10
#define VERSION
Definition: mod2.h:18
slists * lists
Definition: mpr_numeric.h:146
#define OPT_WEIGHTM
Definition: options.h:96
int yydebug
Definition: grammar.cc:1803
lists primeFactorisation(const number n, const int pBound)
Factorises a given bigint number n into its prime factors less than or equal to a given bound...
Definition: misc_ip.cc:371
int siSeed
Definition: sirandom.c:29
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:138
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic ...
Definition: coeffs.h:36
#define V_NSB
Definition: options.h:55
#define V_CANCELUNIT
Definition: options.h:57
void killhdl(idhdl h, package proot)
Definition: ipid.cc:376
const char * singular_date
Definition: misc_ip.cc:785
package basePack
Definition: ipid.cc:60
static const int SW_USE_QGCD
set to 1 to use Encarnacion GCD over Q(a)
Definition: cf_defs.h:40
static const int SW_USE_EZGCD
set to 1 to use EZGCD over Z
Definition: cf_defs.h:32
#define IDRING(a)
Definition: ipid.h:122
static BOOLEAN length(leftv result, leftv arg)
Definition: interval.cc:267
const CanonicalForm & w
Definition: facAbsFact.cc:55
package currPack
Definition: ipid.cc:59
Variable x
Definition: cfModGcd.cc:4023
int rtyp
Definition: subexpr.h:91
#define SI_SAVE_OPT(A, B)
Definition: options.h:21
sleftv sLastPrinted
Definition: subexpr.cc:51
#define SIPC_MAX_SEMAPHORES
Definition: simpleipc.h:10
void Clean(ring r=currRing)
Definition: lists.h:25
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
void * Data()
Definition: subexpr.cc:1134
#define OPT_REDTHROUGH
Definition: options.h:81
int initTimer()
Definition: timer.cc:69
#define V_INTERSECT_SYZ
Definition: options.h:68
Definition: tok.h:118
#define V_ASSIGN_NONE
Definition: options.h:69
#define SI_SHOW_BUILTIN_MODULE(name)
omBin slists_bin
Definition: lists.cc:23
NF_Proc nc_NF
Definition: old.gring.cc:66
#define TEST_RINGDEP_OPTS
Definition: options.h:99
#define omCheckAddr(addr)
Definition: omAllocDecl.h:328
static FORCE_INLINE BOOLEAN n_GreaterZero(number n, const coeffs r)
ordered fields: TRUE iff &#39;n&#39; is positive; in Z/pZ: TRUE iff 0 < m <= roundedBelow(p/2), where m is the long representing n in C: TRUE iff (Im(n) != 0 and Im(n) >= 0) or (Im(n) == 0 and Re(n) >= 0) in K(a)/<p(a)>: TRUE iff (n != 0 and (LC(n) > 0 or deg(n) > 0)) in K(t_1, ..., t_n): TRUE iff (LC(numerator(n) is a constant and > 0) or (LC(numerator(n) is not a constant) in Z/2^kZ: TRUE iff 0 < n <= 2^(k-1) in Z/mZ: TRUE iff the internal mpz is greater than zero in Z: TRUE iff n > 0
Definition: coeffs.h:495
void iiCheckPack(package &p)
Definition: ipshell.cc:1536
#define SEEK_SET
Definition: mod2.h:116
#define OPT_DEGBOUND
Definition: options.h:89
int p
Definition: cfModGcd.cc:4019
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:1005
#define IDDATA(a)
Definition: ipid.h:121
#define OPT_NOTREGULARITY
Definition: options.h:95
char * fe_fgets_stdin_drl(const char *pr, char *s, int size)
Definition: feread.cc:270
int sem_acquired[SIPC_MAX_SEMAPHORES]
Definition: semaphore.c:25
static int factor_using_division(mpz_t t, unsigned int limit, lists primes, int *multiplicities, int &index, unsigned long bound)
Definition: misc_ip.cc:123
#define OPT_INTERRUPT
Definition: options.h:78
BBA_Proc sca_gr_bba
Definition: old.gring.cc:71
unsigned si_opt_2
Definition: options.c:6
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition: iplib.cc:192
static Poly * h
Definition: janet.cc:972
int BOOLEAN
Definition: auxiliary.h:85
#define NONE
Definition: tok.h:218
#define V_REDEFINE
Definition: options.h:45
void dErrorBreak()
Definition: dError.cc:141
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define OPT_FASTHC
Definition: options.h:84
void * CopyD(int t)
Definition: subexpr.cc:703
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:93
#define V_MODPSOLVSB
Definition: options.h:58
used to represent polys as coeffcients
Definition: coeffs.h:35
int si_echo
Definition: febase.cc:35
BOOLEAN setOption(leftv res, leftv v)
Definition: misc_ip.cc:585
#define COMMAND
Definition: tok.h:29
#define OPT_RETURN_SB
Definition: options.h:83
#define V_IMAP
Definition: options.h:53
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:349
BOOLEAN ntInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition: transext.cc:2492
#define omStrDup(s)
Definition: omAllocDecl.h:263