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