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