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
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 }
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 {
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 {
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 {
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 {
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 {
178 break;
179 }
180 }
181 else
182 {
183 mpz_swap (t, q);
184 if (f!=last_f)
185 {
188 index++;
189 }
190 else
191 {
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;
210 unsigned long long k, l, i;
211
212 mpz_init (t1);
213 mpz_init (t2);
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
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 {
280 a = a_limb;
281 }
282 while (a == 0);
283
285 }
286 else
287 {
288 if (mpz_cmp(t1,last_f)==0)
289 {
291 }
292 else
293 {
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 {
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);
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. */
337 if (division_limit > 1000)
338 division_limit = 1000 * 1000;
339 else
341
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
354 }
355 }
356}
357/* n and pBound are assumed to be bigint numbers */
359{
360 int i;
361 int index=0;
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 }
375 }
376
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
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 }
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);
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 */
522 {"staircaseBound",Sy_bit(OPT_STAIRCASEBOUND),~Sy_bit(OPT_STAIRCASEBOUND) },
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 */
533 {"notRegularity",Sy_bit(OPT_NOTREGULARITY), ~Sy_bit(OPT_NOTREGULARITY) },
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 ) {
619 si_opt_1 &=~Sy_bit(OPT_INTSTRATEGY);
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 ) {
649 test &=~Sy_bit(OPT_INTSTRATEGY);
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
706 else om_sing_opt_show_mem = 0;
707
708 return FALSE;
709}
710
712{
713 int i;
714 BITSET tmp;
715
716 StringSetS("//options:");
717 if ((si_opt_1!=0)||(si_opt_2!=0))
718 {
720 if(tmp)
721 {
722 for (i=0; optionStruct[i].setval!=0; i++)
723 {
724 if (optionStruct[i].setval & tmp)
725 {
727 tmp &=optionStruct[i].resetval;
728 }
729 }
730 for (i=0; i<32; i++)
731 {
732 if (tmp & Sy_bit(i)) StringAppend(" %d",i);
733 }
734 }
736 if (tmp)
737 {
738 for (i=0; verboseStruct[i].setval!=0; i++)
739 {
740 if (verboseStruct[i].setval & tmp)
741 {
743 tmp &=verboseStruct[i].resetval;
744 }
745 }
746 for (i=1; i<32; i++)
747 {
748 if (tmp & Sy_bit(i)) StringAppend(" %d",i+32);
749 }
750 }
751 return StringEndS();
752 }
753 StringAppendS(" none");
754 return StringEndS();
755}
756
757/* version strings */
758#ifdef HAVE_FLINT
759#ifndef __GMP_BITS_PER_MP_LIMB
760#define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS
761#endif
762#include <flint/flint.h>
763#endif
764
765#ifndef MAKE_DISTRIBUTION
767#endif
768
769char * versionString(/*const bool bShowDetails = false*/ )
770{
771 StringSetS("");
772 StringAppend("Singular for %s version %s (%d, %d bit) %s",
773 S_UNAME, VERSION, // SINGULAR_VERSION,
774 SINGULAR_VERSION, sizeof(void*)*8,
777#else
779#endif
780 StringAppendS("\nwith\n\t");
781
782#if defined(mpir_version)
783 StringAppend("MPIR(%s)~GMP(%s),", mpir_version, gmp_version);
784#elif defined(gmp_version)
785 // #if defined (__GNU_MP_VERSION) && defined (__GNU_MP_VERSION_MINOR)
786 // StringAppend("GMP(%d.%d),",__GNU_MP_VERSION,__GNU_MP_VERSION_MINOR);
787 StringAppend("GMP(%s),", gmp_version);
788#endif
789#ifdef HAVE_NTL
790 StringAppend("NTL(%s),",NTL_VERSION);
791#endif
792
793#ifdef HAVE_FLINT
794 StringAppend("FLINT(%s),",FLINT_VERSION);
795#endif
796// StringAppendS("factory(" FACTORYVERSION "),");
797 StringAppendS("\n\t");
798#ifndef HAVE_OMALLOC
799 StringAppendS("xalloc,");
800#else
801 StringAppendS("omalloc,");
802#endif
803#if defined(HAVE_DYN_RL)
805 StringAppendS("no input,");
806 else if (fe_fgets_stdin==fe_fgets)
807 StringAppendS("fgets,");
809 StringAppend("dynamic readline%d),",RL_VERSION_MAJOR);
810 #ifdef HAVE_FEREAD
812 StringAppendS("emulated readline,");
813 #endif
814 else
815 StringAppendS("unknown fgets method,");
816#else
817 #if defined(HAVE_READLINE) && !defined(FEREAD)
818 StringAppend("static readline(%d),",RL_VERSION_MAJOR);
819 #else
820 #ifdef HAVE_FEREAD
821 StringAppendS("emulated readline,");
822 #else
823 StringAppendS("fgets,");
824 #endif
825 #endif
826#endif
827#ifdef HAVE_PLURAL
828 StringAppendS("Plural,");
829#endif
830#ifdef HAVE_VSPACE
831 #if defined(__GNUC__) && (__GNUC__<9) &&!defined(__clang__)
832 StringAppendS("vspace(1),");
833 #else
834 StringAppendS("vspace(2),");
835 #endif
836#endif
837#ifdef HAVE_DBM
838 StringAppendS("DBM,\n\t");
839#else
840 StringAppendS("\n\t");
841#endif
842#ifdef HAVE_DYNAMIC_LOADING
843 StringAppendS("dynamic modules,");
844#endif
845#ifdef HAVE_DYNANIC_PPROCS
846 StringAppendS("dynamic p_Procs,");
847#endif
848#if YYDEBUG
849 StringAppendS("YYDEBUG=1,");
850#endif
851#ifdef MDEBUG
852 StringAppend("MDEBUG=%d,",MDEBUG);
853#endif
854#ifdef OM_CHECK
855 StringAppend("OM_CHECK=%d,",OM_CHECK);
856#endif
857#ifdef OM_TRACK
858 StringAppend("OM_TRACK=%d,",OM_TRACK);
859#endif
860#ifdef OM_NDEBUG
861 StringAppendS("OM_NDEBUG,");
862#endif
863#ifdef SING_NDEBUG
864 StringAppendS("SING_NDEBUG,");
865#endif
866#ifdef PDEBUG
867 StringAppendS("PDEBUG,");
868#endif
869#ifdef KDEBUG
870 StringAppendS("KDEBUG,");
871#endif
872#ifdef HAVE_SDB
873 StringAppendS("sdb,");
874#endif
875 StringAppendS("\n\t");
876#ifdef __OPTIMIZE__
877 StringAppendS("CC:OPTIMIZE,");
878#endif
879#ifdef __OPTIMIZE_SIZE__
880 StringAppendS("CC:OPTIMIZE_SIZE,");
881#endif
882#ifdef __NO_INLINE__
883 StringAppendS("CC:NO_INLINE,");
884#endif
885#ifdef HAVE_NTL
886 #ifdef NTL_AVOID_BRANCHING
887 #undef HAVE_GENERIC_ADD
888 #endif
889#endif
890#ifdef HAVE_GENERIC_ADD
891 StringAppendS("GenericAdd,");
892#else
893 StringAppendS("AvoidBranching,");
894#endif
895#ifdef HAVE_GENERIC_MULT
896 StringAppendS("GenericMult,");
897#else
898 StringAppendS("TableMult,");
899#endif
900#ifdef HAVE_INVTABLE
901 StringAppendS("invTable,");
902#else
903 StringAppendS("no invTable,");
904#endif
905 StringAppendS("\n\t");
906#ifdef HAVE_EIGENVAL
907 StringAppendS("eigenvalues,");
908#endif
909#ifdef HAVE_GMS
910 StringAppendS("Gauss-Manin system,");
911#endif
912#ifdef HAVE_RATGRING
913 StringAppendS("ratGB,");
914#endif
915 StringAppend("random=%d\n",siRandomStart);
916
917#define SI_SHOW_BUILTIN_MODULE(name) StringAppend(" %s", #name);
918 StringAppendS("built-in modules: {");
920 StringAppendS("}\n");
921#undef SI_SHOW_BUILTIN_MODULE
922
923 StringAppend("AC_CONFIGURE_ARGS = %s,\n"
924 "CC = %s,FLAGS : %s,\n"
925 "CXX = %s,FLAGS : %s,\n"
926 "DEFS : %s,CPPFLAGS : %s,\n"
927 "LDFLAGS : %s,LIBS : %s "
929 "(ver: " __VERSION__ ")"
930#endif
933 LIBS " " PTHREAD_LIBS);
936 StringAppendS("\n");
937 return StringEndS();
938}
939
940#ifdef PDEBUG
941#if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM)
943{
944 switch(l->rtyp)
945 {
946 case INT_CMD:
947 case BIGINT_CMD:
948 case IDHDL:
949 case DEF_CMD:
950 break;
951 case POLY_CMD:
952 case VECTOR_CMD:
953 {
954 poly p=(poly)l->data;
955 while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); }
956 break;
957 }
958 case IDEAL_CMD:
959 case MODUL_CMD:
960 case MATRIX_CMD:
961 {
962 ideal I=(ideal)l->data;
963 int i;
964 for(i=IDELEMS(I)-1;i>=0;i--)
965 {
966 poly p=I->m[i];
967 while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); }
968 }
969 break;
970 }
971 case COMMAND:
972 {
973 command d=(command)l->data;
974 p_SetRingOfLeftv(&d->arg1, r);
975 if (d->argc>1) p_SetRingOfLeftv(&d->arg2, r);
976 if (d->argc>2) p_SetRingOfLeftv(&d->arg3, r);
977 break;
978 }
979 default:
980 printf("type %d not yet implementd in p_SetRingOfLeftv\n",l->rtyp);
981 break;
982 }
983}
984#endif
985#endif
986
987#if 0 /* debug only */
988void listall(int showproc)
989{
990 idhdl hh=basePack->idroot;
991 PrintS("====== Top ==============\n");
992 while (hh!=NULL)
993 {
994 if (showproc || (IDTYP(hh)!=PROC_CMD))
995 {
996 if (IDDATA(hh)==(void *)currRing) PrintS("(R)");
997 else if (IDDATA(hh)==(void *)currPack) PrintS("(P)");
998 else PrintS(" ");
999 Print("::%s, typ %s level %d data %lx",
1000 IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh));
1001 if (IDTYP(hh)==RING_CMD)
1002 Print(" ref: %d\n",IDRING(hh)->ref);
1003 else
1004 PrintLn();
1005 }
1006 hh=IDNEXT(hh);
1007 }
1008 hh=basePack->idroot;
1009 while (hh!=NULL)
1010 {
1011 if (IDDATA(hh)==(void *)basePack)
1012 Print("(T)::%s, typ %s level %d data %lx\n",
1013 IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh));
1014 else
1015 if ((IDTYP(hh)==RING_CMD)
1016 || (IDTYP(hh)==PACKAGE_CMD))
1017 {
1018 Print("====== %s ==============\n",IDID(hh));
1019 idhdl h2=IDRING(hh)->idroot;
1020 while (h2!=NULL)
1021 {
1022 if (showproc || (IDTYP(h2)!=PROC_CMD))
1023 {
1024 if ((IDDATA(h2)==(void *)currRing)
1025 && (IDTYP(h2)==RING_CMD))
1026 PrintS("(R)");
1027 else if (IDDATA(h2)==(void *)currPack) PrintS("(P)");
1028 else PrintS(" ");
1029 Print("%s::%s, typ %s level %d data %lx\n",
1030 IDID(hh),IDID(h2),Tok2Cmdname(IDTYP(h2)),IDLEV(h2),(long)IDDATA(h2));
1031 }
1032 h2=IDNEXT(h2);
1033 }
1034 }
1035 hh=IDNEXT(hh);
1036 }
1037 Print("currRing:%lx, currPack:%lx,basePack:%lx\n",(long)currRing,(long)currPack,(long)basePack);
1039}
1040#endif
1041
1042#ifndef SING_NDEBUG
1043void checkall()
1044{
1045 idhdl hh=basePack->idroot;
1046 while (hh!=NULL)
1047 {
1048 omCheckAddr(hh);
1050 if (RingDependend(IDTYP(hh)))
1051 {
1052 Print("%s typ %d in Top (should be in ring)\n",IDID(hh),IDTYP(hh));
1053 }
1054 hh=IDNEXT(hh);
1055 }
1056 hh=basePack->idroot;
1057 while (hh!=NULL)
1058 {
1059 if (IDTYP(hh)==PACKAGE_CMD)
1060 {
1061 idhdl h2=NULL;
1062 if (IDPACKAGE(hh)!=NULL)
1063 h2=IDPACKAGE(hh)->idroot;
1064 if (IDPACKAGE(hh)!=basePack)
1065 {
1066 while (h2!=NULL)
1067 {
1068 omCheckAddr(h2);
1070 if (RingDependend(IDTYP(h2)))
1071 {
1072 Print("%s typ %d in %s (should be in ring)\n",IDID(h2),IDTYP(h2),IDID(hh));
1073 }
1074 h2=IDNEXT(h2);
1075 }
1076 }
1077 }
1078 hh=IDNEXT(hh);
1079 }
1080}
1081#endif
1082
1083extern "C"
1084int singular_fstat(int fd, struct stat *buf)
1085{
1086 return si_fstat(fd,buf);
1087}
1088
1089/*2
1090* the global exit routine of Singular
1091*/
1092extern "C" {
1093/* Note: We cannot use a mutex here because mutexes are not async-safe, but
1094 * m2_end is called by sig_term_hdl(). Anyway, the race condition in the first
1095 * few lines of m2_end() should not matter.
1096 */
1098
1099/* m2_end(0): close everything and return
1100 * m2_end(1): close everything and exit(0)
1101 * m2_end(i<0): close everything and _exit(0) (for children))
1102 * m2_end(i>1): close everything and exit(i)
1103 */
1104void m2_end(int i)
1105{
1106 if (!m2_end_called)
1107 {
1112 if (File_Log!=NULL)
1113 {
1115 File_Log=NULL;
1116 if (File_Log_written==FALSE) // remove empty logs
1117 {
1118 int pid=getpid();
1119 char buf[20];
1120 snprintf(buf,20,"/tmp/sing_log.%d",pid);
1121 remove(buf);
1122 }
1123 }
1125#ifdef HAVE_SIMPLEIPC
1126 for (int j = SIPC_MAX_SEMAPHORES-1; j >= 0; j--)
1127 {
1128 if (semaphore[j] != NULL)
1129 {
1130 while (sem_acquired[j] > 0)
1131 {
1132#if PORTABLE_SEMAPHORES
1133 sem_post(semaphore[j]->sig);
1134#else
1136#endif
1137 sem_acquired[j]--;
1138 }
1139 }
1140 }
1141#endif // HAVE_SIMPLEIPC
1142 monitor(NULL,0);
1144 {
1146 while(hh!=NULL)
1147 {
1148 //Print("close %s\n",hh->l->name);
1149 slPrepClose(hh->l);
1150 hh=(link_list)hh->next;
1151 }
1153
1154 idhdl h = currPack->idroot;
1155 while(h != NULL)
1156 {
1157 if(IDTYP(h) == LINK_CMD)
1158 {
1159 idhdl hh=h->next;
1160 //Print("kill %s\n",IDID(h));
1161 killhdl(h, currPack);
1162 h = hh;
1163 }
1164 else
1165 {
1166 h = h->next;
1167 }
1168 }
1170 while(hh!=NULL)
1171 {
1172 //Print("close %s\n",hh->l->name);
1173 slClose(hh->l);
1175 }
1176 }
1177#ifdef PAGE_TEST
1178 mmEndStat();
1179#endif
1182 {
1183 if (TEST_V_QUIET)
1184 {
1185 if ((i==0)||(i==1))
1186 printf("Auf Wiedersehen.\n");
1187 }
1188 if (i>1)
1189 {
1190 printf("\nhalt %d\n",i);
1191 }
1192 }
1193 if (i>1) exit(i);
1194 else if (i==1) exit(0);
1195 else if (i<0) _exit(0);
1196 }
1197}
1198}
1199
1200extern "C"
1201{
1203 {
1204 fprintf(stderr, "\nSingular error: no more memory\n");
1206 m2_end(14);
1207 /* should never get here */
1208 exit(1);
1209 }
1210}
1211
1212#ifdef HAVE_FLINT
1215//STATIC_VAR n_coeffType n_FlintQrat=n_unknown;
1217{
1218 const short t[]={2,INT_CMD,STRING_CMD};
1219 if (iiCheckTypes(a,t,1))
1220 {
1222 p.ch=(int)(long)a->Data();
1223 p.name=(char*)a->next->Data();
1224 res->rtyp=CRING_CMD;
1225 res->data=(void*)nInitChar(n_FlintZn,(void*)&p);
1226 return FALSE;
1227 }
1228 return TRUE;
1229}
1231{
1232 const short t[]={1,STRING_CMD};
1233 if (iiCheckTypes(a,t,1))
1234 {
1235 char* p;
1236 p=(char*)a->Data();
1237 res->rtyp=CRING_CMD;
1238 res->data=(void*)nInitChar(n_FlintQ,(void*)p);
1239 return FALSE;
1240 }
1241 return TRUE;
1242}
1243#if __FLINT_RELEASE >= 20503
1245{
1246 if (a==NULL)
1247 {
1248 WerrorS("at least one name required");
1249 return TRUE;
1250 }
1251 QaInfo par;
1252 #ifdef QA_DEBUG
1253 par.C=r->cf;
1254 a=a->next;
1255 #endif
1256 par.N=a->listLength();
1257 par.names=(char**)omAlloc(par.N*sizeof(char*));
1258 int i=0;
1259 while(a!=NULL)
1260 {
1261 par.names[i]=omStrDup(a->Name());
1262 i++;
1263 a=a->next;
1264 }
1265 res->rtyp=CRING_CMD;
1266 res->data=(void*)nInitChar(n_FlintQrat,&par);
1267 for(i=par.N-1;i>=0;i--)
1268 {
1269 omFree(par.names[i]);
1270 }
1271 omFreeSize(par.names,par.N*sizeof(char*));
1272 return FALSE;
1273}
1274#endif
1276{
1277 package save=currPack;
1280 if (n_FlintQ!=n_unknown)
1281 {
1282 iiAddCproc("kernel","flintQp",FALSE,ii_FlintQ_init);
1284 }
1285#if __FLINT_RELEASE >= 20503
1286 iiAddCproc("kernel","flintQ",FALSE,ii_FlintQrat_init);
1288#endif
1290 if (n_FlintZn!=n_unknown)
1291 {
1292 iiAddCproc("kernel","flintZn",FALSE,ii_FlintZn_init);
1294 }
1295 currPack=save;
1296 return MAX_TOK;
1297}
1298#endif
1299
1301{
1302 short float_len=3;
1303 short float_len2=SHORT_REAL_LENGTH;
1304 coeffs cf=NULL;
1305 if ((pnn!=NULL) && (pnn->Typ()==INT_CMD))
1306 {
1307 float_len=(int)(long)pnn->Data();
1308 float_len2=float_len;
1309 pnn=pnn->next;
1310 if ((pnn!=NULL) && (pnn->Typ()==INT_CMD))
1311 {
1312 float_len2=(int)(long)pnn->Data();
1313 pnn=pnn->next;
1314 }
1315 }
1316 if (float_len2 <= (short)SHORT_REAL_LENGTH)
1317 cf=nInitChar(n_R, NULL);
1318 else // longR or longC?
1319 {
1321 param.float_len = si_min (float_len, 32767);
1322 param.float_len2 = si_min (float_len2, 32767);
1323 cf = nInitChar(n_long_R, (void*)&param);
1324 }
1325 res->rtyp=CRING_CMD;
1326 res->data=cf;
1327 return cf==NULL;
1328}
1330{
1331 leftv h=args;
1332 coeffs *c=NULL;
1333 coeffs cf=NULL;
1334 int i=0;
1335 if (h==NULL) goto crossprod_error;
1336 while (h!=NULL)
1337 {
1338 if (h->Typ()!=CRING_CMD) goto crossprod_error;
1339 i++;
1340 h=h->next;
1341 }
1342 c=(coeffs*)omAlloc0((i+1)*sizeof(coeffs));
1343 h=args;
1344 i=0;
1345 while (h!=NULL)
1346 {
1347 c[i]=(coeffs)h->CopyD();
1348 i++;
1349 h=h->next;
1350 }
1352 res->data=cf;
1353 res->rtyp=CRING_CMD;
1354 return FALSE;
1355
1357 WerrorS("expected `crossprod(coeffs, ...)`");
1358 return TRUE;
1359}
1360/*2
1361* initialize components of Singular
1362*/
1363static void callWerrorS(const char *s) { WerrorS(s); }
1364void siInit(char *name)
1365{
1366// memory initialization: -----------------------------------------------
1367 om_Opts.OutOfMemoryFunc = omSingOutOfMemoryFunc;
1368#ifndef OM_NDEBUG
1369#ifndef __OPTIMIZE__
1370 #ifndef MAKE_DISTRUBTION
1371 om_Opts.ErrorHook = dErrorBreak;
1372 #endif
1373#else
1374 om_Opts.Keep = 0; /* !OM_NDEBUG, __OPTIMIZE__*/
1375#endif
1376#else
1377 om_Opts.Keep = 0; /* OM_NDEBUG */
1378#endif
1379 omInitInfo();
1380// factory
1381#ifndef HAVE_NTL
1382 extern void initPT();
1383 initPT();
1384#endif
1385 { // set cpus (in siInit), if SINGULAR_CPUS is set, set within the limits
1386 char *env_cpu=getenv("SINGULAR_CPUS");
1387 if (env_cpu!=NULL)
1388 {
1389 int cpu_n,cpus;
1390 #ifdef _SC_NPROCESSORS_ONLN
1392 #elif defined(_SC_NPROCESSORS_CONF)
1394 #endif
1395 #ifdef HAVE_SIMPLEIPC
1397 #endif
1398
1399 int t=atoi(env_cpu);
1400 if ((t>=0)&&(t<cpus)) cpus=t;
1402 // how many threads ? -----------------------------------------------------
1404 }
1405 }
1406// options ---------------------------------------------------------------
1407 si_opt_1=0;
1408// interpreter tables etc.: -----------------------------------------------
1409 memset(&sLastPrinted,0,sizeof(sleftv));
1411
1412 extern int iiInitArithmetic(); iiInitArithmetic(); // iparith.cc
1413
1414 basePack=(package)omAlloc0(sizeof(*basePack));
1416 idhdl h;
1417 h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, FALSE);
1419 IDPACKAGE(h)->language = LANG_TOP;
1420 currPackHdl=h;
1421 basePackHdl=h;
1422
1423 coeffs_BIGINT = nInitChar(n_Q,(void*)1);
1424
1425#if 1
1426 // def HAVE_POLYEXTENSIONS
1427 if(TRUE)
1428 {
1429 n_coeffType type;
1430 #ifdef SINGULAR_4_2
1432 assume(type == n_polyExt);
1433 #endif
1434
1435 type = nRegister(n_algExt, naInitChar);
1436 assume(type == n_algExt);
1437
1439 assume(type == n_transExt);
1440
1441 (void)type;
1442 }
1443#endif
1444
1445// random generator: -----------------------------------------------
1446 {
1447 int t=startTimer();
1448 if (t==0) t=1;
1449 initRTimer();
1450 siSeed=t;
1451 factoryseed(t);
1452 siRandomStart=t;
1453 feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart);
1454 }
1455
1456// ressource table: ----------------------------------------------------
1457 // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
1458 // hack such that all shared' libs in the bindir are loaded correctly
1460
1461// singular links: --------------------------------------------------
1463 myynest=0;
1464
1465// default coeffs
1466 {
1467 idhdl h;
1468 h=enterid("QQ",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1469 IDDATA(h)=(char*)nInitChar(n_Q,NULL);
1470 h=enterid("ZZ",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1471 IDDATA(h)=(char*)nInitChar(n_Z,NULL);
1473 iiAddCproc("kernel","crossprod",FALSE,iiCrossProd);
1474 iiAddCproc("kernel","Float",FALSE,iiFloat);
1475 //h=enterid("RR",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1476 //IDDATA(h)=(char*)nInitChar(n_R,NULL);
1477 //h=enterid("CC",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1478 //IDDATA(h)=(char*)nInitChar(n_long_C,NULL);
1479 }
1480// setting routines for PLURAL QRINGS:
1481// allowing to use libpolys without libSingular(kStd)
1482#ifdef HAVE_PLURAL
1483 nc_NF=k_NF;
1489#endif
1490// loading standard.lib -----------------------------------------------
1492 {
1495 si_opt_2 &= ~Sy_bit(V_LOAD_LIB);
1496 iiLibCmd("standard.lib", TRUE,TRUE,TRUE);
1498 }
1499 // interpreter error handling
1500 #ifndef __CYGWIN__
1501 factoryError=callWerrorS; // to honour later changes of variable WerrorS
1502 #endif
1503 errorreported = 0;
1504}
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition algext.cc:1386
BOOLEAN n2pInitChar(coeffs cf, void *infoStruct)
Definition algext.cc:1640
#define BITSET
Definition auxiliary.h:85
int BOOLEAN
Definition auxiliary.h:88
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
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
char name() const
Definition variable.cc:122
Variable next() const
Definition factory.h:146
Definition idrec.h:35
Class used for (list of) interpreter objects.
Definition subexpr.h:83
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
Definition lists.h:24
sleftv * m
Definition lists.h:46
INLINE_THIS void Init(int l=0)
VAR BOOLEAN singular_in_batchmode
Definition cntrlc.cc: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:990
static FORCE_INLINE number mpz2number(mpz_t m, coeffs c)
Definition coeffs.h:991
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
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
#define Print
Definition emacs.cc:80
#define WarnS
Definition emacs.cc:78
#define StringAppend
Definition emacs.cc:79
const CanonicalForm int s
Definition facAbsFact.cc:51
const CanonicalForm int const CFList const Variable & y
Definition facAbsFact.cc:53
CanonicalForm res
Definition facAbsFact.cc:60
const CanonicalForm & w
Definition facAbsFact.cc:51
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
int j
Definition facHensel.cc:110
char name(const Variable &v)
Definition factory.h:189
#define VERSION
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:9965
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition ipid.cc:279
VAR package basePack
Definition ipid.cc:56
VAR package currPack
Definition ipid.cc:55
void killhdl(idhdl h, package proot)
Definition ipid.cc:414
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
#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
#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:885
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:3447
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:1084
#define SI_SHOW_BUILTIN_MODULE(name)
const struct soptionStruct verboseStruct[]
Definition misc_ip.cc:539
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:1329
void siInit(char *name)
Definition misc_ip.cc:1364
char * versionString()
Definition misc_ip.cc:769
static BOOLEAN ii_FlintQ_init(leftv res, leftv a)
Definition misc_ip.cc:1230
const char * singular_date
Definition misc_ip.cc:766
int flint_mod_init(SModulFunctions *psModulFunctions)
Definition misc_ip.cc:1275
STATIC_VAR n_coeffType n_FlintQ
Definition misc_ip.cc:1214
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:1202
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:1300
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:1216
const struct soptionStruct optionStruct[]
Definition misc_ip.cc:508
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:1213
char * showOption()
Definition misc_ip.cc:711
static void callWerrorS(const char *s)
Definition misc_ip.cc:1363
volatile BOOLEAN m2_end_called
Definition misc_ip.cc:1097
STATIC_VAR unsigned add[]
Definition misc_ip.cc:108
void m2_end(int i)
Definition misc_ip.cc:1104
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:554
#define rField_is_Ring(R)
Definition ring.h:491
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
#define loop
Definition structs.h:71
INST_VAR sleftv sLastPrinted
Definition subexpr.cc:46
@ LANG_TOP
Definition subexpr.h:22
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