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