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 |
---|
9 | * misc_ip.h. |
---|
10 | * |
---|
11 | * @author Frank Seelisch |
---|
12 | * |
---|
13 | * @internal @version \$Id$ |
---|
14 | * |
---|
15 | **/ |
---|
16 | /*****************************************************************************/ |
---|
17 | |
---|
18 | // include header files |
---|
19 | #include "mod2.h" |
---|
20 | #include "lists.h" |
---|
21 | #include "longrat.h" /* We only need bigints. */ |
---|
22 | #include "misc_ip.h" |
---|
23 | |
---|
24 | /* This works by Newton iteration, i.e., |
---|
25 | a(1) = n; |
---|
26 | a(i+1) = a(i)/2 + n/2/a(i), i > 0. |
---|
27 | This sequence is guaranteed to decrease monotonously and |
---|
28 | it is known to converge fast. |
---|
29 | All used numbers are bigints. */ |
---|
30 | number approximateSqrt(const number n) |
---|
31 | { |
---|
32 | if (nlIsZero(n)) { number zero = nlInit(0, NULL); return zero; } |
---|
33 | number temp1; number temp2; |
---|
34 | number one = nlInit(1, NULL); |
---|
35 | number two = nlInit(2, NULL); |
---|
36 | number m = nlCopy(n); |
---|
37 | number mOld = nlSub(m, one); /* initially required to be different from m */ |
---|
38 | number nHalf = nlIntDiv(n, two); |
---|
39 | bool check = true; |
---|
40 | while (!nlEqual(m, mOld) && check) |
---|
41 | { |
---|
42 | temp1 = nlIntDiv(m, two); |
---|
43 | temp2 = nlIntDiv(nHalf, m); |
---|
44 | mOld = m; |
---|
45 | m = nlAdd(temp1, temp2); |
---|
46 | nlDelete(&temp1, NULL); nlDelete(&temp2, NULL); |
---|
47 | temp1 = nlMult(m, m); |
---|
48 | check = nlGreater(temp1, n); |
---|
49 | nlDelete(&temp1, NULL); |
---|
50 | } |
---|
51 | nlDelete(&mOld, NULL); nlDelete(&two, NULL); nlDelete(&nHalf, NULL); |
---|
52 | while (!check) |
---|
53 | { |
---|
54 | temp1 = nlAdd(m, one); |
---|
55 | nlDelete(&m, NULL); |
---|
56 | m = temp1; |
---|
57 | temp1 = nlMult(m, m); |
---|
58 | check = nlGreater(temp1, n); |
---|
59 | nlDelete(&temp1, NULL); |
---|
60 | } |
---|
61 | temp1 = nlSub(m, one); |
---|
62 | nlDelete(&m, NULL); |
---|
63 | nlDelete(&one, NULL); |
---|
64 | m = temp1; |
---|
65 | return m; |
---|
66 | } |
---|
67 | |
---|
68 | /* returns the quotient resulting from division of n by the prime as many |
---|
69 | times as possible without remainder; afterwards, the parameter times |
---|
70 | will contain the highest exponent e of p such that p^e divides n |
---|
71 | e.g., divTimes(48, 4, t) = 3 with t = 2, since 48 = 4*4*3; |
---|
72 | n is expected to be a bigint; returned type is also bigint */ |
---|
73 | number divTimes(const number n, const int p, int* times) |
---|
74 | { |
---|
75 | number nn = nlCopy(n); |
---|
76 | number dd = nlInit(p, NULL); |
---|
77 | number rr = nlIntMod(nn, dd); |
---|
78 | *times = 0; |
---|
79 | while (nlIsZero(rr)) |
---|
80 | { |
---|
81 | (*times)++; |
---|
82 | number temp = nlIntDiv(nn, dd); |
---|
83 | nlDelete(&nn, NULL); |
---|
84 | nn = temp; |
---|
85 | nlDelete(&rr, NULL); |
---|
86 | rr = nlIntMod(nn, dd); |
---|
87 | } |
---|
88 | nlDelete(&rr, NULL); nlDelete(&dd, NULL); |
---|
89 | return nn; |
---|
90 | } |
---|
91 | |
---|
92 | /* returns an object of type lists which contains the entries |
---|
93 | theInts[0..(length-1)] as INT_CMDs*/ |
---|
94 | lists makeListsObject(const int* theInts, int length) |
---|
95 | { |
---|
96 | lists L=(lists)omAllocBin(slists_bin); |
---|
97 | L->Init(length); |
---|
98 | for (int i = 0; i < length; i++) |
---|
99 | { L->m[i].rtyp = INT_CMD; L->m[i].data = (void*)theInts[i]; } |
---|
100 | return L; |
---|
101 | } |
---|
102 | |
---|
103 | /* returns the i-th bit of the binary number which arises by |
---|
104 | concatenating array[length-1], ..., array[1], array[0], |
---|
105 | where array[0] contains the 32 lowest bits etc.; |
---|
106 | i is assumed to be small enough to address a valid index |
---|
107 | in the given array */ |
---|
108 | bool getValue(const unsigned i, const unsigned int* ii) |
---|
109 | { |
---|
110 | if (i==2) return true; |
---|
111 | if ((i & 1)==0) return false; |
---|
112 | unsigned I= i/2; |
---|
113 | unsigned index = I / 32; |
---|
114 | unsigned offset = I % 32; |
---|
115 | unsigned int v = 1 << offset; |
---|
116 | return ((ii[index] & v) != 0); |
---|
117 | } |
---|
118 | |
---|
119 | /* sets the i-th bit of the binary number which arises by |
---|
120 | concatenating array[length-1], ..., array[1], array[0], |
---|
121 | where array[0] contains the 32 lowest bits etc.; |
---|
122 | i is assumed to be small enough to address a valid index |
---|
123 | in the given array */ |
---|
124 | void setValue(const unsigned i, bool value, unsigned int* ii) |
---|
125 | { |
---|
126 | if ((i&1)==0) return; // ignore odd numbers |
---|
127 | unsigned I=i/2; |
---|
128 | unsigned index = I / 32; |
---|
129 | unsigned offset = I % 32; |
---|
130 | unsigned int v = 1 << offset; |
---|
131 | if (value) { ii[index] |= v; } |
---|
132 | else { ii[index] &= ~v; } |
---|
133 | } |
---|
134 | |
---|
135 | /* returns whether i is less than or equal to the bigint number n */ |
---|
136 | bool isLeq(const int i, const number n) |
---|
137 | { |
---|
138 | number iN = nlInit(i - 1, NULL); |
---|
139 | bool result = nlGreater(n, iN); |
---|
140 | nlDelete(&iN, NULL); |
---|
141 | return result; |
---|
142 | } |
---|
143 | |
---|
144 | lists primeFactorisation(const number n, const int pBound) |
---|
145 | { |
---|
146 | number nn = nlCopy(n); int i; |
---|
147 | int pCounter = 0; /* for counting the number of mutually distinct |
---|
148 | prime factors in n */ |
---|
149 | /* we assume that there are at most 1000 mutually distinct prime |
---|
150 | factors in n */ |
---|
151 | int* primes = new int[1000]; int* multiplicities = new int[1000]; |
---|
152 | |
---|
153 | /* extra treatment for the primes 2 and 3; |
---|
154 | all other primes are equal to +1/-1 mod 6 */ |
---|
155 | int e; number temp; |
---|
156 | temp = divTimes(nn, 2, &e); nlDelete(&nn, NULL); nn = temp; |
---|
157 | if (e > 0) { primes[pCounter] = 2; multiplicities[pCounter++] = e; } |
---|
158 | temp = divTimes(nn, 3, &e); nlDelete(&nn, NULL); nn = temp; |
---|
159 | if (e > 0) { primes[pCounter] = 3; multiplicities[pCounter++] = e; } |
---|
160 | |
---|
161 | /* now we simultaneously: |
---|
162 | - build the sieve of Erathostenes up to s, |
---|
163 | - divide out each prime factor of nn that we find along the way |
---|
164 | (This may result in an earlier termination.) */ |
---|
165 | |
---|
166 | int s = 1<<25; /* = 2^25 */ |
---|
167 | int maxP = 2147483647; /* = 2^31 - 1, by the way a Mersenne prime */ |
---|
168 | if ((pBound != 0) && (pBound < maxP)) |
---|
169 | { |
---|
170 | maxP = pBound; |
---|
171 | } |
---|
172 | if (maxP< (2147483647-63) ) s=(maxP+63)/64; |
---|
173 | else s=2147483647/64+1; |
---|
174 | unsigned int* isPrime = new unsigned int[s]; |
---|
175 | /* the lowest bit of isPrime[0] stores whether 1 is a prime, |
---|
176 | next bit is for 3, next for 5, etc. i.e. |
---|
177 | intended usage is: isPrime[0] = ... |
---|
178 | We shall make use only of bits which correspond to numbers = |
---|
179 | -1 or +1 mod 6. */ |
---|
180 | for (i = 0; i < s; i++) isPrime[i] = ~0;/*4294967295*/; /* all 32 bits set */ |
---|
181 | int p=9; while((p<maxP) && (p>0)) { setValue(p,false,isPrime); p+=6; } |
---|
182 | p = 5; bool add2 = true; |
---|
183 | /* due to possible overflows, we need to check whether p > 0, and |
---|
184 | likewise i > 0 below */ |
---|
185 | while ((0 < p) && (p <= maxP) && (isLeq(p, nn))) |
---|
186 | { |
---|
187 | /* at this point, p is guaranteed to be a prime; |
---|
188 | we divide nn by the highest power of p and store p |
---|
189 | if nn is at all divisible by p */ |
---|
190 | temp = divTimes(nn, p, &e); |
---|
191 | nlDelete(&nn, NULL); nn = temp; |
---|
192 | if (e > 0) |
---|
193 | { primes[pCounter] = p; multiplicities[pCounter++] = e; } |
---|
194 | /* invalidate all multiples of p, starting with 2*p */ |
---|
195 | i = 2 * p; |
---|
196 | while ((0 < i) && (i < maxP)) { setValue(i, false, isPrime); i += p; } |
---|
197 | /* move on to the next prime in the sieve; we either add 2 or 4 |
---|
198 | in order to visit just the numbers equal to -1/+1 mod 6 */ |
---|
199 | if (add2) { p += 2; add2 = false; } |
---|
200 | else { p += 4; add2 = true; } |
---|
201 | while ((0 < p) && (p <= maxP) && (isLeq(p, nn)) && (!getValue(p, isPrime))) |
---|
202 | { |
---|
203 | if (add2) { p += 2; add2 = false; } |
---|
204 | else { p += 4; add2 = true; } |
---|
205 | } |
---|
206 | } |
---|
207 | |
---|
208 | /* build return structure and clean up */ |
---|
209 | delete [] isPrime; |
---|
210 | lists primesL = makeListsObject(primes, pCounter); |
---|
211 | lists multiplicitiesL = makeListsObject(multiplicities, pCounter); |
---|
212 | delete [] primes; delete [] multiplicities; |
---|
213 | lists L=(lists)omAllocBin(slists_bin); |
---|
214 | L->Init(3); |
---|
215 | L->m[0].rtyp = BIGINT_CMD; L->m[0].data = (void *)nn; |
---|
216 | /* try to fit nn into an int: */ |
---|
217 | int nnAsInt = nlInt(nn, NULL); |
---|
218 | if (nlIsZero(nn) || (nnAsInt != 0)) |
---|
219 | { L->m[0].rtyp = INT_CMD; L->m[0].data = (void *)nnAsInt; } |
---|
220 | L->m[1].rtyp = LIST_CMD; L->m[1].data = (void *)primesL; |
---|
221 | L->m[2].rtyp = LIST_CMD; L->m[2].data = (void *)multiplicitiesL; |
---|
222 | return L; |
---|
223 | } |
---|
224 | |
---|
225 | #include <string.h> |
---|
226 | #include <unistd.h> |
---|
227 | #include <stdio.h> |
---|
228 | #include <stddef.h> |
---|
229 | #include <stdlib.h> |
---|
230 | #include <time.h> |
---|
231 | |
---|
232 | #include <mylimits.h> |
---|
233 | #include "omalloc.h" |
---|
234 | #include "options.h" |
---|
235 | #include "febase.h" |
---|
236 | #include "cntrlc.h" |
---|
237 | #include "page.h" |
---|
238 | #include "ipid.h" |
---|
239 | #include "ipshell.h" |
---|
240 | #include "kstd1.h" |
---|
241 | #include "subexpr.h" |
---|
242 | #include "timer.h" |
---|
243 | #include "intvec.h" |
---|
244 | #include "ring.h" |
---|
245 | #include "omSingularConfig.h" |
---|
246 | #include "p_Procs.h" |
---|
247 | /* Needed for debug Version of p_SetRingOfLeftv, Oliver */ |
---|
248 | #ifdef PDEBUG |
---|
249 | #include "p_polys.h" |
---|
250 | #endif |
---|
251 | #include "version.h" |
---|
252 | |
---|
253 | #include "static.h" |
---|
254 | #ifdef HAVE_STATIC |
---|
255 | #undef HAVE_DYN_RL |
---|
256 | #endif |
---|
257 | |
---|
258 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
259 | |
---|
260 | //#ifdef HAVE_LIBPARSER |
---|
261 | //# include "libparse.h" |
---|
262 | //#endif /* HAVE_LIBPARSER */ |
---|
263 | |
---|
264 | #ifdef HAVE_FACTORY |
---|
265 | #include <factory.h> |
---|
266 | // libfac: |
---|
267 | extern const char * libfac_version; |
---|
268 | extern const char * libfac_date; |
---|
269 | #endif |
---|
270 | |
---|
271 | /* version strings */ |
---|
272 | #include <si_gmp.h> |
---|
273 | #ifdef HAVE_MPSR |
---|
274 | #include <MP_Config.h> |
---|
275 | #endif |
---|
276 | |
---|
277 | /*2 |
---|
278 | * initialize components of Singular |
---|
279 | */ |
---|
280 | int inits(void) |
---|
281 | { |
---|
282 | int t; |
---|
283 | /*4 signal handler:*/ |
---|
284 | init_signals(); |
---|
285 | /*4 randomize: */ |
---|
286 | t=initTimer(); |
---|
287 | /*t=(int)time(NULL);*/ |
---|
288 | if (t==0) t=1; |
---|
289 | #ifdef HAVE_RTIMER |
---|
290 | initRTimer(); |
---|
291 | #endif |
---|
292 | #ifdef buildin_rand |
---|
293 | siSeed=t; |
---|
294 | #else |
---|
295 | srand((unsigned int)t); |
---|
296 | #endif |
---|
297 | #ifdef HAVE_FACTORY |
---|
298 | factoryseed(t); |
---|
299 | #endif |
---|
300 | /*4 private data of other modules*/ |
---|
301 | memset(&sLastPrinted,0,sizeof(sleftv)); |
---|
302 | sLastPrinted.rtyp=NONE; |
---|
303 | return t; |
---|
304 | } |
---|
305 | |
---|
306 | /*2 |
---|
307 | * the renice routine for very large jobs |
---|
308 | * works only on unix machines, |
---|
309 | * testet on : linux, HP 9.0 |
---|
310 | * |
---|
311 | *#include <sys/times.h> |
---|
312 | *#include <sys/resource.h> |
---|
313 | *extern "C" int setpriority(int,int,int); |
---|
314 | *void very_nice() |
---|
315 | *{ |
---|
316 | *#ifndef NO_SETPRIORITY |
---|
317 | * setpriority(PRIO_PROCESS,0,19); |
---|
318 | *#endif |
---|
319 | * sleep(10); |
---|
320 | *} |
---|
321 | */ |
---|
322 | |
---|
323 | void singular_example(char *str) |
---|
324 | { |
---|
325 | assume(str!=NULL); |
---|
326 | char *s=str; |
---|
327 | while (*s==' ') s++; |
---|
328 | char *ss=s; |
---|
329 | while (*ss!='\0') ss++; |
---|
330 | while (*ss<=' ') |
---|
331 | { |
---|
332 | *ss='\0'; |
---|
333 | ss--; |
---|
334 | } |
---|
335 | idhdl h=IDROOT->get(s,myynest); |
---|
336 | if ((h!=NULL) && (IDTYP(h)==PROC_CMD)) |
---|
337 | { |
---|
338 | char *lib=iiGetLibName(IDPROC(h)); |
---|
339 | if((lib!=NULL)&&(*lib!='\0')) |
---|
340 | { |
---|
341 | Print("// proc %s from lib %s\n",s,lib); |
---|
342 | s=iiGetLibProcBuffer(IDPROC(h), 2); |
---|
343 | if (s!=NULL) |
---|
344 | { |
---|
345 | if (strlen(s)>5) |
---|
346 | { |
---|
347 | iiEStart(s,IDPROC(h)); |
---|
348 | return; |
---|
349 | } |
---|
350 | else omFree((ADDRESS)s); |
---|
351 | } |
---|
352 | } |
---|
353 | } |
---|
354 | else |
---|
355 | { |
---|
356 | char sing_file[MAXPATHLEN]; |
---|
357 | FILE *fd=NULL; |
---|
358 | char *res_m=feResource('m', 0); |
---|
359 | if (res_m!=NULL) |
---|
360 | { |
---|
361 | sprintf(sing_file, "%s/%s.sing", res_m, s); |
---|
362 | fd = feFopen(sing_file, "r"); |
---|
363 | } |
---|
364 | if (fd != NULL) |
---|
365 | { |
---|
366 | |
---|
367 | int old_echo = si_echo; |
---|
368 | int length, got; |
---|
369 | char* s; |
---|
370 | |
---|
371 | fseek(fd, 0, SEEK_END); |
---|
372 | length = ftell(fd); |
---|
373 | fseek(fd, 0, SEEK_SET); |
---|
374 | s = (char*) omAlloc((length+20)*sizeof(char)); |
---|
375 | got = fread(s, sizeof(char), length, fd); |
---|
376 | fclose(fd); |
---|
377 | if (got != length) |
---|
378 | { |
---|
379 | Werror("Error while reading file %s", sing_file); |
---|
380 | omFree(s); |
---|
381 | } |
---|
382 | else |
---|
383 | { |
---|
384 | s[length] = '\0'; |
---|
385 | strcat(s, "\n;return();\n\n"); |
---|
386 | si_echo = 2; |
---|
387 | iiEStart(s, NULL); |
---|
388 | si_echo = old_echo; |
---|
389 | } |
---|
390 | } |
---|
391 | else |
---|
392 | { |
---|
393 | Werror("no example for %s", str); |
---|
394 | } |
---|
395 | } |
---|
396 | } |
---|
397 | |
---|
398 | |
---|
399 | struct soptionStruct |
---|
400 | { |
---|
401 | const char * name; |
---|
402 | unsigned setval; |
---|
403 | unsigned resetval; |
---|
404 | }; |
---|
405 | |
---|
406 | struct soptionStruct optionStruct[]= |
---|
407 | { |
---|
408 | {"prot", Sy_bit(OPT_PROT), ~Sy_bit(OPT_PROT) }, |
---|
409 | {"redSB", Sy_bit(OPT_REDSB), ~Sy_bit(OPT_REDSB) }, |
---|
410 | {"notBuckets", Sy_bit(OPT_NOT_BUCKETS), ~Sy_bit(OPT_NOT_BUCKETS) }, |
---|
411 | {"notSugar", Sy_bit(OPT_NOT_SUGAR), ~Sy_bit(OPT_NOT_SUGAR) }, |
---|
412 | {"interrupt", Sy_bit(OPT_INTERRUPT), ~Sy_bit(OPT_INTERRUPT) }, |
---|
413 | {"sugarCrit", Sy_bit(OPT_SUGARCRIT), ~Sy_bit(OPT_SUGARCRIT) }, |
---|
414 | {"teach", Sy_bit(OPT_DEBUG), ~Sy_bit(OPT_DEBUG) }, |
---|
415 | /* 9 return SB in syz, quotient, intersect */ |
---|
416 | {"returnSB", Sy_bit(OPT_RETURN_SB), ~Sy_bit(OPT_RETURN_SB) }, |
---|
417 | {"fastHC", Sy_bit(OPT_FASTHC), ~Sy_bit(OPT_FASTHC) }, |
---|
418 | /* 11-19 sort in L/T */ |
---|
419 | {"staircaseBound",Sy_bit(OPT_STAIRCASEBOUND),~Sy_bit(OPT_STAIRCASEBOUND) }, |
---|
420 | {"multBound", Sy_bit(OPT_MULTBOUND), ~Sy_bit(OPT_MULTBOUND) }, |
---|
421 | {"degBound", Sy_bit(OPT_DEGBOUND), ~Sy_bit(OPT_DEGBOUND) }, |
---|
422 | /* 25 no redTail(p)/redTail(s) */ |
---|
423 | {"redTail", Sy_bit(OPT_REDTAIL), ~Sy_bit(OPT_REDTAIL) }, |
---|
424 | {"redThrough", Sy_bit(OPT_REDTHROUGH), ~Sy_bit(OPT_REDTHROUGH) }, |
---|
425 | {"lazy", Sy_bit(OPT_OLDSTD), ~Sy_bit(OPT_OLDSTD) }, |
---|
426 | {"intStrategy", Sy_bit(OPT_INTSTRATEGY), ~Sy_bit(OPT_INTSTRATEGY) }, |
---|
427 | {"infRedTail", Sy_bit(OPT_INFREDTAIL), ~Sy_bit(OPT_INFREDTAIL) }, |
---|
428 | /* 30: use not regularity for syz */ |
---|
429 | {"notRegularity",Sy_bit(OPT_NOTREGULARITY), ~Sy_bit(OPT_NOTREGULARITY) }, |
---|
430 | {"weightM", Sy_bit(OPT_WEIGHTM), ~Sy_bit(OPT_WEIGHTM) }, |
---|
431 | /*special for "none" and also end marker for showOption:*/ |
---|
432 | {"ne", 0, 0 } |
---|
433 | }; |
---|
434 | |
---|
435 | struct soptionStruct verboseStruct[]= |
---|
436 | { |
---|
437 | {"mem", Sy_bit(V_SHOW_MEM), ~Sy_bit(V_SHOW_MEM) }, |
---|
438 | {"yacc", Sy_bit(V_YACC), ~Sy_bit(V_YACC) }, |
---|
439 | {"redefine", Sy_bit(V_REDEFINE), ~Sy_bit(V_REDEFINE) }, |
---|
440 | {"reading", Sy_bit(V_READING), ~Sy_bit(V_READING) }, |
---|
441 | {"loadLib", Sy_bit(V_LOAD_LIB), ~Sy_bit(V_LOAD_LIB) }, |
---|
442 | {"debugLib", Sy_bit(V_DEBUG_LIB), ~Sy_bit(V_DEBUG_LIB) }, |
---|
443 | {"loadProc", Sy_bit(V_LOAD_PROC), ~Sy_bit(V_LOAD_PROC) }, |
---|
444 | {"defRes", Sy_bit(V_DEF_RES), ~Sy_bit(V_DEF_RES) }, |
---|
445 | {"usage", Sy_bit(V_SHOW_USE), ~Sy_bit(V_SHOW_USE) }, |
---|
446 | {"Imap", Sy_bit(V_IMAP), ~Sy_bit(V_IMAP) }, |
---|
447 | {"prompt", Sy_bit(V_PROMPT), ~Sy_bit(V_PROMPT) }, |
---|
448 | {"length", Sy_bit(V_LENGTH), ~Sy_bit(V_LENGTH) }, |
---|
449 | {"notWarnSB",Sy_bit(V_NSB), ~Sy_bit(V_NSB) }, |
---|
450 | {"contentSB",Sy_bit(V_CONTENTSB), ~Sy_bit(V_CONTENTSB) }, |
---|
451 | {"cancelunit",Sy_bit(V_CANCELUNIT),~Sy_bit(V_CANCELUNIT)}, |
---|
452 | {"modpsolve",Sy_bit(V_MODPSOLVSB),~Sy_bit(V_MODPSOLVSB)}, |
---|
453 | {"geometricSB",Sy_bit(V_UPTORADICAL),~Sy_bit(V_UPTORADICAL)}, |
---|
454 | {"findMonomials",Sy_bit(V_FINDMONOM),~Sy_bit(V_FINDMONOM)}, |
---|
455 | {"coefStrat",Sy_bit(V_COEFSTRAT), ~Sy_bit(V_COEFSTRAT)}, |
---|
456 | {"qringNF", Sy_bit(V_QRING), ~Sy_bit(V_QRING)}, |
---|
457 | /*special for "none" and also end marker for showOption:*/ |
---|
458 | {"ne", 0, 0 } |
---|
459 | }; |
---|
460 | |
---|
461 | BOOLEAN setOption(leftv res, leftv v) |
---|
462 | { |
---|
463 | const char *n; |
---|
464 | do |
---|
465 | { |
---|
466 | if (v->Typ()==STRING_CMD) |
---|
467 | { |
---|
468 | n=(const char *)v->CopyD(STRING_CMD); |
---|
469 | } |
---|
470 | else |
---|
471 | { |
---|
472 | if (v->name==NULL) |
---|
473 | return TRUE; |
---|
474 | if (v->rtyp==0) |
---|
475 | { |
---|
476 | n=v->name; |
---|
477 | v->name=NULL; |
---|
478 | } |
---|
479 | else |
---|
480 | { |
---|
481 | n=omStrDup(v->name); |
---|
482 | } |
---|
483 | } |
---|
484 | |
---|
485 | int i; |
---|
486 | |
---|
487 | if(strcmp(n,"get")==0) |
---|
488 | { |
---|
489 | intvec *w=new intvec(2); |
---|
490 | (*w)[0]=test; |
---|
491 | (*w)[1]=verbose; |
---|
492 | res->rtyp=INTVEC_CMD; |
---|
493 | res->data=(void *)w; |
---|
494 | goto okay; |
---|
495 | } |
---|
496 | if(strcmp(n,"set")==0) |
---|
497 | { |
---|
498 | if((v->next!=NULL) |
---|
499 | &&(v->next->Typ()==INTVEC_CMD)) |
---|
500 | { |
---|
501 | v=v->next; |
---|
502 | intvec *w=(intvec*)v->Data(); |
---|
503 | test=(*w)[0]; |
---|
504 | verbose=(*w)[1]; |
---|
505 | #if 0 |
---|
506 | if (TEST_OPT_INTSTRATEGY && (currRing!=NULL) |
---|
507 | && rField_has_simple_inverse() |
---|
508 | #ifdef HAVE_RINGS |
---|
509 | && !rField_is_Ring(currRing) |
---|
510 | #endif |
---|
511 | ) { |
---|
512 | test &=~Sy_bit(OPT_INTSTRATEGY); |
---|
513 | } |
---|
514 | #endif |
---|
515 | goto okay; |
---|
516 | } |
---|
517 | } |
---|
518 | if(strcmp(n,"none")==0) |
---|
519 | { |
---|
520 | test=0; |
---|
521 | verbose=0; |
---|
522 | goto okay; |
---|
523 | } |
---|
524 | for (i=0; (i==0) || (optionStruct[i-1].setval!=0); i++) |
---|
525 | { |
---|
526 | if (strcmp(n,optionStruct[i].name)==0) |
---|
527 | { |
---|
528 | if (optionStruct[i].setval & validOpts) |
---|
529 | { |
---|
530 | test |= optionStruct[i].setval; |
---|
531 | // optOldStd disables redthrough |
---|
532 | if (optionStruct[i].setval == Sy_bit(OPT_OLDSTD)) |
---|
533 | test &= ~Sy_bit(OPT_REDTHROUGH); |
---|
534 | } |
---|
535 | else |
---|
536 | Warn("cannot set option"); |
---|
537 | #if 0 |
---|
538 | if (TEST_OPT_INTSTRATEGY && (currRing!=NULL) |
---|
539 | && rField_has_simple_inverse() |
---|
540 | #ifdef HAVE_RINGS |
---|
541 | && !rField_is_Ring(currRing) |
---|
542 | #endif |
---|
543 | ) { |
---|
544 | test &=~Sy_bit(OPT_INTSTRATEGY); |
---|
545 | } |
---|
546 | #endif |
---|
547 | goto okay; |
---|
548 | } |
---|
549 | else if ((strncmp(n,"no",2)==0) |
---|
550 | && (strcmp(n+2,optionStruct[i].name)==0)) |
---|
551 | { |
---|
552 | if (optionStruct[i].setval & validOpts) |
---|
553 | { |
---|
554 | test &= optionStruct[i].resetval; |
---|
555 | } |
---|
556 | else |
---|
557 | Warn("cannot clear option"); |
---|
558 | goto okay; |
---|
559 | } |
---|
560 | } |
---|
561 | for (i=0; (i==0) || (verboseStruct[i-1].setval!=0); i++) |
---|
562 | { |
---|
563 | if (strcmp(n,verboseStruct[i].name)==0) |
---|
564 | { |
---|
565 | verbose |= verboseStruct[i].setval; |
---|
566 | #ifdef YYDEBUG |
---|
567 | #if YYDEBUG |
---|
568 | /*debugging the bison grammar --> grammar.cc*/ |
---|
569 | extern int yydebug; |
---|
570 | if (BVERBOSE(V_YACC)) yydebug=1; |
---|
571 | else yydebug=0; |
---|
572 | #endif |
---|
573 | #endif |
---|
574 | goto okay; |
---|
575 | } |
---|
576 | else if ((strncmp(n,"no",2)==0) |
---|
577 | && (strcmp(n+2,verboseStruct[i].name)==0)) |
---|
578 | { |
---|
579 | verbose &= verboseStruct[i].resetval; |
---|
580 | #ifdef YYDEBUG |
---|
581 | #if YYDEBUG |
---|
582 | /*debugging the bison grammar --> grammar.cc*/ |
---|
583 | extern int yydebug; |
---|
584 | if (BVERBOSE(V_YACC)) yydebug=1; |
---|
585 | else yydebug=0; |
---|
586 | #endif |
---|
587 | #endif |
---|
588 | goto okay; |
---|
589 | } |
---|
590 | } |
---|
591 | Werror("unknown option `%s`",n); |
---|
592 | okay: |
---|
593 | if (currRing != NULL) |
---|
594 | currRing->options = test & TEST_RINGDEP_OPTS; |
---|
595 | omFree((ADDRESS)n); |
---|
596 | v=v->next; |
---|
597 | } while (v!=NULL); |
---|
598 | #ifdef HAVE_TCL |
---|
599 | if (tclmode) |
---|
600 | { |
---|
601 | BITSET tmp; |
---|
602 | int i; |
---|
603 | StringSetS(""); |
---|
604 | if ((test!=0)||(verbose!=0)) |
---|
605 | { |
---|
606 | tmp=test; |
---|
607 | if(tmp) |
---|
608 | { |
---|
609 | for (i=0; optionStruct[i].setval!=0; i++) |
---|
610 | { |
---|
611 | if (optionStruct[i].setval & test) |
---|
612 | { |
---|
613 | StringAppend(" %s",optionStruct[i].name); |
---|
614 | tmp &=optionStruct[i].resetval; |
---|
615 | } |
---|
616 | } |
---|
617 | } |
---|
618 | tmp=verbose; |
---|
619 | if (tmp) |
---|
620 | { |
---|
621 | for (i=0; verboseStruct[i].setval!=0; i++) |
---|
622 | { |
---|
623 | if (verboseStruct[i].setval & tmp) |
---|
624 | { |
---|
625 | StringAppend(" %s",verboseStruct[i].name); |
---|
626 | tmp &=verboseStruct[i].resetval; |
---|
627 | } |
---|
628 | } |
---|
629 | } |
---|
630 | PrintTCLS('O',StringAppendS("")); |
---|
631 | StringSetS(""); |
---|
632 | } |
---|
633 | else |
---|
634 | { |
---|
635 | PrintTCLS('O'," "); |
---|
636 | } |
---|
637 | } |
---|
638 | #endif |
---|
639 | // set global variable to show memory usage |
---|
640 | if (BVERBOSE(V_SHOW_MEM)) om_sing_opt_show_mem = 1; |
---|
641 | else om_sing_opt_show_mem = 0; |
---|
642 | return FALSE; |
---|
643 | } |
---|
644 | |
---|
645 | char * showOption() |
---|
646 | { |
---|
647 | int i; |
---|
648 | BITSET tmp; |
---|
649 | |
---|
650 | StringSetS("//options:"); |
---|
651 | if ((test!=0)||(verbose!=0)) |
---|
652 | { |
---|
653 | tmp=test; |
---|
654 | if(tmp) |
---|
655 | { |
---|
656 | for (i=0; optionStruct[i].setval!=0; i++) |
---|
657 | { |
---|
658 | if (optionStruct[i].setval & test) |
---|
659 | { |
---|
660 | StringAppend(" %s",optionStruct[i].name); |
---|
661 | tmp &=optionStruct[i].resetval; |
---|
662 | } |
---|
663 | } |
---|
664 | for (i=0; i<32; i++) |
---|
665 | { |
---|
666 | if (tmp & Sy_bit(i)) StringAppend(" %d",i); |
---|
667 | } |
---|
668 | } |
---|
669 | tmp=verbose; |
---|
670 | if (tmp) |
---|
671 | { |
---|
672 | for (i=0; verboseStruct[i].setval!=0; i++) |
---|
673 | { |
---|
674 | if (verboseStruct[i].setval & tmp) |
---|
675 | { |
---|
676 | StringAppend(" %s",verboseStruct[i].name); |
---|
677 | tmp &=verboseStruct[i].resetval; |
---|
678 | } |
---|
679 | } |
---|
680 | for (i=1; i<32; i++) |
---|
681 | { |
---|
682 | if (tmp & Sy_bit(i)) StringAppend(" %d",i+32); |
---|
683 | } |
---|
684 | } |
---|
685 | return omStrDup(StringAppendS("")); |
---|
686 | } |
---|
687 | else |
---|
688 | return omStrDup(StringAppendS(" none")); |
---|
689 | } |
---|
690 | |
---|
691 | char * versionString() |
---|
692 | { |
---|
693 | char* str = StringSetS(""); |
---|
694 | StringAppend("Singular for %s version %s (%d-%lu) %s\nwith\n", |
---|
695 | S_UNAME, S_VERSION1, SINGULAR_VERSION, |
---|
696 | feVersionId,singular_date); |
---|
697 | StringAppendS("\t"); |
---|
698 | #ifdef HAVE_FACTORY |
---|
699 | StringAppend("factory(%s),", factoryVersion); |
---|
700 | StringAppend("libfac(%s,%s),\n\t",libfac_version,libfac_date); |
---|
701 | #endif |
---|
702 | #if defined (__GNU_MP_VERSION) && defined (__GNU_MP_VERSION_MINOR) |
---|
703 | StringAppend("GMP(%d.%d),",__GNU_MP_VERSION,__GNU_MP_VERSION_MINOR); |
---|
704 | #else |
---|
705 | StringAppendS("GMP(1.3),"); |
---|
706 | #endif |
---|
707 | #ifdef HAVE_NTL |
---|
708 | #include "NTL/version.h" |
---|
709 | StringAppend("NTL(%s),",NTL_VERSION); |
---|
710 | #endif |
---|
711 | #ifdef HAVE_MPSR |
---|
712 | StringAppend("MP(%s),",MP_VERSION); |
---|
713 | #endif |
---|
714 | #if SIZEOF_VOIDP == 8 |
---|
715 | StringAppendS("64bit,"); |
---|
716 | #else |
---|
717 | StringAppendS("32bit,"); |
---|
718 | #endif |
---|
719 | #if defined(HAVE_DYN_RL) |
---|
720 | if (fe_fgets_stdin==fe_fgets_dummy) |
---|
721 | StringAppendS("no input,"); |
---|
722 | else if (fe_fgets_stdin==fe_fgets) |
---|
723 | StringAppendS("fgets,"); |
---|
724 | if (fe_fgets_stdin==fe_fgets_stdin_drl) |
---|
725 | StringAppendS("dynamic readline,"); |
---|
726 | #ifdef HAVE_FEREAD |
---|
727 | else if (fe_fgets_stdin==fe_fgets_stdin_emu) |
---|
728 | StringAppendS("emulated readline,"); |
---|
729 | #endif |
---|
730 | else |
---|
731 | StringAppendS("unknown fgets method,"); |
---|
732 | #else |
---|
733 | #if defined(HAVE_READLINE) && !defined(FEREAD) |
---|
734 | StringAppendS("static readline,"); |
---|
735 | #else |
---|
736 | #ifdef HAVE_FEREAD |
---|
737 | StringAppendS("emulated readline,"); |
---|
738 | #else |
---|
739 | StringAppendS("fgets,"); |
---|
740 | #endif |
---|
741 | #endif |
---|
742 | #endif |
---|
743 | #ifdef HAVE_PLURAL |
---|
744 | StringAppendS("Plural,"); |
---|
745 | #endif |
---|
746 | #ifdef HAVE_DBM |
---|
747 | StringAppendS("DBM,\n\t"); |
---|
748 | #else |
---|
749 | StringAppendS("\n\t"); |
---|
750 | #endif |
---|
751 | #ifdef HAVE_DYNAMIC_LOADING |
---|
752 | StringAppendS("dynamic modules,"); |
---|
753 | #endif |
---|
754 | if (p_procs_dynamic) StringAppendS("dynamic p_Procs,"); |
---|
755 | #ifdef TEST |
---|
756 | StringAppendS("TESTs,"); |
---|
757 | #endif |
---|
758 | #if YYDEBUG |
---|
759 | StringAppendS("YYDEBUG=1,"); |
---|
760 | #endif |
---|
761 | #ifdef HAVE_ASSUME |
---|
762 | StringAppendS("ASSUME,"); |
---|
763 | #endif |
---|
764 | #ifdef MDEBUG |
---|
765 | StringAppend("MDEBUG=%d,",MDEBUG); |
---|
766 | #endif |
---|
767 | #ifdef OM_CHECK |
---|
768 | StringAppend("OM_CHECK=%d,",OM_CHECK); |
---|
769 | #endif |
---|
770 | #ifdef OM_TRACK |
---|
771 | StringAppend("OM_TRACK=%d,",OM_TRACK); |
---|
772 | #endif |
---|
773 | #ifdef OM_NDEBUG |
---|
774 | StringAppendS("OM_NDEBUG,"); |
---|
775 | #endif |
---|
776 | #ifdef PDEBUG |
---|
777 | StringAppendS("PDEBUG,"); |
---|
778 | #endif |
---|
779 | #ifdef KDEBUG |
---|
780 | StringAppendS("KDEBUG,"); |
---|
781 | #endif |
---|
782 | #ifndef __OPTIMIZE__ |
---|
783 | StringAppendS("-g,"); |
---|
784 | #endif |
---|
785 | #ifdef HAVE_EIGENVAL |
---|
786 | StringAppendS("eigenvalues,"); |
---|
787 | #endif |
---|
788 | #ifdef HAVE_GMS |
---|
789 | StringAppendS("Gauss-Manin system,"); |
---|
790 | #endif |
---|
791 | #ifdef HAVE_RATGRING |
---|
792 | StringAppendS("ratGB,"); |
---|
793 | #endif |
---|
794 | StringAppend("random=%d\n",siRandomStart); |
---|
795 | StringAppend("\tCC=%s,\n\tCXX=%s" |
---|
796 | #ifdef __GNUC__ |
---|
797 | "(" __VERSION__ ")" |
---|
798 | #endif |
---|
799 | "\n",CC,CXX); |
---|
800 | feStringAppendResources(0); |
---|
801 | feStringAppendBrowsers(0); |
---|
802 | StringAppendS("\n"); |
---|
803 | return str; |
---|
804 | } |
---|
805 | |
---|
806 | #ifdef PDEBUG |
---|
807 | #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM) |
---|
808 | void p_SetRingOfLeftv(leftv l, ring r) |
---|
809 | { |
---|
810 | switch(l->rtyp) |
---|
811 | { |
---|
812 | case INT_CMD: |
---|
813 | case BIGINT_CMD: |
---|
814 | case IDHDL: |
---|
815 | case DEF_CMD: |
---|
816 | break; |
---|
817 | case POLY_CMD: |
---|
818 | case VECTOR_CMD: |
---|
819 | { |
---|
820 | poly p=(poly)l->data; |
---|
821 | while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); } |
---|
822 | break; |
---|
823 | } |
---|
824 | case IDEAL_CMD: |
---|
825 | case MODUL_CMD: |
---|
826 | case MATRIX_CMD: |
---|
827 | { |
---|
828 | ideal I=(ideal)l->data; |
---|
829 | int i; |
---|
830 | for(i=IDELEMS(I)-1;i>=0;i--) |
---|
831 | { |
---|
832 | poly p=I->m[i]; |
---|
833 | while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); } |
---|
834 | } |
---|
835 | break; |
---|
836 | } |
---|
837 | case COMMAND: |
---|
838 | { |
---|
839 | command d=(command)l->data; |
---|
840 | p_SetRingOfLeftv(&d->arg1, r); |
---|
841 | if (d->argc>1) p_SetRingOfLeftv(&d->arg2, r); |
---|
842 | if (d->argc>2) p_SetRingOfLeftv(&d->arg3, r); |
---|
843 | break; |
---|
844 | } |
---|
845 | default: |
---|
846 | printf("type %d not yet implementd in p_SetRingOfLeftv\n",l->rtyp); |
---|
847 | break; |
---|
848 | } |
---|
849 | } |
---|
850 | #endif |
---|
851 | #endif |
---|
852 | |
---|
853 | void listall(int showproc) |
---|
854 | { |
---|
855 | idhdl hh=basePack->idroot; |
---|
856 | PrintS("====== Top ==============\n"); |
---|
857 | while (hh!=NULL) |
---|
858 | { |
---|
859 | if (showproc || (IDTYP(hh)!=PROC_CMD)) |
---|
860 | { |
---|
861 | if (IDDATA(hh)==(void *)currRing) PrintS("(R)"); |
---|
862 | else if (IDDATA(hh)==(void *)currPack) PrintS("(P)"); |
---|
863 | else PrintS(" "); |
---|
864 | Print("::%s, typ %s level %d data %lx", |
---|
865 | IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh)); |
---|
866 | if ((IDTYP(hh)==RING_CMD) |
---|
867 | || (IDTYP(hh)==QRING_CMD)) |
---|
868 | Print(" ref: %d\n",IDRING(hh)->ref); |
---|
869 | else |
---|
870 | PrintLn(); |
---|
871 | } |
---|
872 | hh=IDNEXT(hh); |
---|
873 | } |
---|
874 | hh=basePack->idroot; |
---|
875 | while (hh!=NULL) |
---|
876 | { |
---|
877 | if (IDDATA(hh)==(void *)basePack) |
---|
878 | Print("(T)::%s, typ %s level %d data %lx\n", |
---|
879 | IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh)); |
---|
880 | else |
---|
881 | if ((IDTYP(hh)==RING_CMD) |
---|
882 | || (IDTYP(hh)==QRING_CMD) |
---|
883 | || (IDTYP(hh)==PACKAGE_CMD)) |
---|
884 | { |
---|
885 | Print("====== %s ==============\n",IDID(hh)); |
---|
886 | idhdl h2=IDRING(hh)->idroot; |
---|
887 | while (h2!=NULL) |
---|
888 | { |
---|
889 | if (showproc || (IDTYP(h2)!=PROC_CMD)) |
---|
890 | { |
---|
891 | if ((IDDATA(h2)==(void *)currRing) |
---|
892 | && ((IDTYP(h2)==RING_CMD)||(IDTYP(h2)==QRING_CMD))) |
---|
893 | PrintS("(R)"); |
---|
894 | else if (IDDATA(h2)==(void *)currPack) PrintS("(P)"); |
---|
895 | else PrintS(" "); |
---|
896 | Print("%s::%s, typ %s level %d data %lx\n", |
---|
897 | IDID(hh),IDID(h2),Tok2Cmdname(IDTYP(h2)),IDLEV(h2),(long)IDDATA(h2)); |
---|
898 | } |
---|
899 | h2=IDNEXT(h2); |
---|
900 | } |
---|
901 | } |
---|
902 | hh=IDNEXT(hh); |
---|
903 | } |
---|
904 | Print("currRing:%lx, currPack:%lx,basePack:%lx\n",(long)currRing,(long)currPack,(long)basePack); |
---|
905 | iiCheckPack(currPack); |
---|
906 | } |
---|
907 | #ifndef NDEBUG |
---|
908 | void checkall() |
---|
909 | { |
---|
910 | idhdl hh=basePack->idroot; |
---|
911 | while (hh!=NULL) |
---|
912 | { |
---|
913 | omCheckAddr(hh); |
---|
914 | omCheckAddr((ADDRESS)IDID(hh)); |
---|
915 | if (RingDependend(IDTYP(hh))) Print("%s typ %d in Top\n",IDID(hh),IDTYP(hh)); |
---|
916 | hh=IDNEXT(hh); |
---|
917 | } |
---|
918 | hh=basePack->idroot; |
---|
919 | while (hh!=NULL) |
---|
920 | { |
---|
921 | if (IDTYP(hh)==PACKAGE_CMD) |
---|
922 | { |
---|
923 | idhdl h2=IDPACKAGE(hh)->idroot; |
---|
924 | while (h2!=NULL) |
---|
925 | { |
---|
926 | omCheckAddr(h2); |
---|
927 | omCheckAddr((ADDRESS)IDID(h2)); |
---|
928 | if (RingDependend(IDTYP(h2))) Print("%s typ %d in %s\n",IDID(h2),IDTYP(h2),IDID(hh)); |
---|
929 | h2=IDNEXT(h2); |
---|
930 | } |
---|
931 | } |
---|
932 | hh=IDNEXT(hh); |
---|
933 | } |
---|
934 | } |
---|
935 | #endif |
---|
936 | |
---|
937 | #include <sys/types.h> |
---|
938 | #include <sys/stat.h> |
---|
939 | #include <unistd.h> |
---|
940 | |
---|
941 | extern "C" |
---|
942 | int singular_fstat(int fd, struct stat *buf) |
---|
943 | { |
---|
944 | return fstat(fd,buf); |
---|
945 | } |
---|
946 | |
---|