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 
15 #include <kernel/mod2.h>
16 #include <misc/auxiliary.h>
17 #include <misc/sirandom.h>
18 
19 #include <reporter/si_signals.h>
20 
21 #include <factory/factory.h>
22 
23 #include <coeffs/si_gmp.h>
24 #include <coeffs/coeffs.h>
25 #include <coeffs/OPAE.h>
26 #include <coeffs/OPAEQ.h>
27 #include <coeffs/OPAEp.h>
28 
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 
42 static FORCE_INLINE void number2mpz(number n, mpz_t m){ number2mpz(n, coeffs_BIGINT, m); }
43 static FORCE_INLINE number mpz2number(mpz_t m){ return mpz2number(m, coeffs_BIGINT); }
44 
45 
46 void setListEntry(lists L, int index, mpz_t n)
47 { /* assumes n > 0 */
48  /* try to fit nn into an int: */
49  if (mpz_size1(n)<=1)
50  {
51  int ui=(int)mpz_get_si(n);
52  if ((((ui<<3)>>3)==ui)
53  && (mpz_cmp_si(n,(long)ui)==0))
54  {
55  L->m[index].rtyp = INT_CMD; L->m[index].data = (void*)(long)ui;
56  return;
57  }
58  }
59  number nn = mpz2number(n);
60  L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn;
61 }
62 
63 void setListEntry_ui(lists L, int index, unsigned long ui)
64 { /* assumes n > 0 */
65  /* try to fit nn into an int: */
66  int i=(int)ui;
67  if ((((unsigned long)i)==ui) && (((i<<3)>>3)==i))
68  {
69  L->m[index].rtyp = INT_CMD; L->m[index].data = (void*)(long)i;
70  }
71  else
72  {
73  number nn = n_Init(ui, coeffs_BIGINT);
74  L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn;
75  }
76 }
77 
78 /* Factoring with Pollard's rho method. stolen from GMP/demos */
79 static unsigned add[] = {4, 2, 4, 2, 4, 6, 2, 6};
80 
81 static int factor_using_division (mpz_t t, unsigned int limit,lists primes, int *multiplicities,int &index, unsigned long bound)
82 {
83  mpz_t q, r;
84  unsigned long int f;
85  int ai;
86  unsigned *addv = add;
87  unsigned int failures;
88  int bound_not_reached=1;
89 
90  mpz_init (q);
91  mpz_init (r);
92 
93  f = mpz_scan1 (t, 0);
94  mpz_div_2exp (t, t, f);
95  if (f>0)
96  {
97  setListEntry_ui(primes, index, 2);
98  multiplicities[index++] = f;
99  }
100 
101  f=0;
102  loop
103  {
104  mpz_tdiv_qr_ui (q, r, t, 3);
105  if (mpz_cmp_ui (r, 0) != 0)
106  break;
107  mpz_set (t, q);
108  f++;
109  }
110  if (f>0)
111  {
112  setListEntry_ui(primes, index, 3);
113  multiplicities[index++] = f;
114  }
115  f=0;
116  loop
117  {
118  mpz_tdiv_qr_ui (q, r, t, 5);
119  if (mpz_cmp_ui (r, 0) != 0)
120  break;
121  mpz_set (t, q);
122  f++;
123  }
124  if (f>0)
125  {
126  setListEntry_ui(primes, index, 5);
127  multiplicities[index++] = f;
128  }
129 
130  failures = 0;
131  f = 7;
132  ai = 0;
133  unsigned long last_f=0;
134  while (mpz_cmp_ui (t, 1) != 0)
135  {
136  mpz_tdiv_qr_ui (q, r, t, f);
137  if (mpz_cmp_ui (r, 0) != 0)
138  {
139  f += addv[ai];
140  if (mpz_cmp_ui (t, f) < 0)
141  break;
142  ai = (ai + 1) & 7;
143  failures++;
144  if (failures > limit)
145  break;
146  if ((bound!=0) && (f>bound))
147  {
148  bound_not_reached=0;
149  break;
150  }
151  }
152  else
153  {
154  mpz_swap (t, q);
155  if (f!=last_f)
156  {
157  setListEntry_ui(primes, index, f);
158  multiplicities[index]++;
159  index++;
160  }
161  else
162  {
163  multiplicities[index-1]++;
164  }
165  last_f=f;
166  failures = 0;
167  }
168  }
169 
170  mpz_clear (q);
171  mpz_clear (r);
172  //printf("bound=%d,f=%d,failures=%d, reached=%d\n",bound,f,failures,bound_not_reached);
173  return bound_not_reached;
174 }
175 
176 static void factor_using_pollard_rho (mpz_t n, unsigned long a, lists primes, int * multiplicities,int &index)
177 {
178  mpz_t x, x1, y, P;
179  mpz_t t1, t2;
180  mpz_t last_f;
181  unsigned long long k, l, i;
182 
183  mpz_init (t1);
184  mpz_init (t2);
185  mpz_init_set_si (last_f, 0);
186  mpz_init_set_si (y, 2);
187  mpz_init_set_si (x, 2);
188  mpz_init_set_si (x1, 2);
189  mpz_init_set_ui (P, 1);
190  k = 1;
191  l = 1;
192 
193  while (mpz_cmp_ui (n, 1) != 0)
194  {
195  loop
196  {
197  do
198  {
199  mpz_mul (t1, x, x);
200  mpz_mod (x, t1, n);
201  mpz_add_ui (x, x, a);
202  mpz_sub (t1, x1, x);
203  mpz_mul (t2, P, t1);
204  mpz_mod (P, t2, n);
205 
206  if (k % 32 == 1)
207  {
208  mpz_gcd (t1, P, n);
209  if (mpz_cmp_ui (t1, 1) != 0)
210  goto factor_found;
211  mpz_set (y, x);
212  }
213  }
214  while (--k != 0);
215 
216  mpz_gcd (t1, P, n);
217  if (mpz_cmp_ui (t1, 1) != 0)
218  goto factor_found;
219 
220  mpz_set (x1, x);
221  k = l;
222  l = 2 * l;
223  for (i = 0; i < k; i++)
224  {
225  mpz_mul (t1, x, x);
226  mpz_mod (x, t1, n);
227  mpz_add_ui (x, x, a);
228  }
229  mpz_set (y, x);
230  }
231 
232  factor_found:
233  do
234  {
235  mpz_mul (t1, y, y);
236  mpz_mod (y, t1, n);
237  mpz_add_ui (y, y, a);
238  mpz_sub (t1, x1, y);
239  mpz_gcd (t1, t1, n);
240  }
241  while (mpz_cmp_ui (t1, 1) == 0);
242 
243  mpz_divexact (n, n, t1); /* divide by t1, before t1 is overwritten */
244 
245  if (!mpz_probab_prime_p (t1, 10))
246  {
247  do
248  {
249  mp_limb_t a_limb;
250  mpn_random (&a_limb, (mp_size_t) 1);
251  a = a_limb;
252  }
253  while (a == 0);
254 
255  factor_using_pollard_rho (t1, a, primes,multiplicities,index);
256  }
257  else
258  {
259  if (mpz_cmp(t1,last_f)==0)
260  {
261  multiplicities[index-1]++;
262  }
263  else
264  {
265  mpz_set(last_f,t1);
266  setListEntry(primes, index, t1);
267  multiplicities[index++] = 1;
268  }
269  }
270  mpz_mod (x, x, n);
271  mpz_mod (x1, x1, n);
272  mpz_mod (y, y, n);
273  if (mpz_probab_prime_p (n, 10))
274  {
275  if (mpz_cmp(n,last_f)==0)
276  {
277  multiplicities[index-1]++;
278  }
279  else
280  {
281  mpz_set(last_f,n);
282  setListEntry(primes, index, n);
283  multiplicities[index++] = 1;
284  }
285  mpz_set_ui(n,1);
286  break;
287  }
288  }
289 
290  mpz_clear (P);
291  mpz_clear (t2);
292  mpz_clear (t1);
293  mpz_clear (x1);
294  mpz_clear (x);
295  mpz_clear (y);
296  mpz_clear (last_f);
297 }
298 
299 static void factor_gmp (mpz_t t,lists primes,int *multiplicities,int &index,unsigned long bound)
300 {
301  unsigned int division_limit;
302 
303  if (mpz_sgn (t) == 0)
304  return;
305 
306  /* Set the trial division limit according the size of t. */
307  division_limit = mpz_sizeinbase (t, 2);
308  if (division_limit > 1000)
309  division_limit = 1000 * 1000;
310  else
311  division_limit = division_limit * division_limit;
312 
313  if (factor_using_division (t, division_limit,primes,multiplicities,index,bound))
314  {
315  if (mpz_cmp_ui (t, 1) != 0)
316  {
317  if (mpz_probab_prime_p (t, 10))
318  {
319  setListEntry(primes, index, t);
320  multiplicities[index++] = 1;
321  mpz_set_ui(t,1);
322  }
323  else
324  factor_using_pollard_rho (t, 1L, primes,multiplicities,index);
325  }
326  }
327 }
328 /* n and pBound are assumed to be bigint numbers */
329 lists primeFactorisation(const number n, const int pBound)
330 {
331  int i;
332  int index=0;
333  mpz_t nn; number2mpz(n, nn);
334  lists primes = (lists)omAllocBin(slists_bin); primes->Init(1000);
335  int* multiplicities = (int*)omAlloc0(1000*sizeof(int));
336  int positive=1;
337 
338  if (!n_IsZero(n, coeffs_BIGINT))
339  {
340  if (!n_GreaterZero(n, coeffs_BIGINT))
341  {
342  positive=-1;
343  mpz_neg(nn,nn);
344  }
345  factor_gmp(nn,primes,multiplicities,index,pBound);
346  }
347 
348  lists primesL = (lists)omAllocBin(slists_bin);
349  primesL->Init(index);
350  for (i = 0; i < index; i++)
351  {
352  primesL->m[i].rtyp = primes->m[i].rtyp;
353  primesL->m[i].data = primes->m[i].data;
354  primes->m[i].rtyp=0;
355  primes->m[i].data=NULL;
356  }
357  primes->Clean(NULL);
358 
359  lists multiplicitiesL = (lists)omAllocBin(slists_bin);
360  multiplicitiesL->Init(index);
361  for (i = 0; i < index; i++)
362  {
363  multiplicitiesL->m[i].rtyp = INT_CMD;
364  multiplicitiesL->m[i].data = (void*)(long)multiplicities[i];
365  }
366  omFree(multiplicities);
367 
369  L->Init(3);
370  if (positive==-1) mpz_neg(nn,nn);
371  L->m[0].rtyp = LIST_CMD; L->m[0].data = (void*)primesL;
372  L->m[1].rtyp = LIST_CMD; L->m[1].data = (void*)multiplicitiesL;
373  setListEntry(L, 2, nn);
374 
375  mpz_clear(nn);
376 
377  return L;
378 }
379 
380 #include <omalloc/omalloc.h>
381 #include <misc/mylimits.h>
382 
383 #include <misc/options.h>
384 #include <misc/intvec.h>
385 
386 #include <polys/monomials/ring.h>
387 #include <polys/templates/p_Procs.h>
388 
389 #include <kernel/GBEngine/kstd1.h>
390 #include <kernel/oswrapper/timer.h>
391 #include <resources/feResource.h>
392 #include <kernel/oswrapper/feread.h>
393 
394 #include "subexpr.h"
395 #include "cntrlc.h"
396 #include "ipid.h"
397 #include "ipshell.h"
398 
399 #include "fehelp.h"
400 
401 #ifdef HAVE_STATIC
402 #undef HAVE_DYN_RL
403 #endif
404 
405 //#ifdef HAVE_LIBPARSER
406 //# include "libparse.h"
407 //#endif /* HAVE_LIBPARSER */
408 
409 
410 /*2
411 * the renice routine for very large jobs
412 * works only on unix machines,
413 * testet on : linux, HP 9.0
414 *
415 *#include <sys/times.h>
416 *#include <sys/resource.h>
417 *extern "C" int setpriority(int,int,int);
418 *void very_nice()
419 *{
420 *#ifndef NO_SETPRIORITY
421 * setpriority(PRIO_PROCESS,0,19);
422 *#endif
423 * sleep(10);
424 *}
425 */
426 
427 #include <string.h>
428 #include <unistd.h>
429 #include <stdio.h>
430 #include <stddef.h>
431 #include <stdlib.h>
432 #include <time.h>
433 
434 
435 void singular_example(char *str)
436 {
437  assume(str!=NULL);
438  char *s=str;
439  while (*s==' ') s++;
440  char *ss=s;
441  while (*ss!='\0') ss++;
442  while (*ss<=' ')
443  {
444  *ss='\0';
445  ss--;
446  }
447  idhdl h=IDROOT->get(s,myynest);
448  if ((h!=NULL) && (IDTYP(h)==PROC_CMD))
449  {
450  char *lib=iiGetLibName(IDPROC(h));
451  if((lib!=NULL)&&(*lib!='\0'))
452  {
453  Print("// proc %s from lib %s\n",s,lib);
454  s=iiGetLibProcBuffer(IDPROC(h), 2);
455  if (s!=NULL)
456  {
457  if (strlen(s)>5)
458  {
459  iiEStart(s,IDPROC(h));
460  omFree((ADDRESS)s);
461  return;
462  }
463  else omFree((ADDRESS)s);
464  }
465  }
466  }
467  else
468  {
469  char sing_file[MAXPATHLEN];
470  FILE *fd=NULL;
471  char *res_m=feResource('m', 0);
472  if (res_m!=NULL)
473  {
474  sprintf(sing_file, "%s/%s.sing", res_m, s);
475  fd = feFopen(sing_file, "r");
476  }
477  if (fd != NULL)
478  {
479 
480  int old_echo = si_echo;
481  int length, got;
482  char* s;
483 
484  fseek(fd, 0, SEEK_END);
485  length = ftell(fd);
486  fseek(fd, 0, SEEK_SET);
487  s = (char*) omAlloc((length+20)*sizeof(char));
488  got = fread(s, sizeof(char), length, fd);
489  fclose(fd);
490  if (got != length)
491  {
492  Werror("Error while reading file %s", sing_file);
493  }
494  else
495  {
496  s[length] = '\0';
497  strcat(s, "\n;return();\n\n");
498  si_echo = 2;
499  iiEStart(s, NULL);
500  si_echo = old_echo;
501  }
502  omFree(s);
503  }
504  else
505  {
506  Werror("no example for %s", str);
507  }
508  }
509 }
510 
511 
512 struct soptionStruct
513 {
514  const char * name;
515  unsigned setval;
516  unsigned resetval;
517 };
518 
520 {
521  {"prot", Sy_bit(OPT_PROT), ~Sy_bit(OPT_PROT) },
522  {"redSB", Sy_bit(OPT_REDSB), ~Sy_bit(OPT_REDSB) },
523  {"notBuckets", Sy_bit(OPT_NOT_BUCKETS), ~Sy_bit(OPT_NOT_BUCKETS) },
524  {"notSugar", Sy_bit(OPT_NOT_SUGAR), ~Sy_bit(OPT_NOT_SUGAR) },
525  {"interrupt", Sy_bit(OPT_INTERRUPT), ~Sy_bit(OPT_INTERRUPT) },
526  {"sugarCrit", Sy_bit(OPT_SUGARCRIT), ~Sy_bit(OPT_SUGARCRIT) },
527  {"teach", Sy_bit(OPT_DEBUG), ~Sy_bit(OPT_DEBUG) },
528  {"notSyzMinim", Sy_bit(OPT_NO_SYZ_MINIM), ~Sy_bit(OPT_NO_SYZ_MINIM) },
529  /* 9 return SB in syz, quotient, intersect */
530  {"returnSB", Sy_bit(OPT_RETURN_SB), ~Sy_bit(OPT_RETURN_SB) },
531  {"fastHC", Sy_bit(OPT_FASTHC), ~Sy_bit(OPT_FASTHC) },
532  /* 11-19 sort in L/T */
533  {"staircaseBound",Sy_bit(OPT_STAIRCASEBOUND),~Sy_bit(OPT_STAIRCASEBOUND) },
534  {"multBound", Sy_bit(OPT_MULTBOUND), ~Sy_bit(OPT_MULTBOUND) },
535  {"degBound", Sy_bit(OPT_DEGBOUND), ~Sy_bit(OPT_DEGBOUND) },
536  /* 25 no redTail(p)/redTail(s) */
537  {"redTail", Sy_bit(OPT_REDTAIL), ~Sy_bit(OPT_REDTAIL) },
538  {"redThrough", Sy_bit(OPT_REDTHROUGH), ~Sy_bit(OPT_REDTHROUGH) },
539  {"lazy", Sy_bit(OPT_OLDSTD), ~Sy_bit(OPT_OLDSTD) },
540  {"intStrategy", Sy_bit(OPT_INTSTRATEGY), ~Sy_bit(OPT_INTSTRATEGY) },
541  {"infRedTail", Sy_bit(OPT_INFREDTAIL), ~Sy_bit(OPT_INFREDTAIL) },
542  /* 30: use not regularity for syz */
543  {"notRegularity",Sy_bit(OPT_NOTREGULARITY), ~Sy_bit(OPT_NOTREGULARITY) },
544  {"weightM", Sy_bit(OPT_WEIGHTM), ~Sy_bit(OPT_WEIGHTM) },
545 /*special for "none" and also end marker for showOption:*/
546  {"ne", 0, 0 }
547 };
548 
550 {
551  {"mem", Sy_bit(V_SHOW_MEM), ~Sy_bit(V_SHOW_MEM) },
552  {"yacc", Sy_bit(V_YACC), ~Sy_bit(V_YACC) },
553  {"redefine", Sy_bit(V_REDEFINE), ~Sy_bit(V_REDEFINE) },
554  {"reading", Sy_bit(V_READING), ~Sy_bit(V_READING) },
555  {"loadLib", Sy_bit(V_LOAD_LIB), ~Sy_bit(V_LOAD_LIB) },
556  {"debugLib", Sy_bit(V_DEBUG_LIB), ~Sy_bit(V_DEBUG_LIB) },
557  {"loadProc", Sy_bit(V_LOAD_PROC), ~Sy_bit(V_LOAD_PROC) },
558  {"defRes", Sy_bit(V_DEF_RES), ~Sy_bit(V_DEF_RES) },
559  {"usage", Sy_bit(V_SHOW_USE), ~Sy_bit(V_SHOW_USE) },
560  {"Imap", Sy_bit(V_IMAP), ~Sy_bit(V_IMAP) },
561  {"prompt", Sy_bit(V_PROMPT), ~Sy_bit(V_PROMPT) },
562  {"length", Sy_bit(V_LENGTH), ~Sy_bit(V_LENGTH) },
563  {"notWarnSB",Sy_bit(V_NSB), ~Sy_bit(V_NSB) },
564  {"contentSB",Sy_bit(V_CONTENTSB), ~Sy_bit(V_CONTENTSB) },
565  {"cancelunit",Sy_bit(V_CANCELUNIT),~Sy_bit(V_CANCELUNIT)},
566  {"modpsolve",Sy_bit(V_MODPSOLVSB),~Sy_bit(V_MODPSOLVSB)},
567  {"geometricSB",Sy_bit(V_UPTORADICAL),~Sy_bit(V_UPTORADICAL)},
568  {"findMonomials",Sy_bit(V_FINDMONOM),~Sy_bit(V_FINDMONOM)},
569  {"coefStrat",Sy_bit(V_COEFSTRAT), ~Sy_bit(V_COEFSTRAT)},
570  {"qringNF", Sy_bit(V_QRING), ~Sy_bit(V_QRING)},
571  {"warn", Sy_bit(V_ALLWARN), ~Sy_bit(V_ALLWARN)},
572  {"interedSyz",Sy_bit(V_INTERSECT_SYZ), ~Sy_bit(V_INTERSECT_SYZ)},
573  {"interedElim",Sy_bit(V_INTERSECT_ELIM), ~Sy_bit(V_INTERSECT_ELIM)},
574 /*special for "none" and also end marker for showOption:*/
575  {"ne", 0, 0 }
576 };
577 
579 {
580  const char *n;
581  do
582  {
583  if (v->Typ()==STRING_CMD)
584  {
585  n=(const char *)v->CopyD(STRING_CMD);
586  }
587  else
588  {
589  if (v->name==NULL)
590  return TRUE;
591  if (v->rtyp==0)
592  {
593  n=v->name;
594  v->name=NULL;
595  }
596  else
597  {
598  n=omStrDup(v->name);
599  }
600  }
601 
602  int i;
603 
604  if(strcmp(n,"get")==0)
605  {
606  intvec *w=new intvec(2);
607  (*w)[0]=si_opt_1;
608  (*w)[1]=si_opt_2;
609  res->rtyp=INTVEC_CMD;
610  res->data=(void *)w;
611  goto okay;
612  }
613  if(strcmp(n,"set")==0)
614  {
615  if((v->next!=NULL)
616  &&(v->next->Typ()==INTVEC_CMD))
617  {
618  v=v->next;
619  intvec *w=(intvec*)v->Data();
620  si_opt_1=(*w)[0];
621  si_opt_2=(*w)[1];
622 #if 0
625 #ifdef HAVE_RINGS
627 #endif
628  ) {
630  }
631 #endif
632  goto okay;
633  }
634  }
635  if(strcmp(n,"none")==0)
636  {
637  si_opt_1=0;
638  si_opt_2=0;
639  goto okay;
640  }
641  for (i=0; (i==0) || (optionStruct[i-1].setval!=0); i++)
642  {
643  if (strcmp(n,optionStruct[i].name)==0)
644  {
645  if (optionStruct[i].setval & validOpts)
646  {
647  si_opt_1 |= optionStruct[i].setval;
648  // optOldStd disables redthrough
649  if (optionStruct[i].setval == Sy_bit(OPT_OLDSTD))
651  }
652  else
653  Warn("cannot set option");
654 #if 0
657 #ifdef HAVE_RINGS
659 #endif
660  ) {
662  }
663 #endif
664  goto okay;
665  }
666  else if ((strncmp(n,"no",2)==0)
667  && (strcmp(n+2,optionStruct[i].name)==0))
668  {
669  if (optionStruct[i].setval & validOpts)
670  {
671  si_opt_1 &= optionStruct[i].resetval;
672  }
673  else
674  Warn("cannot clear option");
675  goto okay;
676  }
677  }
678  for (i=0; (i==0) || (verboseStruct[i-1].setval!=0); i++)
679  {
680  if (strcmp(n,verboseStruct[i].name)==0)
681  {
682  si_opt_2 |= verboseStruct[i].setval;
683  #ifdef YYDEBUG
684  #if YYDEBUG
685  /*debugging the bison grammar --> grammar.cc*/
686  extern int yydebug;
687  if (BVERBOSE(V_YACC)) yydebug=1;
688  else yydebug=0;
689  #endif
690  #endif
691  goto okay;
692  }
693  else if ((strncmp(n,"no",2)==0)
694  && (strcmp(n+2,verboseStruct[i].name)==0))
695  {
696  si_opt_2 &= verboseStruct[i].resetval;
697  #ifdef YYDEBUG
698  #if YYDEBUG
699  /*debugging the bison grammar --> grammar.cc*/
700  extern int yydebug;
701  if (BVERBOSE(V_YACC)) yydebug=1;
702  else yydebug=0;
703  #endif
704  #endif
705  goto okay;
706  }
707  }
708  Werror("unknown option `%s`",n);
709  okay:
710  if (currRing != NULL)
711  currRing->options = si_opt_1 & TEST_RINGDEP_OPTS;
712  omFree((ADDRESS)n);
713  v=v->next;
714  } while (v!=NULL);
715 
716 #ifdef OM_SINGULAR_CONFIG_H
717  // set global variable to show memory usage
718  extern int om_sing_opt_show_mem;
719  if (BVERBOSE(V_SHOW_MEM)) om_sing_opt_show_mem = 1;
720  else om_sing_opt_show_mem = 0;
721 #endif
722 
723  return FALSE;
724 }
725 
726 char * showOption()
727 {
728  int i;
729  BITSET tmp;
730 
731  StringSetS("//options:");
732  if ((si_opt_1!=0)||(si_opt_2!=0))
733  {
734  tmp=si_opt_1;
735  if(tmp)
736  {
737  for (i=0; optionStruct[i].setval!=0; i++)
738  {
739  if (optionStruct[i].setval & tmp)
740  {
741  StringAppend(" %s",optionStruct[i].name);
742  tmp &=optionStruct[i].resetval;
743  }
744  }
745  for (i=0; i<32; i++)
746  {
747  if (tmp & Sy_bit(i)) StringAppend(" %d",i);
748  }
749  }
750  tmp=si_opt_2;
751  if (tmp)
752  {
753  for (i=0; verboseStruct[i].setval!=0; i++)
754  {
755  if (verboseStruct[i].setval & tmp)
756  {
757  StringAppend(" %s",verboseStruct[i].name);
758  tmp &=verboseStruct[i].resetval;
759  }
760  }
761  for (i=1; i<32; i++)
762  {
763  if (tmp & Sy_bit(i)) StringAppend(" %d",i+32);
764  }
765  }
766  return StringEndS();
767  }
768  StringAppendS(" none");
769  return StringEndS();
770 }
771 
772 /* version strings */
773 #ifdef HAVE_FLINT
774 extern "C"
775 {
776 #ifndef __GMP_BITS_PER_MP_LIMB
777 #define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS
778 #endif
779 #include <flint/flint.h>
780 }
781 #endif
782 
783 char * versionString(/*const bool bShowDetails = false*/ )
784 {
785  StringSetS("");
786  StringAppend("Singular for %s version %s (%d, %d bit) %s #%s",
787  S_UNAME, VERSION, // SINGULAR_VERSION,
788  SINGULAR_VERSION, SIZEOF_VOIDP*8, singular_date, GIT_VERSION);
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 #include <NTL/version.h>
800  StringAppend("NTL(%s),",NTL_VERSION);
801 #endif
802 
803 #ifdef HAVE_FLINT
804  StringAppend("FLINT(%s),",version);
805 #endif
806  StringAppend("factory(%s),\n\t", factoryVersion);
807 #if defined(HAVE_DYN_RL)
809  StringAppendS("no input,");
810  else if (fe_fgets_stdin==fe_fgets)
811  StringAppendS("fgets,");
813  StringAppendS("dynamic readline,");
814  #ifdef HAVE_FEREAD
816  StringAppendS("emulated readline,");
817  #endif
818  else
819  StringAppendS("unknown fgets method,");
820 #else
821  #if defined(HAVE_READLINE) && !defined(FEREAD)
822  StringAppendS("static readline,");
823  #else
824  #ifdef HAVE_FEREAD
825  StringAppendS("emulated readline,");
826  #else
827  StringAppendS("fgets,");
828  #endif
829  #endif
830 #endif
831 #ifdef HAVE_PLURAL
832  StringAppendS("Plural,");
833 #endif
834 #ifdef HAVE_DBM
835  StringAppendS("DBM,\n\t");
836 #else
837  StringAppendS("\n\t");
838 #endif
839 #ifdef HAVE_DYNAMIC_LOADING
840  StringAppendS("dynamic modules,");
841 #endif
842  if (p_procs_dynamic) StringAppendS("dynamic p_Procs,");
843 #if YYDEBUG
844  StringAppendS("YYDEBUG=1,");
845 #endif
846 #ifdef HAVE_ASSUME
847  StringAppendS("ASSUME,");
848 #endif
849 #ifdef MDEBUG
850  StringAppend("MDEBUG=%d,",MDEBUG);
851 #endif
852 #ifdef OM_CHECK
853  StringAppend("OM_CHECK=%d,",OM_CHECK);
854 #endif
855 #ifdef OM_TRACK
856  StringAppend("OM_TRACK=%d,",OM_TRACK);
857 #endif
858 #ifdef OM_NDEBUG
859  StringAppendS("OM_NDEBUG,");
860 #endif
861 #ifdef SING_NDEBUG
862  StringAppendS("SING_NDEBUG,");
863 #endif
864 #ifdef PDEBUG
865  StringAppendS("PDEBUG,");
866 #endif
867 #ifdef KDEBUG
868  StringAppendS("KDEBUG,");
869 #endif
870 #ifdef __OPTIMIZE__
871  StringAppendS("CC:OPTIMIZE,");
872 #endif
873 #ifdef __OPTIMIZE_SIZE__
874  StringAppendS("CC:OPTIMIZE_SIZE,");
875 #endif
876 #ifdef __NO_INLINE__
877  StringAppendS("CC:NO_INLINE,");
878 #endif
879 #ifdef HAVE_EIGENVAL
880  StringAppendS("eigenvalues,");
881 #endif
882 #ifdef HAVE_GMS
883  StringAppendS("Gauss-Manin system,");
884 #endif
885 #ifdef HAVE_RATGRING
886  StringAppendS("ratGB,");
887 #endif
888  StringAppend("random=%d\n",siRandomStart);
889 
890 #define SI_SHOW_BUILTIN_MODULE(name) StringAppend(" %s", #name);
891  StringAppendS("built-in modules: {");
893  StringAppendS("}\n");
894 #undef SI_SHOW_BUILTIN_MODULE
895 
896  StringAppend("AC_CONFIGURE_ARGS = %s,\n"
897  "CC = %s,FLAGS : %s,\n"
898  "CXX = %s,FLAGS : %s,\n"
899  "DEFS : %s,CPPFLAGS : %s,\n"
900  "LDFLAGS : %s,LIBS : %s "
901 #ifdef __GNUC__
902  "(ver: " __VERSION__ ")"
903 #endif
904  "\n",AC_CONFIGURE_ARGS, CC,CFLAGS, CXX,CXXFLAGS, DEFS,CPPFLAGS, LDFLAGS,LIBS);
907  StringAppendS("\n");
908  return StringEndS();
909 }
910 
911 #ifdef PDEBUG
912 #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM)
913 void p_SetRingOfLeftv(leftv l, ring r)
914 {
915  switch(l->rtyp)
916  {
917  case INT_CMD:
918  case BIGINT_CMD:
919  case IDHDL:
920  case DEF_CMD:
921  break;
922  case POLY_CMD:
923  case VECTOR_CMD:
924  {
925  poly p=(poly)l->data;
926  while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); }
927  break;
928  }
929  case IDEAL_CMD:
930  case MODUL_CMD:
931  case MATRIX_CMD:
932  {
933  ideal I=(ideal)l->data;
934  int i;
935  for(i=IDELEMS(I)-1;i>=0;i--)
936  {
937  poly p=I->m[i];
938  while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); }
939  }
940  break;
941  }
942  case COMMAND:
943  {
944  command d=(command)l->data;
945  p_SetRingOfLeftv(&d->arg1, r);
946  if (d->argc>1) p_SetRingOfLeftv(&d->arg2, r);
947  if (d->argc>2) p_SetRingOfLeftv(&d->arg3, r);
948  break;
949  }
950  default:
951  printf("type %d not yet implementd in p_SetRingOfLeftv\n",l->rtyp);
952  break;
953  }
954 }
955 #endif
956 #endif
957 
958 #if 0 /* debug only */
959 void listall(int showproc)
960 {
961  idhdl hh=basePack->idroot;
962  PrintS("====== Top ==============\n");
963  while (hh!=NULL)
964  {
965  if (showproc || (IDTYP(hh)!=PROC_CMD))
966  {
967  if (IDDATA(hh)==(void *)currRing) PrintS("(R)");
968  else if (IDDATA(hh)==(void *)currPack) PrintS("(P)");
969  else PrintS(" ");
970  Print("::%s, typ %s level %d data %lx",
971  IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh));
972  if ((IDTYP(hh)==RING_CMD)
973  || (IDTYP(hh)==QRING_CMD))
974  Print(" ref: %d\n",IDRING(hh)->ref);
975  else
976  PrintLn();
977  }
978  hh=IDNEXT(hh);
979  }
980  hh=basePack->idroot;
981  while (hh!=NULL)
982  {
983  if (IDDATA(hh)==(void *)basePack)
984  Print("(T)::%s, typ %s level %d data %lx\n",
985  IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh));
986  else
987  if ((IDTYP(hh)==RING_CMD)
988  || (IDTYP(hh)==QRING_CMD)
989  || (IDTYP(hh)==PACKAGE_CMD))
990  {
991  Print("====== %s ==============\n",IDID(hh));
992  idhdl h2=IDRING(hh)->idroot;
993  while (h2!=NULL)
994  {
995  if (showproc || (IDTYP(h2)!=PROC_CMD))
996  {
997  if ((IDDATA(h2)==(void *)currRing)
998  && ((IDTYP(h2)==RING_CMD)||(IDTYP(h2)==QRING_CMD)))
999  PrintS("(R)");
1000  else if (IDDATA(h2)==(void *)currPack) PrintS("(P)");
1001  else PrintS(" ");
1002  Print("%s::%s, typ %s level %d data %lx\n",
1003  IDID(hh),IDID(h2),Tok2Cmdname(IDTYP(h2)),IDLEV(h2),(long)IDDATA(h2));
1004  }
1005  h2=IDNEXT(h2);
1006  }
1007  }
1008  hh=IDNEXT(hh);
1009  }
1010  Print("currRing:%lx, currPack:%lx,basePack:%lx\n",(long)currRing,(long)currPack,(long)basePack);
1011  iiCheckPack(currPack);
1012 }
1013 #endif
1014 
1015 #ifndef SING_NDEBUG
1016 void checkall()
1017 {
1018  idhdl hh=basePack->idroot;
1019  while (hh!=NULL)
1020  {
1021  omCheckAddr(hh);
1022  omCheckAddr((ADDRESS)IDID(hh));
1023  if (RingDependend(IDTYP(hh)))
1024  {
1025  Print("%s typ %d in Top (should be in ring)\n",IDID(hh),IDTYP(hh));
1026  }
1027  hh=IDNEXT(hh);
1028  }
1029  hh=basePack->idroot;
1030  while (hh!=NULL)
1031  {
1032  if (IDTYP(hh)==PACKAGE_CMD)
1033  {
1034  idhdl h2=IDPACKAGE(hh)->idroot;
1035  if (IDPACKAGE(hh)!=basePack)
1036  {
1037  while (h2!=NULL)
1038  {
1039  omCheckAddr(h2);
1040  omCheckAddr((ADDRESS)IDID(h2));
1041  if (RingDependend(IDTYP(h2)))
1042  {
1043  Print("%s typ %d in %s (should be in ring)\n",IDID(h2),IDTYP(h2),IDID(hh));
1044  }
1045  h2=IDNEXT(h2);
1046  }
1047  }
1048  }
1049  hh=IDNEXT(hh);
1050  }
1051 }
1052 #endif
1053 
1054 #include <sys/types.h>
1055 #include <sys/stat.h>
1056 #include <unistd.h>
1057 
1058 extern "C"
1059 int singular_fstat(int fd, struct stat *buf)
1060 {
1061  return si_fstat(fd,buf);
1062 }
1063 
1064 /*2
1065 * the global exit routine of Singular
1066 */
1067 extern "C" {
1068 /* Note: We cannot use a mutex here because mutexes are not async-safe, but
1069  * m2_end is called by sig_term_hdl(). Anyway, the race condition in the first
1070  * few lines of m2_end() should not matter.
1071  */
1073 
1074 void m2_end(int i)
1075 {
1076  if (!m2_end_called)
1077  {
1078  m2_end_called = TRUE;
1079 #ifdef HAVE_SIMPLEIPC
1080  for (int j = SIPC_MAX_SEMAPHORES; j >= 0; j--)
1081  {
1082  if (semaphore[j] != NULL)
1083  {
1084  while (sem_acquired[j] > 0)
1085  {
1086  sem_post(semaphore[j]);
1087  sem_acquired[j]--;
1088  }
1089  }
1090  }
1091 #endif // HAVE_SIMPLEIPC
1093 #ifdef PAGE_TEST
1094  mmEndStat();
1095 #endif
1098  {
1100  while(hh!=NULL)
1101  {
1102  //Print("close %s\n",hh->l->name);
1103  slPrepClose(hh->l);
1104  hh=(link_list)hh->next;
1105  }
1107 
1108  idhdl h = currPack->idroot;
1109  while(h != NULL)
1110  {
1111  if(IDTYP(h) == LINK_CMD)
1112  {
1113  idhdl hh=h->next;
1114  //Print("kill %s\n",IDID(h));
1115  killhdl(h, currPack);
1116  h = hh;
1117  }
1118  else
1119  {
1120  h = h->next;
1121  }
1122  }
1123  hh=ssiToBeClosed;
1124  while(hh!=NULL)
1125  {
1126  //Print("close %s\n",hh->l->name);
1127  slClose(hh->l);
1128  hh=ssiToBeClosed;
1129  }
1130  }
1131  if (!singular_in_batchmode)
1132  {
1133  if (i<=0)
1134  {
1135  if (TEST_V_QUIET)
1136  {
1137  if (i==0)
1138  printf("Auf Wiedersehen.\n");
1139  else
1140  printf("\n$Bye.\n");
1141  }
1142  //#ifdef sun
1143  // #ifndef __svr4__
1144  // _cleanup();
1145  // _exit(0);
1146  // #endif
1147  //#endif
1148  i=0;
1149  }
1150  else
1151  {
1152  printf("\nhalt %d\n",i);
1153  }
1154  }
1155  exit(i);
1156  }
1157 }
1158 }
1159 
1160 const char *singular_date=__DATE__ " " __TIME__;
1161 
1162 extern "C"
1163 {
1165  {
1166  fprintf(stderr, "\nSingular error: no more memory\n");
1167  omPrintStats(stderr);
1168  m2_end(14);
1169  /* should never get here */
1170  exit(1);
1171  }
1172 }
1173 
1174 #ifdef SINGULAR_4_1
1177 {
1178  if (a->Typ()!=INT_CMD)
1179  {
1180  WerrorS("`int` expected");
1181  return TRUE;
1182  }
1183  else
1184  {
1185  res->rtyp=CRING_CMD;
1186  res->data=(void*)nInitChar(n_pAE,(void*)a->Data());
1187  return FALSE;
1188  }
1189 }
1190 #endif
1191 /*2
1192 * initialize components of Singular
1193 */
1194 void siInit(char *name)
1195 {
1196 // factory default settings: -----------------------------------------------
1197  On(SW_USE_EZGCD);
1199  //On(SW_USE_FF_MOD_GCD);
1200  On(SW_USE_EZGCD_P);
1201  On(SW_USE_QGCD);
1202  Off(SW_USE_NTL_SORT); // may be changed by an command line option
1204 
1205 // memory initialization: -----------------------------------------------
1206  om_Opts.OutOfMemoryFunc = omSingOutOfMemoryFunc;
1207 #ifndef OM_NDEBUG
1208 #ifndef __OPTIMIZE__
1209  om_Opts.ErrorHook = dErrorBreak;
1210 #else
1211  om_Opts.Keep = 0; /* !OM_NDEBUG, __OPTIMIZE__*/
1212 #endif
1213 #else
1214  om_Opts.Keep = 0; /* OM_NDEBUG */
1215 #endif
1216  omInitInfo();
1217 
1218 // options ---------------------------------------------------------------
1219  si_opt_1=0;
1220 // interpreter tables etc.: -----------------------------------------------
1221  memset(&sLastPrinted,0,sizeof(sleftv));
1223 
1224  extern int iiInitArithmetic(); iiInitArithmetic(); // iparith.cc
1225 
1226  basePack=(package)omAlloc0(sizeof(*basePack));
1228  idhdl h;
1229  h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE);
1230  IDPACKAGE(h)->language = LANG_TOP;
1231  IDPACKAGE(h)=basePack;
1232  currPackHdl=h;
1233  basePackHdl=h;
1234 
1235  coeffs_BIGINT = nInitChar(n_Q,(void*)1);
1236 
1237 #if 1
1238  // def HAVE_POLYEXTENSIONS
1239  if(TRUE)
1240  {
1242  assume(type == n_algExt);
1243 
1244  type = nRegister(n_transExt, ntInitChar);
1245  assume(type == n_transExt);
1246 
1247  (void)type;
1248  }
1249 #endif
1250 
1251 // random generator: -----------------------------------------------
1252  int t=initTimer();
1253  if (t==0) t=1;
1254  initRTimer();
1255  siSeed=t;
1256  factoryseed(t);
1257  siRandomStart=t;
1258  feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart);
1259 
1260 // ressource table: ----------------------------------------------------
1261  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
1262  // hack such that all shared' libs in the bindir are loaded correctly
1263  feInitResources(name);
1264 
1265 // singular links: --------------------------------------------------
1266  slStandardInit();
1267  myynest=0;
1268 // semapohore 0 -----------------------------------------------------
1269  int cpus=2;
1270  int cpu_n;
1271  #ifdef _SC_NPROCESSORS_ONLN
1272  if ((cpu_n=sysconf(_SC_NPROCESSORS_ONLN))>cpus) cpus=cpu_n;
1273  #elif defined(_SC_NPROCESSORS_CONF)
1274  if ((cpu_n=sysconf(_SC_NPROCESSORS_CONF))>cpus) cpus=cpu_n;
1275  #endif
1276  feSetOptValue(FE_OPT_CPUS, cpus);
1277 
1278 #ifdef SINGULAR_4_1
1279 // default coeffs
1280  {
1281  idhdl h;
1282  h=enterid(omStrDup("QQ"),0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1283  IDDATA(h)=(char*)nInitChar(n_Q,NULL);
1284  h=enterid(omStrDup("ZZ"),0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1285  IDDATA(h)=(char*)nInitChar(n_Z,NULL);
1286  //h=enterid(omStrDup("RR"),0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1287  //IDDATA(h)=(char*)nInitChar(n_R,NULL);
1288  //h=enterid(omStrDup("CC"),0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1289  //IDDATA(h)=(char*)nInitChar(n_long_C,NULL);
1291  if (t!=n_unknown)
1292  {
1293  h=enterid(omStrDup("AE"),0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1294  IDDATA(h)=(char*)nInitChar(t,NULL);
1295  }
1297  if (t!=n_unknown)
1298  {
1299  h=enterid(omStrDup("QAE"),0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1300  IDDATA(h)=(char*)nInitChar(t,NULL);
1301  }
1303  if (n_pAE!=n_unknown)
1304  {
1305  iiAddCproc("kernel","pAE",FALSE,ii_pAE_init);
1306  }
1307  }
1308 #endif
1309 // loading standard.lib -----------------------------------------------
1310  if (! feOptValue(FE_OPT_NO_STDLIB))
1311  {
1312  BITSET save1,save2;
1313  SI_SAVE_OPT(save1,save2);
1314  si_opt_2 &= ~Sy_bit(V_LOAD_LIB);
1315  iiLibCmd(omStrDup("standard.lib"), TRUE,TRUE,TRUE);
1316  SI_RESTORE_OPT(save1,save2);
1317  }
1318  errorreported = 0;
1319 }
#define OPT_REDSB
Definition: options.h:71
int iiInitArithmetic()
initialisation of arithmetic structured data
Definition: iparith.cc:8898
void m2_end(int i)
Definition: misc_ip.cc:1074
int status int fd
Definition: si_signals.h:58
#define TEST_V_QUIET
Definition: options.h:127
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
const const intvec const intvec const ring _currRing const const intvec const intvec const ring _currRing int
Definition: gb_hack.h:53
static void factor_gmp(mpz_t t, lists primes, int *multiplicities, int &index, unsigned long bound)
Definition: misc_ip.cc:299
ip_package * package
Definition: structs.h:46
void omSingOutOfMemoryFunc()
Definition: misc_ip.cc:1164
const CanonicalForm int s
Definition: facAbsFact.cc:55
unsigned si_opt_1
Definition: options.c:5
This file provides miscellaneous functionality.
sleftv * m
Definition: lists.h:45
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition: feread.cc:33
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
#define OPT_PROT
Definition: options.h:70
BOOLEAN n_AEInitChar(coeffs r, void *)
Definition: OPAE.cc:339
void factoryseed(int s)
random seed initializer
Definition: cf_random.cc:176
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
void singular_example(char *str)
Definition: misc_ip.cc:435
#define MAXPATHLEN
Definition: omRet2Info.c:22
ip_command * command
Definition: ipid.h:24
#define V_COEFSTRAT
Definition: options.h:59
static FORCE_INLINE void number2mpz(number n, mpz_t m)
Definition: misc_ip.cc:42
const poly a
Definition: syzextra.cc:212
void PrintLn()
Definition: reporter.cc:322
static CanonicalForm bound(const CFMatrix &M)
Definition: cf_linsys.cc:460
#define Print
Definition: emacs.cc:83
void feStringAppendResources(int warn)
Definition: reporter.cc:410
Definition: tok.h:85
const BOOLEAN p_procs_dynamic
#define OPT_INFREDTAIL
Definition: options.h:89
static void * feOptValue(feOptIndex opt)
Definition: feOpt.h:40
void Off(int sw)
switches
idhdl currPackHdl
Definition: ipid.cc:60
#define V_LENGTH
Definition: options.h:61
Definition: lists.h:22
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition: algext.cc:1389
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition: coeffs.h:37
loop
Definition: myNF.cc:98
#define IDID(a)
Definition: ipid.h:121
volatile BOOLEAN m2_end_called
Definition: misc_ip.cc:1072
#define FALSE
Definition: auxiliary.h:140
#define OM_CHECK
Definition: omtTest.c:4
Definition: tok.h:42
return P p
Definition: myNF.cc:203
f
Definition: cfModGcd.cc:4022
static void factor_using_pollard_rho(mpz_t n, unsigned long a, lists primes, int *multiplicities, int &index)
Definition: misc_ip.cc:176
void siInit(char *name)
Definition: misc_ip.cc:1194
void setListEntry(lists L, int index, mpz_t n)
Definition: misc_ip.cc:46
#define V_LOAD_LIB
Definition: options.h:45
#define SINGULAR_VERSION
Definition: mod2.h:94
static unsigned add[]
Definition: misc_ip.cc:79
static char * feResource(feResourceConfig config, int warn)
Definition: feResource.cc:252
#define OPT_MULTBOUND
Definition: options.h:84
char * fe_fgets(const char *pr, char *s, int size)
Definition: feread.cc:310
static const int SW_USE_EZGCD_P
set to 1 to use EZGCD over F_q
Definition: cf_defs.h:34
rational (GMP) numbers
Definition: coeffs.h:30
#define V_DEF_RES
Definition: options.h:48
#define OPT_NO_SYZ_MINIM
Definition: options.h:78
char * showOption()
Definition: misc_ip.cc:726
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:537
int singular_fstat(int fd, struct stat *buf)
Definition: misc_ip.cc:1059
#define IDNEXT(a)
Definition: ipid.h:117
#define V_FINDMONOM
Definition: options.h:58
BOOLEAN n_QAEInitChar(coeffs r, void *)
Definition: OPAEQ.cc:331
const ideal
Definition: gb_hack.h:42
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
#define IDROOT
Definition: ipid.h:20
char * fe_fgets_dummy(const char *, char *, int)
Definition: feread.cc:418
#define OPT_OLDSTD
Definition: options.h:81
int siRandomStart
Definition: cntrlc.cc:109
static const int SW_USE_NTL_SORT
set to 1 to sort factors in a factorization
Definition: cf_defs.h:36
#define TRUE
Definition: auxiliary.h:144
#define FORCE_INLINE
Definition: auxiliary.h:386
static unsigned short primes[]
primes, primes_len: used to step through possible extensions
void * ADDRESS
Definition: auxiliary.h:161
void * value
Definition: fegetopt.h:93
SI_FOREACH_BUILTIN(SI_GET_BUILTIN_MOD_INIT0)}
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition: feOpt.cc:153
void feInitResources(const char *argv0)
Definition: feResource.cc:164
void WerrorS(const char *s)
Definition: feFopen.cc:23
void initRTimer()
Definition: timer.cc:158
void omPrintStats(FILE *fd)
Definition: omStats.c:114
int k
Definition: cfEzgcd.cc:93
char * StringEndS()
Definition: reporter.cc:151
static n_coeffType n_pAE
Definition: misc_ip.cc:1175
idhdl basePackHdl
Definition: ipid.cc:61
#define V_DEBUG_LIB
Definition: options.h:46
#define V_INTERSECT_ELIM
Definition: options.h:64
#define BITSET
Definition: structs.h:17
coeffs coeffs_BIGINT
Definition: ipid.cc:53
int Typ()
Definition: subexpr.cc:949
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define Sy_bit(x)
Definition: options.h:30
static FORCE_INLINE number mpz2number(mpz_t m)
Definition: misc_ip.cc:43
BOOLEAN iiLibCmd(char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition: iplib.cc:801
#define OM_TRACK
Definition: mod2.h:290
Definition: idrec.h:34
#define IDHDL
Definition: tok.h:35
char * versionString()
Definition: misc_ip.cc:783
void checkall()
Definition: misc_ip.cc:1016
BITSET validOpts
Definition: kstd1.cc:70
omOpts_t om_Opts
Definition: omOpts.c:11
static BOOLEAN rField_has_simple_inverse(const ring r)
Definition: ring.h:488
void * data
Definition: subexpr.h:89
void feStringAppendBrowsers(int warn)
Definition: fehelp.cc:352
void setListEntry_ui(lists L, int index, unsigned long ui)
Definition: misc_ip.cc:63
#define pIter(p)
Definition: monomials.h:44
#define V_QRING
Definition: options.h:40
unsigned setval
Definition: iplib.cc:305
poly res
Definition: myNF.cc:322
#define IDPACKAGE(a)
Definition: ipid.h:138
int myynest
Definition: febase.cc:46
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:12
#define V_SHOW_USE
Definition: options.h:50
#define IDTYP(a)
Definition: ipid.h:118
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:256
#define V_SHOW_MEM
Definition: options.h:41
Definition: tok.h:56
int RingDependend(int t)
Definition: gentable.cc:23
sem_t * semaphore[SIPC_MAX_SEMAPHORES]
Definition: semaphore.c:29
const ring r
Definition: syzextra.cc:208
#define SI_RESTORE_OPT(A, B)
Definition: options.h:22
BOOLEAN singular_in_batchmode
Definition: cntrlc.cc:78
#define MDEBUG
Definition: mod2.h:196
Coefficient rings, fields and other domains suitable for Singular polynomials.
void omInitInfo()
Definition: omStats.c:17
#define TEST_OPT_INTSTRATEGY
Definition: options.h:105
Definition: intvec.h:16
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
Definition: numbers.cc:507
#define OPT_REDTAIL
Definition: options.h:86
#define OPT_NOT_BUCKETS
Definition: options.h:72
int j
Definition: myNF.cc:70
Definition: tok.h:58
unsigned resetval
Definition: iplib.cc:306
const char * name
Definition: subexpr.h:88
#define omFree(addr)
Definition: omAllocDecl.h:261
#define p_SetRingOfLm(p, r)
Definition: monomials.h:152
struct soptionStruct verboseStruct[]
Definition: misc_ip.cc:549
polyrec * poly
Definition: hilb.h:10
#define assume(x)
Definition: mod2.h:405
char * fe_fgets_stdin_emu(const char *pr, char *s, int size)
Definition: feread.cc:254
void StringSetS(const char *st)
Definition: reporter.cc:128
int status int void * buf
Definition: si_signals.h:58
struct soptionStruct optionStruct[]
Definition: misc_ip.cc:519
void StringAppendS(const char *st)
Definition: reporter.cc:107
struct fe_option feOptSpec[]
#define OPT_NOT_SUGAR
Definition: options.h:73
void fe_reset_input_mode()
Definition: fereadl.c:826
All the auxiliary stuff.
#define V_CONTENTSB
Definition: options.h:54
#define V_UPTORADICAL
Definition: options.h:57
int m
Definition: cfEzgcd.cc:119
#define OPT_STAIRCASEBOUND
Definition: options.h:83
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:41
void On(int sw)
switches
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:46
#define StringAppend
Definition: emacs.cc:82
int i
Definition: cfEzgcd.cc:123
void PrintS(const char *s)
Definition: reporter.cc:294
idhdl next
Definition: idrec.h:38
#define version
Definition: libparse.cc:1260
static const int SW_USE_CHINREM_GCD
set to 1 to use modular gcd over Z
Definition: cf_defs.h:38
Definition: tok.h:88
#define IDELEMS(i)
Definition: simpleideals.h:19
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:464
BOOLEAN iiEStart(char *example, procinfo *pi)
Definition: iplib.cc:655
#define IDLEV(a)
Definition: ipid.h:120
#define V_READING
Definition: options.h:44
short errorreported
Definition: feFopen.cc:22
leftv next
Definition: subexpr.h:87
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:597
#define OPT_SUGARCRIT
Definition: options.h:75
#define OPT_INTSTRATEGY
Definition: options.h:87
#define BVERBOSE(a)
Definition: options.h:33
INLINE_THIS void Init(int l=0)
Definition: lists.h:66
CanonicalForm test
Definition: cfModGcd.cc:4037
#define V_LOAD_PROC
Definition: options.h:47
#define IDPROC(a)
Definition: ipid.h:139
#define V_ALLWARN
Definition: options.h:63
#define OPT_DEBUG
Definition: options.h:76
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
BOOLEAN n_pAEInitChar(coeffs r, void *p)
Definition: OPAEp.cc:351
#define mpz_size1(A)
Definition: si_gmp.h:12
n_coeffType
Definition: coeffs.h:26
char name(const Variable &v)
Definition: variable.h:95
#define V_YACC
Definition: options.h:42
#define SEEK_END
Definition: mod2.h:121
Definition: tok.h:95
#define V_PROMPT
Definition: options.h:52
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:428
#define NULL
Definition: omList.c:10
#define VERSION
Definition: mod2.h:21
slists * lists
Definition: mpr_numeric.h:146
#define OPT_WEIGHTM
Definition: options.h:92
int yydebug
Definition: grammar.cc:1862
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:329
int siSeed
Definition: sirandom.c:29
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:128
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic ...
Definition: coeffs.h:34
#define V_NSB
Definition: options.h:53
#define V_CANCELUNIT
Definition: options.h:55
void killhdl(idhdl h, package proot)
Definition: ipid.cc:369
const char * singular_date
Definition: misc_ip.cc:1160
package basePack
Definition: ipid.cc:63
static const int SW_USE_QGCD
set to 1 to use Encarnacion GCD over Q(a)
Definition: cf_defs.h:40
static const int SW_USE_EZGCD
set to 1 to use EZGCD over Z
Definition: cf_defs.h:32
#define IDRING(a)
Definition: ipid.h:126
const CanonicalForm & w
Definition: facAbsFact.cc:55
package currPack
Definition: ipid.cc:62
Variable x
Definition: cfModGcd.cc:4023
int rtyp
Definition: subexpr.h:92
#define SI_SAVE_OPT(A, B)
Definition: options.h:19
sleftv sLastPrinted
Definition: subexpr.cc:55
#define SIPC_MAX_SEMAPHORES
Definition: simpleipc.h:10
void Clean(ring r=currRing)
Definition: lists.h:25
void * Data()
Definition: subexpr.cc:1091
#define OPT_REDTHROUGH
Definition: options.h:77
int initTimer()
Definition: timer.cc:69
#define V_INTERSECT_SYZ
Definition: options.h:65
Definition: tok.h:96
char * iiGetLibName(procinfov pi)
Definition: iplib.cc:101
#define SI_SHOW_BUILTIN_MODULE(name)
omBin slists_bin
Definition: lists.cc:23
const char factoryVersion[]
extern const char factoryVersion[];
Definition: tok.h:126
#define TEST_RINGDEP_OPTS
Definition: options.h:95
#define omCheckAddr(addr)
Definition: omAllocDecl.h:328
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), where m is the long representing n in C: TRUE iff (Im(n) != 0 and Im(n) >= 0) or (Im(n) == 0 and Re(n) >= 0) in K(a)/: TRUE iff (n != 0 and (LC(n) > 0 or deg(n) > 0)) in K(t_1, ..., t_n): TRUE iff (LC(numerator(n) is a constant and > 0) or (LC(numerator(n) is not a constant) in Z/2^kZ: TRUE iff 0 < n <= 2^(k-1) in Z/mZ: TRUE iff the internal mpz is greater than zero in Z: TRUE iff n > 0
Definition: coeffs.h:494
void iiCheckPack(package &p)
Definition: ipshell.cc:1629
#define SEEK_SET
Definition: mod2.h:125
#define OPT_DEGBOUND
Definition: options.h:85
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:991
kBucketDestroy & P
Definition: myNF.cc:191
#define IDDATA(a)
Definition: ipid.h:125
#define OPT_NOTREGULARITY
Definition: options.h:91
char * fe_fgets_stdin_drl(const char *pr, char *s, int size)
Definition: feread.cc:270
int sem_acquired[SIPC_MAX_SEMAPHORES]
Definition: semaphore.c:30
const char * name
Definition: iplib.cc:304
static int factor_using_division(mpz_t t, unsigned int limit, lists primes, int *multiplicities, int &index, unsigned long bound)
Definition: misc_ip.cc:81
#define OPT_INTERRUPT
Definition: options.h:74
unsigned si_opt_2
Definition: options.c:6
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition: iplib.cc:200
static Poly * h
Definition: janet.cc:978
int BOOLEAN
Definition: auxiliary.h:131
static BOOLEAN ii_pAE_init(leftv res, leftv a)
Definition: misc_ip.cc:1176
#define NONE
Definition: tok.h:170
#define V_REDEFINE
Definition: options.h:43
void dErrorBreak()
Definition: dError.cc:141
void Werror(const char *fmt,...)
Definition: reporter.cc:199
#define OPT_FASTHC
Definition: options.h:80
void * CopyD(int t)
Definition: subexpr.cc:656
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:94
#define V_MODPSOLVSB
Definition: options.h:56
int si_echo
Definition: febase.cc:41
void(* factoryError)(const char *s)
Definition: cf_util.cc:75
BOOLEAN setOption(leftv res, leftv v)
Definition: misc_ip.cc:578
#define COMMAND
Definition: tok.h:33
#define OPT_RETURN_SB
Definition: options.h:79
#define V_IMAP
Definition: options.h:51
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:316
BOOLEAN ntInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition: transext.cc:2370
#define Warn
Definition: emacs.cc:80
#define omStrDup(s)
Definition: omAllocDecl.h:263