[150e5d] | 1 | /*****************************************************************************\ |
---|
[a3c063] | 2 | * Computer Algebra System SINGULAR |
---|
[150e5d] | 3 | \*****************************************************************************/ |
---|
[73fa1c] | 4 | /** @file misc_ip.cc |
---|
[150e5d] | 5 | * |
---|
| 6 | * This file provides miscellaneous functionality. |
---|
| 7 | * |
---|
[a8ee9f] | 8 | * For more general information, see the documentation in misc_ip.h. |
---|
[150e5d] | 9 | * |
---|
| 10 | * @internal @version \$Id$ |
---|
| 11 | * |
---|
| 12 | **/ |
---|
| 13 | /*****************************************************************************/ |
---|
| 14 | |
---|
| 15 | // include header files |
---|
[a8ee9f] | 16 | #include <misc/auxiliary.h> |
---|
[762407] | 17 | #include "config.h" |
---|
[047597] | 18 | #include <kernel/mod2.h> |
---|
[a8ee9f] | 19 | |
---|
[3e305b] | 20 | #ifdef HAVE_FACTORY |
---|
| 21 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
| 22 | #include <factory/factory.h> |
---|
| 23 | #endif |
---|
| 24 | |
---|
| 25 | #include <coeffs/si_gmp.h> |
---|
[a8ee9f] | 26 | #include <coeffs/coeffs.h> |
---|
| 27 | |
---|
[047597] | 28 | #include <polys/ext_fields/algext.h> |
---|
| 29 | #include <polys/ext_fields/transext.h> |
---|
| 30 | |
---|
| 31 | #include "misc_ip.h" |
---|
| 32 | #include "ipid.h" |
---|
[a8ee9f] | 33 | #include "feOpt.h" |
---|
| 34 | #include "silink.h" |
---|
[150e5d] | 35 | |
---|
[95eb6d] | 36 | // the following 2 inline functions are just convenience shortcuts for Frank's code: |
---|
| 37 | static inline void number2mpz(number n, mpz_t m){ n_MPZ(m, n, coeffs_BIGINT); } |
---|
[02fe5f] | 38 | static inline number mpz2number(mpz_t m){ return n_InitMPZ(m, coeffs_BIGINT); } |
---|
[555b03] | 39 | |
---|
[a8ee9f] | 40 | |
---|
[555b03] | 41 | void divTimes(mpz_t n, mpz_t d, int* times) |
---|
[150e5d] | 42 | { |
---|
| 43 | *times = 0; |
---|
[555b03] | 44 | mpz_t r; mpz_init(r); |
---|
| 45 | mpz_t q; mpz_init(q); |
---|
| 46 | mpz_fdiv_qr(q, r, n, d); |
---|
| 47 | while (mpz_cmp_ui(r, 0) == 0) |
---|
[150e5d] | 48 | { |
---|
| 49 | (*times)++; |
---|
[555b03] | 50 | mpz_set(n, q); |
---|
| 51 | mpz_fdiv_qr(q, r, n, d); |
---|
[150e5d] | 52 | } |
---|
[555b03] | 53 | mpz_clear(r); |
---|
| 54 | mpz_clear(q); |
---|
[150e5d] | 55 | } |
---|
| 56 | |
---|
[4df33b] | 57 | void divTimes_ui(mpz_t n, unsigned long d, int* times) |
---|
[41ab421] | 58 | { |
---|
| 59 | *times = 0; |
---|
| 60 | mpz_t r; mpz_init(r); |
---|
| 61 | mpz_t q; mpz_init(q); |
---|
| 62 | mpz_fdiv_qr_ui(q, r, n, d); |
---|
| 63 | while (mpz_cmp_ui(r, 0) == 0) |
---|
| 64 | { |
---|
| 65 | (*times)++; |
---|
| 66 | mpz_set(n, q); |
---|
| 67 | mpz_fdiv_qr_ui(q, r, n, d); |
---|
| 68 | } |
---|
| 69 | mpz_clear(r); |
---|
| 70 | mpz_clear(q); |
---|
| 71 | } |
---|
| 72 | |
---|
[4df33b] | 73 | static inline void divTimes_ui_ui(unsigned long *n, unsigned long d, int* times) |
---|
| 74 | { |
---|
| 75 | *times = 0; |
---|
| 76 | unsigned long q=(*n) / d; |
---|
| 77 | unsigned long r=(*n) % d; |
---|
| 78 | while (r==0) |
---|
| 79 | { |
---|
| 80 | (*times)++; |
---|
| 81 | (*n)=q; |
---|
| 82 | q=(*n)/d; r=(*n)%d; |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
[555b03] | 86 | void setListEntry(lists L, int index, mpz_t n) |
---|
| 87 | { /* assumes n > 0 */ |
---|
[41ab421] | 88 | /* try to fit nn into an int: */ |
---|
| 89 | if (mpz_size1(n)<=1) |
---|
| 90 | { |
---|
| 91 | int ui=(int)mpz_get_si(n); |
---|
| 92 | if ((((ui<<3)>>3)==ui) |
---|
| 93 | && (mpz_cmp_si(n,(long)ui)==0)) |
---|
| 94 | { |
---|
| 95 | L->m[index].rtyp = INT_CMD; L->m[index].data = (void*)ui; |
---|
| 96 | return; |
---|
| 97 | } |
---|
| 98 | } |
---|
[555b03] | 99 | number nn = mpz2number(n); |
---|
| 100 | L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn; |
---|
[41ab421] | 101 | } |
---|
| 102 | |
---|
[d322f7] | 103 | void setListEntry_ui(lists L, int index, unsigned long ui) |
---|
[41ab421] | 104 | { /* assumes n > 0 */ |
---|
[150e5d] | 105 | /* try to fit nn into an int: */ |
---|
[d322f7] | 106 | int i=(int)ui; |
---|
| 107 | if ((((unsigned long)i)==ui) && (((i<<3)>>3)==i)) |
---|
[41ab421] | 108 | { |
---|
[d322f7] | 109 | L->m[index].rtyp = INT_CMD; L->m[index].data = (void*)i; |
---|
[41ab421] | 110 | } |
---|
| 111 | else |
---|
[a3c063] | 112 | { |
---|
[a8ee9f] | 113 | number nn = n_Init(ui, coeffs_BIGINT); |
---|
[41ab421] | 114 | L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn; |
---|
[a3c063] | 115 | } |
---|
[150e5d] | 116 | } |
---|
[cdf5c3c] | 117 | |
---|
[555b03] | 118 | /* true iff p is prime */ |
---|
| 119 | /* |
---|
| 120 | bool isPrime(mpz_t p) |
---|
[cdf5c3c] | 121 | { |
---|
[555b03] | 122 | if (mpz_cmp_ui(p, 2) == 0) return true; |
---|
| 123 | if (mpz_cmp_ui(p, 3) == 0) return true; |
---|
| 124 | if (mpz_cmp_ui(p, 5) < 0) return false; |
---|
[cdf5c3c] | 125 | |
---|
[555b03] | 126 | mpz_t d; mpz_init_set_ui(d, 5); int add = 2; |
---|
| 127 | mpz_t sr; mpz_init(sr); mpz_sqrt(sr, p); |
---|
| 128 | mpz_t r; mpz_init(r); |
---|
| 129 | while (mpz_cmp(d, sr) <= 0) |
---|
[cdf5c3c] | 130 | { |
---|
[555b03] | 131 | mpz_cdiv_r(r, p, d); |
---|
| 132 | if (mpz_cmp_ui(r, 0) == 0) |
---|
[cdf5c3c] | 133 | { |
---|
[555b03] | 134 | mpz_clear(d); mpz_clear(sr); mpz_clear(r); |
---|
| 135 | return false; |
---|
[cdf5c3c] | 136 | } |
---|
[555b03] | 137 | mpz_add_ui(d, d, add); |
---|
| 138 | add += 2; if (add == 6) add = 2; |
---|
[cdf5c3c] | 139 | } |
---|
[555b03] | 140 | mpz_clear(d); mpz_clear(sr); mpz_clear(r); |
---|
| 141 | return true; |
---|
| 142 | } |
---|
| 143 | */ |
---|
| 144 | |
---|
| 145 | /* finds the next prime q, bound >= q >= p; |
---|
| 146 | in case of success, puts q into p; |
---|
| 147 | otherwise sets q = bound + 1; |
---|
| 148 | e.g. p = 24; nextPrime(p, 30) produces p = 29 (success), |
---|
| 149 | p = 24; nextPrime(p, 29) produces p = 29 (success), |
---|
| 150 | p = 24; nextPrime(p, 28) produces p = 29 (no success), |
---|
| 151 | p = 24; nextPrime(p, 27) produces p = 28 (no success) */ |
---|
| 152 | /* |
---|
| 153 | void nextPrime(mpz_t p, mpz_t bound) |
---|
| 154 | { |
---|
| 155 | int add; |
---|
| 156 | mpz_t r; mpz_init(r); mpz_cdiv_r_ui(r, p, 6); // r = p mod 6, 0 <= r <= 5 |
---|
| 157 | if (mpz_cmp_ui(r, 0) == 0) { mpz_add_ui(p, p, 1); add = 4; } |
---|
| 158 | if (mpz_cmp_ui(r, 1) == 0) { add = 4; } |
---|
| 159 | if (mpz_cmp_ui(r, 2) == 0) { mpz_add_ui(p, p, 3); add = 2; } |
---|
| 160 | if (mpz_cmp_ui(r, 3) == 0) { mpz_add_ui(p, p, 2); add = 2; } |
---|
| 161 | if (mpz_cmp_ui(r, 4) == 0) { mpz_add_ui(p, p, 1); add = 2; } |
---|
| 162 | if (mpz_cmp_ui(r, 5) == 0) { add = 2; } |
---|
| 163 | |
---|
| 164 | while (mpz_cmp(p, bound) <= 0) |
---|
| 165 | { |
---|
| 166 | if (isPrime(p)) { mpz_clear(r); return; } |
---|
| 167 | mpz_add_ui(p, p, add); |
---|
| 168 | add += 2; if (add == 6) add = 2; |
---|
| 169 | } |
---|
| 170 | mpz_set(p, bound); |
---|
| 171 | mpz_add_ui(p, p, 1); |
---|
| 172 | mpz_clear(r); |
---|
| 173 | return; |
---|
| 174 | } |
---|
| 175 | */ |
---|
[cdf5c3c] | 176 | |
---|
[a8ee9f] | 177 | |
---|
| 178 | |
---|
[555b03] | 179 | /* n and pBound are assumed to be bigint numbers */ |
---|
[3dabc0] | 180 | lists primeFactorisation(const number n, const number pBound) |
---|
[555b03] | 181 | { |
---|
| 182 | mpz_t nn; number2mpz(n, nn); |
---|
| 183 | mpz_t pb; number2mpz(pBound, pb); |
---|
| 184 | mpz_t b; number2mpz(pBound, b); |
---|
| 185 | mpz_t p; mpz_init(p); int tt; |
---|
| 186 | mpz_t sr; mpz_init(sr); int index = 0; int add; |
---|
| 187 | lists primes = (lists)omAllocBin(slists_bin); primes->Init(1000); |
---|
| 188 | int* multiplicities = new int[1000]; |
---|
[8acd267] | 189 | int positive=1; int probTest = 0; |
---|
[555b03] | 190 | |
---|
[a8ee9f] | 191 | if (!n_IsZero(n, coeffs_BIGINT)) |
---|
[555b03] | 192 | { |
---|
[a8ee9f] | 193 | if (!n_GreaterZero(n, coeffs_BIGINT)) |
---|
[4df33b] | 194 | { |
---|
| 195 | positive=-1; |
---|
| 196 | mpz_neg(nn,nn); |
---|
| 197 | } |
---|
| 198 | divTimes_ui(nn, 2, &tt); |
---|
| 199 | if (tt > 0) |
---|
| 200 | { |
---|
| 201 | setListEntry_ui(primes, index, 2); |
---|
| 202 | multiplicities[index++] = tt; |
---|
| 203 | } |
---|
[41ab421] | 204 | |
---|
[4df33b] | 205 | divTimes_ui(nn, 3, &tt); |
---|
[555b03] | 206 | if (tt > 0) |
---|
[cdf5c3c] | 207 | { |
---|
[4df33b] | 208 | setListEntry_ui(primes, index, 3); |
---|
[555b03] | 209 | multiplicities[index++] = tt; |
---|
[4df33b] | 210 | } |
---|
| 211 | |
---|
| 212 | unsigned long p_ui=5; add = 2; |
---|
[8c2051] | 213 | BOOLEAN b_is_0=(mpz_cmp_ui(b, 0) == 0); |
---|
[dc52c8] | 214 | BOOLEAN sr_sets_pb=FALSE; |
---|
[4df33b] | 215 | mpz_sqrt(sr, nn); |
---|
[3dabc0] | 216 | // there are 3 possible limits, we take the minimum: |
---|
| 217 | // - argument pBound (if >0) |
---|
| 218 | // - sr = sqrt(nn) |
---|
| 219 | // - 1<<31 |
---|
[8c2051] | 220 | unsigned long limit=~(0L); |
---|
| 221 | if (b_is_0 || (mpz_cmp(pb, sr) > 0)) |
---|
[03ac3b] | 222 | { |
---|
| 223 | mpz_set(pb, sr); |
---|
[dc52c8] | 224 | sr_sets_pb=TRUE; |
---|
[03ac3b] | 225 | } |
---|
[8c2051] | 226 | if (mpz_cmp_ui(pb, limit)<0) |
---|
[3dabc0] | 227 | { |
---|
| 228 | limit=mpz_get_ui(pb); |
---|
| 229 | } |
---|
| 230 | else |
---|
[03ac3b] | 231 | { |
---|
| 232 | mpz_set_ui(pb,limit); |
---|
| 233 | } |
---|
[4df33b] | 234 | while (p_ui <=limit) |
---|
| 235 | { |
---|
| 236 | divTimes_ui(nn, p_ui, &tt); |
---|
| 237 | if (tt > 0) |
---|
[41ab421] | 238 | { |
---|
[4df33b] | 239 | setListEntry_ui(primes, index, p_ui); |
---|
| 240 | multiplicities[index++] = tt; |
---|
| 241 | //mpz_sqrt(sr, nn); |
---|
| 242 | //if ((mpz_cmp_ui(b, 0) == 0) || (mpz_cmp(pb, sr) > 0)) mpz_set(pb, sr); |
---|
[3dabc0] | 243 | if (mpz_size1(nn)<=2) |
---|
[4df33b] | 244 | { |
---|
| 245 | mpz_sqrt(sr, nn); |
---|
[dc52c8] | 246 | if (sr_sets_pb || (mpz_cmp(pb, sr) > 0)) mpz_set(pb, sr); |
---|
[4df33b] | 247 | unsigned long l=mpz_get_ui(sr); |
---|
[03ac3b] | 248 | if (l<limit) { limit=l; } |
---|
[d322f7] | 249 | if (mpz_size1(nn)<=1) |
---|
| 250 | { |
---|
| 251 | unsigned long nn_ui=mpz_get_ui(nn); |
---|
[3dabc0] | 252 | while (p_ui <=limit) |
---|
[d322f7] | 253 | { |
---|
[4df33b] | 254 | divTimes_ui_ui(&nn_ui, p_ui, &tt); |
---|
| 255 | if (tt > 0) |
---|
| 256 | { |
---|
| 257 | setListEntry_ui(primes, index, p_ui); |
---|
| 258 | multiplicities[index++] = tt; |
---|
[3dabc0] | 259 | if (nn_ui==1) break; |
---|
[03ac3b] | 260 | if (nn_ui<(limit/6)) { limit=nn_ui/6;} |
---|
[4df33b] | 261 | } |
---|
| 262 | p_ui +=add; |
---|
[dc52c8] | 263 | //add += 2; if (add == 6) add = 2; |
---|
| 264 | add =2+2*(add==2); |
---|
[d322f7] | 265 | } |
---|
| 266 | mpz_set_ui(nn,nn_ui); |
---|
| 267 | break; |
---|
| 268 | } |
---|
[4df33b] | 269 | } |
---|
| 270 | } |
---|
| 271 | p_ui +=add; |
---|
[dc52c8] | 272 | //add += 2; if (add == 6) add = 2; |
---|
| 273 | add =2+2*(add==2); |
---|
[4df33b] | 274 | } |
---|
| 275 | mpz_set_ui(p, p_ui); |
---|
| 276 | mpz_sqrt(sr, nn); |
---|
[dc52c8] | 277 | if (b_is_0 || sr_sets_pb || (mpz_cmp(pb, sr) > 0)) mpz_set(pb, sr); |
---|
[4df33b] | 278 | while (mpz_cmp(pb, p) >= 0) |
---|
| 279 | { |
---|
| 280 | divTimes(nn, p, &tt); |
---|
| 281 | if (tt > 0) |
---|
| 282 | { |
---|
| 283 | setListEntry(primes, index, p); |
---|
| 284 | multiplicities[index++] = tt; |
---|
[3dabc0] | 285 | if (mpz_cmp_ui(nn,1)==0) break; |
---|
[dc52c8] | 286 | mpz_sqrt(sr, nn); |
---|
| 287 | if (b_is_0 || sr_sets_pb || (mpz_cmp(pb, sr) > 0)) mpz_set(pb, sr); |
---|
[41ab421] | 288 | } |
---|
[4df33b] | 289 | mpz_add_ui(p, p, add); |
---|
[dc52c8] | 290 | //add += 2; if (add == 6) add = 2; |
---|
| 291 | add =2+2*(add==2); |
---|
[cdf5c3c] | 292 | } |
---|
[4df33b] | 293 | if ((mpz_cmp_ui(nn, 1) > 0) && |
---|
[b57c45] | 294 | (b_is_0 || (mpz_cmp(nn, b) <= 0))) |
---|
[cdf5c3c] | 295 | { |
---|
[4df33b] | 296 | setListEntry(primes, index, nn); |
---|
| 297 | multiplicities[index++] = 1; |
---|
| 298 | mpz_set_ui(nn, 1); |
---|
[cdf5c3c] | 299 | } |
---|
[8acd267] | 300 | if ((mpz_cmp_ui(nn, 1) > 0) && (mpz_probab_prime_p(nn, 25) != 0)) |
---|
| 301 | probTest = 1; |
---|
[cdf5c3c] | 302 | } |
---|
| 303 | |
---|
[555b03] | 304 | lists primesL = (lists)omAllocBin(slists_bin); |
---|
| 305 | primesL->Init(index); |
---|
| 306 | for (int i = 0; i < index; i++) |
---|
[cdf5c3c] | 307 | { |
---|
[555b03] | 308 | primesL->m[i].rtyp = primes->m[i].rtyp; |
---|
| 309 | primesL->m[i].data = primes->m[i].data; |
---|
[cdf5c3c] | 310 | } |
---|
[555b03] | 311 | omFreeSize((ADDRESS)primes->m, (primes->nr + 1) * sizeof(sleftv)); |
---|
| 312 | omFreeBin((ADDRESS)primes, slists_bin); |
---|
[cdf5c3c] | 313 | |
---|
[555b03] | 314 | lists multiplicitiesL = (lists)omAllocBin(slists_bin); |
---|
| 315 | multiplicitiesL->Init(index); |
---|
| 316 | for (int i = 0; i < index; i++) |
---|
[cdf5c3c] | 317 | { |
---|
[555b03] | 318 | multiplicitiesL->m[i].rtyp = INT_CMD; |
---|
| 319 | multiplicitiesL->m[i].data = (void*)multiplicities[i]; |
---|
[cdf5c3c] | 320 | } |
---|
[555b03] | 321 | delete[] multiplicities; |
---|
| 322 | |
---|
| 323 | lists L=(lists)omAllocBin(slists_bin); |
---|
| 324 | L->Init(4); |
---|
[4df33b] | 325 | if (positive==-1) mpz_neg(nn,nn); |
---|
[8acd267] | 326 | L->m[0].rtyp = LIST_CMD; L->m[0].data = (void*)primesL; |
---|
| 327 | L->m[1].rtyp = LIST_CMD; L->m[1].data = (void*)multiplicitiesL; |
---|
| 328 | setListEntry(L, 2, nn); |
---|
[555b03] | 329 | L->m[3].rtyp = INT_CMD; L->m[3].data = (void*)probTest; |
---|
| 330 | mpz_clear(nn); mpz_clear(pb); mpz_clear(b); mpz_clear(p); mpz_clear(sr); |
---|
[cdf5c3c] | 331 | |
---|
| 332 | return L; |
---|
| 333 | } |
---|
[8d38c87] | 334 | |
---|
[b1dfaf] | 335 | #include <omalloc/omalloc.h> |
---|
[e7d5ef] | 336 | #include <misc/mylimits.h> |
---|
[a8ee9f] | 337 | |
---|
[0fb34ba] | 338 | #include <misc/options.h> |
---|
[a8ee9f] | 339 | #include <misc/intvec.h> |
---|
| 340 | |
---|
| 341 | #include <polys/monomials/ring.h> |
---|
| 342 | #include <polys/templates/p_Procs.h> |
---|
| 343 | |
---|
[599326] | 344 | #include <kernel/febase.h> |
---|
| 345 | #include <kernel/page.h> |
---|
| 346 | #include <kernel/kstd1.h> |
---|
| 347 | #include <kernel/timer.h> |
---|
[8d38c87] | 348 | |
---|
[a8ee9f] | 349 | |
---|
| 350 | #include "subexpr.h" |
---|
| 351 | #include "cntrlc.h" |
---|
| 352 | #include "ipid.h" |
---|
| 353 | #include "ipshell.h" |
---|
| 354 | |
---|
| 355 | #include "version.h" |
---|
| 356 | #include "static.h" |
---|
| 357 | |
---|
[cc7302] | 358 | #include "fehelp.h" |
---|
| 359 | |
---|
[8d38c87] | 360 | #ifdef HAVE_STATIC |
---|
| 361 | #undef HAVE_DYN_RL |
---|
| 362 | #endif |
---|
| 363 | |
---|
| 364 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
| 365 | |
---|
| 366 | //#ifdef HAVE_LIBPARSER |
---|
| 367 | //# include "libparse.h" |
---|
| 368 | //#endif /* HAVE_LIBPARSER */ |
---|
| 369 | |
---|
| 370 | |
---|
| 371 | /* version strings */ |
---|
| 372 | #ifdef HAVE_MPSR |
---|
| 373 | #include <MP_Config.h> |
---|
| 374 | #endif |
---|
| 375 | |
---|
| 376 | /*2 |
---|
| 377 | * the renice routine for very large jobs |
---|
| 378 | * works only on unix machines, |
---|
| 379 | * testet on : linux, HP 9.0 |
---|
| 380 | * |
---|
| 381 | *#include <sys/times.h> |
---|
| 382 | *#include <sys/resource.h> |
---|
| 383 | *extern "C" int setpriority(int,int,int); |
---|
| 384 | *void very_nice() |
---|
| 385 | *{ |
---|
| 386 | *#ifndef NO_SETPRIORITY |
---|
| 387 | * setpriority(PRIO_PROCESS,0,19); |
---|
| 388 | *#endif |
---|
| 389 | * sleep(10); |
---|
| 390 | *} |
---|
| 391 | */ |
---|
| 392 | |
---|
[a8ee9f] | 393 | #include <string.h> |
---|
| 394 | #include <unistd.h> |
---|
| 395 | #include <stdio.h> |
---|
| 396 | #include <stddef.h> |
---|
| 397 | #include <stdlib.h> |
---|
| 398 | #include <time.h> |
---|
| 399 | |
---|
| 400 | |
---|
[8d38c87] | 401 | void singular_example(char *str) |
---|
| 402 | { |
---|
| 403 | assume(str!=NULL); |
---|
| 404 | char *s=str; |
---|
| 405 | while (*s==' ') s++; |
---|
| 406 | char *ss=s; |
---|
| 407 | while (*ss!='\0') ss++; |
---|
| 408 | while (*ss<=' ') |
---|
| 409 | { |
---|
| 410 | *ss='\0'; |
---|
| 411 | ss--; |
---|
| 412 | } |
---|
| 413 | idhdl h=IDROOT->get(s,myynest); |
---|
| 414 | if ((h!=NULL) && (IDTYP(h)==PROC_CMD)) |
---|
| 415 | { |
---|
| 416 | char *lib=iiGetLibName(IDPROC(h)); |
---|
| 417 | if((lib!=NULL)&&(*lib!='\0')) |
---|
| 418 | { |
---|
| 419 | Print("// proc %s from lib %s\n",s,lib); |
---|
| 420 | s=iiGetLibProcBuffer(IDPROC(h), 2); |
---|
| 421 | if (s!=NULL) |
---|
| 422 | { |
---|
| 423 | if (strlen(s)>5) |
---|
| 424 | { |
---|
| 425 | iiEStart(s,IDPROC(h)); |
---|
[a71a00] | 426 | omFree((ADDRESS)s); |
---|
[8d38c87] | 427 | return; |
---|
| 428 | } |
---|
| 429 | else omFree((ADDRESS)s); |
---|
| 430 | } |
---|
| 431 | } |
---|
| 432 | } |
---|
| 433 | else |
---|
| 434 | { |
---|
| 435 | char sing_file[MAXPATHLEN]; |
---|
| 436 | FILE *fd=NULL; |
---|
| 437 | char *res_m=feResource('m', 0); |
---|
| 438 | if (res_m!=NULL) |
---|
| 439 | { |
---|
| 440 | sprintf(sing_file, "%s/%s.sing", res_m, s); |
---|
| 441 | fd = feFopen(sing_file, "r"); |
---|
| 442 | } |
---|
| 443 | if (fd != NULL) |
---|
| 444 | { |
---|
| 445 | |
---|
| 446 | int old_echo = si_echo; |
---|
| 447 | int length, got; |
---|
| 448 | char* s; |
---|
| 449 | |
---|
| 450 | fseek(fd, 0, SEEK_END); |
---|
| 451 | length = ftell(fd); |
---|
| 452 | fseek(fd, 0, SEEK_SET); |
---|
| 453 | s = (char*) omAlloc((length+20)*sizeof(char)); |
---|
| 454 | got = fread(s, sizeof(char), length, fd); |
---|
| 455 | fclose(fd); |
---|
| 456 | if (got != length) |
---|
| 457 | { |
---|
| 458 | Werror("Error while reading file %s", sing_file); |
---|
| 459 | } |
---|
| 460 | else |
---|
| 461 | { |
---|
| 462 | s[length] = '\0'; |
---|
| 463 | strcat(s, "\n;return();\n\n"); |
---|
| 464 | si_echo = 2; |
---|
| 465 | iiEStart(s, NULL); |
---|
| 466 | si_echo = old_echo; |
---|
| 467 | } |
---|
[a71a00] | 468 | omFree(s); |
---|
[8d38c87] | 469 | } |
---|
| 470 | else |
---|
| 471 | { |
---|
| 472 | Werror("no example for %s", str); |
---|
| 473 | } |
---|
| 474 | } |
---|
| 475 | } |
---|
| 476 | |
---|
| 477 | |
---|
| 478 | struct soptionStruct |
---|
| 479 | { |
---|
| 480 | const char * name; |
---|
| 481 | unsigned setval; |
---|
| 482 | unsigned resetval; |
---|
| 483 | }; |
---|
| 484 | |
---|
| 485 | struct soptionStruct optionStruct[]= |
---|
| 486 | { |
---|
| 487 | {"prot", Sy_bit(OPT_PROT), ~Sy_bit(OPT_PROT) }, |
---|
| 488 | {"redSB", Sy_bit(OPT_REDSB), ~Sy_bit(OPT_REDSB) }, |
---|
| 489 | {"notBuckets", Sy_bit(OPT_NOT_BUCKETS), ~Sy_bit(OPT_NOT_BUCKETS) }, |
---|
| 490 | {"notSugar", Sy_bit(OPT_NOT_SUGAR), ~Sy_bit(OPT_NOT_SUGAR) }, |
---|
| 491 | {"interrupt", Sy_bit(OPT_INTERRUPT), ~Sy_bit(OPT_INTERRUPT) }, |
---|
| 492 | {"sugarCrit", Sy_bit(OPT_SUGARCRIT), ~Sy_bit(OPT_SUGARCRIT) }, |
---|
[750e70] | 493 | {"teach", Sy_bit(OPT_DEBUG), ~Sy_bit(OPT_DEBUG) }, |
---|
| 494 | {"notSyzMinim", Sy_bit(OPT_NO_SYZ_MINIM), ~Sy_bit(OPT_NO_SYZ_MINIM) }, |
---|
[8d38c87] | 495 | /* 9 return SB in syz, quotient, intersect */ |
---|
| 496 | {"returnSB", Sy_bit(OPT_RETURN_SB), ~Sy_bit(OPT_RETURN_SB) }, |
---|
| 497 | {"fastHC", Sy_bit(OPT_FASTHC), ~Sy_bit(OPT_FASTHC) }, |
---|
| 498 | /* 11-19 sort in L/T */ |
---|
| 499 | {"staircaseBound",Sy_bit(OPT_STAIRCASEBOUND),~Sy_bit(OPT_STAIRCASEBOUND) }, |
---|
| 500 | {"multBound", Sy_bit(OPT_MULTBOUND), ~Sy_bit(OPT_MULTBOUND) }, |
---|
| 501 | {"degBound", Sy_bit(OPT_DEGBOUND), ~Sy_bit(OPT_DEGBOUND) }, |
---|
| 502 | /* 25 no redTail(p)/redTail(s) */ |
---|
| 503 | {"redTail", Sy_bit(OPT_REDTAIL), ~Sy_bit(OPT_REDTAIL) }, |
---|
| 504 | {"redThrough", Sy_bit(OPT_REDTHROUGH), ~Sy_bit(OPT_REDTHROUGH) }, |
---|
| 505 | {"lazy", Sy_bit(OPT_OLDSTD), ~Sy_bit(OPT_OLDSTD) }, |
---|
| 506 | {"intStrategy", Sy_bit(OPT_INTSTRATEGY), ~Sy_bit(OPT_INTSTRATEGY) }, |
---|
| 507 | {"infRedTail", Sy_bit(OPT_INFREDTAIL), ~Sy_bit(OPT_INFREDTAIL) }, |
---|
| 508 | /* 30: use not regularity for syz */ |
---|
| 509 | {"notRegularity",Sy_bit(OPT_NOTREGULARITY), ~Sy_bit(OPT_NOTREGULARITY) }, |
---|
| 510 | {"weightM", Sy_bit(OPT_WEIGHTM), ~Sy_bit(OPT_WEIGHTM) }, |
---|
| 511 | /*special for "none" and also end marker for showOption:*/ |
---|
| 512 | {"ne", 0, 0 } |
---|
| 513 | }; |
---|
| 514 | |
---|
| 515 | struct soptionStruct verboseStruct[]= |
---|
| 516 | { |
---|
| 517 | {"mem", Sy_bit(V_SHOW_MEM), ~Sy_bit(V_SHOW_MEM) }, |
---|
| 518 | {"yacc", Sy_bit(V_YACC), ~Sy_bit(V_YACC) }, |
---|
| 519 | {"redefine", Sy_bit(V_REDEFINE), ~Sy_bit(V_REDEFINE) }, |
---|
| 520 | {"reading", Sy_bit(V_READING), ~Sy_bit(V_READING) }, |
---|
| 521 | {"loadLib", Sy_bit(V_LOAD_LIB), ~Sy_bit(V_LOAD_LIB) }, |
---|
| 522 | {"debugLib", Sy_bit(V_DEBUG_LIB), ~Sy_bit(V_DEBUG_LIB) }, |
---|
| 523 | {"loadProc", Sy_bit(V_LOAD_PROC), ~Sy_bit(V_LOAD_PROC) }, |
---|
| 524 | {"defRes", Sy_bit(V_DEF_RES), ~Sy_bit(V_DEF_RES) }, |
---|
| 525 | {"usage", Sy_bit(V_SHOW_USE), ~Sy_bit(V_SHOW_USE) }, |
---|
| 526 | {"Imap", Sy_bit(V_IMAP), ~Sy_bit(V_IMAP) }, |
---|
| 527 | {"prompt", Sy_bit(V_PROMPT), ~Sy_bit(V_PROMPT) }, |
---|
| 528 | {"length", Sy_bit(V_LENGTH), ~Sy_bit(V_LENGTH) }, |
---|
| 529 | {"notWarnSB",Sy_bit(V_NSB), ~Sy_bit(V_NSB) }, |
---|
| 530 | {"contentSB",Sy_bit(V_CONTENTSB), ~Sy_bit(V_CONTENTSB) }, |
---|
| 531 | {"cancelunit",Sy_bit(V_CANCELUNIT),~Sy_bit(V_CANCELUNIT)}, |
---|
| 532 | {"modpsolve",Sy_bit(V_MODPSOLVSB),~Sy_bit(V_MODPSOLVSB)}, |
---|
| 533 | {"geometricSB",Sy_bit(V_UPTORADICAL),~Sy_bit(V_UPTORADICAL)}, |
---|
| 534 | {"findMonomials",Sy_bit(V_FINDMONOM),~Sy_bit(V_FINDMONOM)}, |
---|
| 535 | {"coefStrat",Sy_bit(V_COEFSTRAT), ~Sy_bit(V_COEFSTRAT)}, |
---|
| 536 | {"qringNF", Sy_bit(V_QRING), ~Sy_bit(V_QRING)}, |
---|
[d693da2] | 537 | {"warn", Sy_bit(V_ALLWARN), ~Sy_bit(V_ALLWARN)}, |
---|
[f6bfc4] | 538 | {"interedSyz",Sy_bit(V_INTERSECT_SYZ), ~Sy_bit(V_INTERSECT_SYZ)}, |
---|
| 539 | {"interedElim",Sy_bit(V_INTERSECT_ELIM), ~Sy_bit(V_INTERSECT_ELIM)}, |
---|
[8d38c87] | 540 | /*special for "none" and also end marker for showOption:*/ |
---|
| 541 | {"ne", 0, 0 } |
---|
| 542 | }; |
---|
| 543 | |
---|
| 544 | BOOLEAN setOption(leftv res, leftv v) |
---|
| 545 | { |
---|
| 546 | const char *n; |
---|
| 547 | do |
---|
| 548 | { |
---|
| 549 | if (v->Typ()==STRING_CMD) |
---|
| 550 | { |
---|
| 551 | n=(const char *)v->CopyD(STRING_CMD); |
---|
| 552 | } |
---|
| 553 | else |
---|
| 554 | { |
---|
| 555 | if (v->name==NULL) |
---|
| 556 | return TRUE; |
---|
| 557 | if (v->rtyp==0) |
---|
| 558 | { |
---|
| 559 | n=v->name; |
---|
| 560 | v->name=NULL; |
---|
| 561 | } |
---|
| 562 | else |
---|
| 563 | { |
---|
| 564 | n=omStrDup(v->name); |
---|
| 565 | } |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | int i; |
---|
| 569 | |
---|
| 570 | if(strcmp(n,"get")==0) |
---|
| 571 | { |
---|
| 572 | intvec *w=new intvec(2); |
---|
| 573 | (*w)[0]=test; |
---|
| 574 | (*w)[1]=verbose; |
---|
| 575 | res->rtyp=INTVEC_CMD; |
---|
| 576 | res->data=(void *)w; |
---|
| 577 | goto okay; |
---|
| 578 | } |
---|
| 579 | if(strcmp(n,"set")==0) |
---|
| 580 | { |
---|
| 581 | if((v->next!=NULL) |
---|
| 582 | &&(v->next->Typ()==INTVEC_CMD)) |
---|
| 583 | { |
---|
| 584 | v=v->next; |
---|
| 585 | intvec *w=(intvec*)v->Data(); |
---|
| 586 | test=(*w)[0]; |
---|
| 587 | verbose=(*w)[1]; |
---|
| 588 | #if 0 |
---|
| 589 | if (TEST_OPT_INTSTRATEGY && (currRing!=NULL) |
---|
| 590 | && rField_has_simple_inverse() |
---|
| 591 | #ifdef HAVE_RINGS |
---|
| 592 | && !rField_is_Ring(currRing) |
---|
| 593 | #endif |
---|
| 594 | ) { |
---|
| 595 | test &=~Sy_bit(OPT_INTSTRATEGY); |
---|
| 596 | } |
---|
| 597 | #endif |
---|
| 598 | goto okay; |
---|
| 599 | } |
---|
| 600 | } |
---|
| 601 | if(strcmp(n,"none")==0) |
---|
| 602 | { |
---|
| 603 | test=0; |
---|
| 604 | verbose=0; |
---|
| 605 | goto okay; |
---|
| 606 | } |
---|
| 607 | for (i=0; (i==0) || (optionStruct[i-1].setval!=0); i++) |
---|
| 608 | { |
---|
| 609 | if (strcmp(n,optionStruct[i].name)==0) |
---|
| 610 | { |
---|
| 611 | if (optionStruct[i].setval & validOpts) |
---|
| 612 | { |
---|
| 613 | test |= optionStruct[i].setval; |
---|
| 614 | // optOldStd disables redthrough |
---|
| 615 | if (optionStruct[i].setval == Sy_bit(OPT_OLDSTD)) |
---|
| 616 | test &= ~Sy_bit(OPT_REDTHROUGH); |
---|
| 617 | } |
---|
| 618 | else |
---|
| 619 | Warn("cannot set option"); |
---|
| 620 | #if 0 |
---|
| 621 | if (TEST_OPT_INTSTRATEGY && (currRing!=NULL) |
---|
| 622 | && rField_has_simple_inverse() |
---|
| 623 | #ifdef HAVE_RINGS |
---|
| 624 | && !rField_is_Ring(currRing) |
---|
| 625 | #endif |
---|
| 626 | ) { |
---|
| 627 | test &=~Sy_bit(OPT_INTSTRATEGY); |
---|
| 628 | } |
---|
| 629 | #endif |
---|
| 630 | goto okay; |
---|
| 631 | } |
---|
| 632 | else if ((strncmp(n,"no",2)==0) |
---|
| 633 | && (strcmp(n+2,optionStruct[i].name)==0)) |
---|
| 634 | { |
---|
| 635 | if (optionStruct[i].setval & validOpts) |
---|
| 636 | { |
---|
| 637 | test &= optionStruct[i].resetval; |
---|
| 638 | } |
---|
| 639 | else |
---|
| 640 | Warn("cannot clear option"); |
---|
| 641 | goto okay; |
---|
| 642 | } |
---|
| 643 | } |
---|
| 644 | for (i=0; (i==0) || (verboseStruct[i-1].setval!=0); i++) |
---|
| 645 | { |
---|
| 646 | if (strcmp(n,verboseStruct[i].name)==0) |
---|
| 647 | { |
---|
| 648 | verbose |= verboseStruct[i].setval; |
---|
| 649 | #ifdef YYDEBUG |
---|
| 650 | #if YYDEBUG |
---|
| 651 | /*debugging the bison grammar --> grammar.cc*/ |
---|
| 652 | extern int yydebug; |
---|
| 653 | if (BVERBOSE(V_YACC)) yydebug=1; |
---|
| 654 | else yydebug=0; |
---|
| 655 | #endif |
---|
| 656 | #endif |
---|
| 657 | goto okay; |
---|
| 658 | } |
---|
| 659 | else if ((strncmp(n,"no",2)==0) |
---|
| 660 | && (strcmp(n+2,verboseStruct[i].name)==0)) |
---|
| 661 | { |
---|
| 662 | verbose &= verboseStruct[i].resetval; |
---|
| 663 | #ifdef YYDEBUG |
---|
| 664 | #if YYDEBUG |
---|
| 665 | /*debugging the bison grammar --> grammar.cc*/ |
---|
| 666 | extern int yydebug; |
---|
| 667 | if (BVERBOSE(V_YACC)) yydebug=1; |
---|
| 668 | else yydebug=0; |
---|
| 669 | #endif |
---|
| 670 | #endif |
---|
| 671 | goto okay; |
---|
| 672 | } |
---|
| 673 | } |
---|
| 674 | Werror("unknown option `%s`",n); |
---|
| 675 | okay: |
---|
| 676 | if (currRing != NULL) |
---|
| 677 | currRing->options = test & TEST_RINGDEP_OPTS; |
---|
| 678 | omFree((ADDRESS)n); |
---|
| 679 | v=v->next; |
---|
| 680 | } while (v!=NULL); |
---|
[715936] | 681 | |
---|
[eeae6e3] | 682 | #ifdef OM_SINGULAR_CONFIG_H |
---|
| 683 | // set global variable to show memory usage |
---|
[22303d] | 684 | extern int om_sing_opt_show_mem; |
---|
[da8702] | 685 | if (BVERBOSE(V_SHOW_MEM)) om_sing_opt_show_mem = 1; |
---|
| 686 | else om_sing_opt_show_mem = 0; |
---|
[eeae6e3] | 687 | #endif |
---|
[715936] | 688 | |
---|
[8d38c87] | 689 | return FALSE; |
---|
| 690 | } |
---|
| 691 | |
---|
| 692 | char * showOption() |
---|
| 693 | { |
---|
| 694 | int i; |
---|
| 695 | BITSET tmp; |
---|
| 696 | |
---|
| 697 | StringSetS("//options:"); |
---|
| 698 | if ((test!=0)||(verbose!=0)) |
---|
| 699 | { |
---|
| 700 | tmp=test; |
---|
| 701 | if(tmp) |
---|
| 702 | { |
---|
| 703 | for (i=0; optionStruct[i].setval!=0; i++) |
---|
| 704 | { |
---|
| 705 | if (optionStruct[i].setval & test) |
---|
| 706 | { |
---|
| 707 | StringAppend(" %s",optionStruct[i].name); |
---|
| 708 | tmp &=optionStruct[i].resetval; |
---|
| 709 | } |
---|
| 710 | } |
---|
| 711 | for (i=0; i<32; i++) |
---|
| 712 | { |
---|
| 713 | if (tmp & Sy_bit(i)) StringAppend(" %d",i); |
---|
| 714 | } |
---|
| 715 | } |
---|
| 716 | tmp=verbose; |
---|
| 717 | if (tmp) |
---|
| 718 | { |
---|
| 719 | for (i=0; verboseStruct[i].setval!=0; i++) |
---|
| 720 | { |
---|
| 721 | if (verboseStruct[i].setval & tmp) |
---|
| 722 | { |
---|
| 723 | StringAppend(" %s",verboseStruct[i].name); |
---|
| 724 | tmp &=verboseStruct[i].resetval; |
---|
| 725 | } |
---|
| 726 | } |
---|
| 727 | for (i=1; i<32; i++) |
---|
| 728 | { |
---|
| 729 | if (tmp & Sy_bit(i)) StringAppend(" %d",i+32); |
---|
| 730 | } |
---|
| 731 | } |
---|
| 732 | return omStrDup(StringAppendS("")); |
---|
| 733 | } |
---|
| 734 | else |
---|
| 735 | return omStrDup(StringAppendS(" none")); |
---|
| 736 | } |
---|
| 737 | |
---|
| 738 | char * versionString() |
---|
| 739 | { |
---|
| 740 | char* str = StringSetS(""); |
---|
[d7e6e0] | 741 | StringAppend("Singular for %s version %s (%d-%s) %s\nwith\n", |
---|
[8d38c87] | 742 | S_UNAME, S_VERSION1, SINGULAR_VERSION, |
---|
| 743 | feVersionId,singular_date); |
---|
| 744 | StringAppendS("\t"); |
---|
| 745 | #ifdef HAVE_FACTORY |
---|
[81845eb] | 746 | StringAppend("factory(%s)", factoryVersion); |
---|
[5348866] | 747 | #ifdef HAVE_LIBFAC |
---|
| 748 | // libfac: |
---|
[81845eb] | 749 | // extern const char * libfac_version; |
---|
| 750 | // extern const char * libfac_date; |
---|
| 751 | StringAppend("+libfac"); |
---|
[5348866] | 752 | #endif // #ifdef HAVE_LIBFAC |
---|
[81845eb] | 753 | StringAppend(","); |
---|
[8d38c87] | 754 | #endif |
---|
[5348866] | 755 | |
---|
[8d38c87] | 756 | #if defined (__GNU_MP_VERSION) && defined (__GNU_MP_VERSION_MINOR) |
---|
| 757 | StringAppend("GMP(%d.%d),",__GNU_MP_VERSION,__GNU_MP_VERSION_MINOR); |
---|
| 758 | #else |
---|
| 759 | StringAppendS("GMP(1.3),"); |
---|
| 760 | #endif |
---|
| 761 | #ifdef HAVE_NTL |
---|
[599326] | 762 | #include <NTL/version.h> |
---|
[8d38c87] | 763 | StringAppend("NTL(%s),",NTL_VERSION); |
---|
| 764 | #endif |
---|
| 765 | #ifdef HAVE_MPSR |
---|
| 766 | StringAppend("MP(%s),",MP_VERSION); |
---|
| 767 | #endif |
---|
| 768 | #if SIZEOF_VOIDP == 8 |
---|
| 769 | StringAppendS("64bit,"); |
---|
| 770 | #else |
---|
| 771 | StringAppendS("32bit,"); |
---|
| 772 | #endif |
---|
| 773 | #if defined(HAVE_DYN_RL) |
---|
| 774 | if (fe_fgets_stdin==fe_fgets_dummy) |
---|
| 775 | StringAppendS("no input,"); |
---|
| 776 | else if (fe_fgets_stdin==fe_fgets) |
---|
| 777 | StringAppendS("fgets,"); |
---|
| 778 | if (fe_fgets_stdin==fe_fgets_stdin_drl) |
---|
| 779 | StringAppendS("dynamic readline,"); |
---|
| 780 | #ifdef HAVE_FEREAD |
---|
| 781 | else if (fe_fgets_stdin==fe_fgets_stdin_emu) |
---|
| 782 | StringAppendS("emulated readline,"); |
---|
| 783 | #endif |
---|
| 784 | else |
---|
| 785 | StringAppendS("unknown fgets method,"); |
---|
| 786 | #else |
---|
| 787 | #if defined(HAVE_READLINE) && !defined(FEREAD) |
---|
| 788 | StringAppendS("static readline,"); |
---|
| 789 | #else |
---|
| 790 | #ifdef HAVE_FEREAD |
---|
| 791 | StringAppendS("emulated readline,"); |
---|
| 792 | #else |
---|
| 793 | StringAppendS("fgets,"); |
---|
| 794 | #endif |
---|
| 795 | #endif |
---|
| 796 | #endif |
---|
| 797 | #ifdef HAVE_PLURAL |
---|
| 798 | StringAppendS("Plural,"); |
---|
| 799 | #endif |
---|
| 800 | #ifdef HAVE_DBM |
---|
| 801 | StringAppendS("DBM,\n\t"); |
---|
| 802 | #else |
---|
| 803 | StringAppendS("\n\t"); |
---|
| 804 | #endif |
---|
| 805 | #ifdef HAVE_DYNAMIC_LOADING |
---|
| 806 | StringAppendS("dynamic modules,"); |
---|
| 807 | #endif |
---|
| 808 | if (p_procs_dynamic) StringAppendS("dynamic p_Procs,"); |
---|
| 809 | #ifdef TEST |
---|
| 810 | StringAppendS("TESTs,"); |
---|
| 811 | #endif |
---|
| 812 | #if YYDEBUG |
---|
| 813 | StringAppendS("YYDEBUG=1,"); |
---|
| 814 | #endif |
---|
| 815 | #ifdef HAVE_ASSUME |
---|
| 816 | StringAppendS("ASSUME,"); |
---|
| 817 | #endif |
---|
| 818 | #ifdef MDEBUG |
---|
| 819 | StringAppend("MDEBUG=%d,",MDEBUG); |
---|
| 820 | #endif |
---|
| 821 | #ifdef OM_CHECK |
---|
| 822 | StringAppend("OM_CHECK=%d,",OM_CHECK); |
---|
| 823 | #endif |
---|
| 824 | #ifdef OM_TRACK |
---|
| 825 | StringAppend("OM_TRACK=%d,",OM_TRACK); |
---|
| 826 | #endif |
---|
| 827 | #ifdef OM_NDEBUG |
---|
| 828 | StringAppendS("OM_NDEBUG,"); |
---|
| 829 | #endif |
---|
| 830 | #ifdef PDEBUG |
---|
| 831 | StringAppendS("PDEBUG,"); |
---|
| 832 | #endif |
---|
| 833 | #ifdef KDEBUG |
---|
| 834 | StringAppendS("KDEBUG,"); |
---|
| 835 | #endif |
---|
| 836 | #ifndef __OPTIMIZE__ |
---|
| 837 | StringAppendS("-g,"); |
---|
| 838 | #endif |
---|
| 839 | #ifdef HAVE_EIGENVAL |
---|
| 840 | StringAppendS("eigenvalues,"); |
---|
| 841 | #endif |
---|
| 842 | #ifdef HAVE_GMS |
---|
| 843 | StringAppendS("Gauss-Manin system,"); |
---|
| 844 | #endif |
---|
| 845 | #ifdef HAVE_RATGRING |
---|
| 846 | StringAppendS("ratGB,"); |
---|
| 847 | #endif |
---|
| 848 | StringAppend("random=%d\n",siRandomStart); |
---|
[4a48c4] | 849 | StringAppend("\tCC=%s,\n\tCXX=%s" |
---|
[8d38c87] | 850 | #ifdef __GNUC__ |
---|
[4a48c4] | 851 | "(" __VERSION__ ")" |
---|
[8d38c87] | 852 | #endif |
---|
[4a48c4] | 853 | "\n",CC,CXX); |
---|
[8d38c87] | 854 | feStringAppendResources(0); |
---|
| 855 | feStringAppendBrowsers(0); |
---|
| 856 | StringAppendS("\n"); |
---|
| 857 | return str; |
---|
| 858 | } |
---|
| 859 | |
---|
| 860 | #ifdef PDEBUG |
---|
| 861 | #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM) |
---|
| 862 | void p_SetRingOfLeftv(leftv l, ring r) |
---|
| 863 | { |
---|
| 864 | switch(l->rtyp) |
---|
| 865 | { |
---|
| 866 | case INT_CMD: |
---|
| 867 | case BIGINT_CMD: |
---|
| 868 | case IDHDL: |
---|
| 869 | case DEF_CMD: |
---|
| 870 | break; |
---|
| 871 | case POLY_CMD: |
---|
| 872 | case VECTOR_CMD: |
---|
| 873 | { |
---|
| 874 | poly p=(poly)l->data; |
---|
| 875 | while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); } |
---|
| 876 | break; |
---|
| 877 | } |
---|
| 878 | case IDEAL_CMD: |
---|
| 879 | case MODUL_CMD: |
---|
| 880 | case MATRIX_CMD: |
---|
| 881 | { |
---|
| 882 | ideal I=(ideal)l->data; |
---|
| 883 | int i; |
---|
| 884 | for(i=IDELEMS(I)-1;i>=0;i--) |
---|
| 885 | { |
---|
| 886 | poly p=I->m[i]; |
---|
| 887 | while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); } |
---|
| 888 | } |
---|
| 889 | break; |
---|
| 890 | } |
---|
| 891 | case COMMAND: |
---|
| 892 | { |
---|
| 893 | command d=(command)l->data; |
---|
| 894 | p_SetRingOfLeftv(&d->arg1, r); |
---|
| 895 | if (d->argc>1) p_SetRingOfLeftv(&d->arg2, r); |
---|
| 896 | if (d->argc>2) p_SetRingOfLeftv(&d->arg3, r); |
---|
| 897 | break; |
---|
| 898 | } |
---|
| 899 | default: |
---|
| 900 | printf("type %d not yet implementd in p_SetRingOfLeftv\n",l->rtyp); |
---|
| 901 | break; |
---|
| 902 | } |
---|
| 903 | } |
---|
| 904 | #endif |
---|
| 905 | #endif |
---|
| 906 | |
---|
[aefd2f] | 907 | #if 0 /* debug only */ |
---|
[8d38c87] | 908 | void listall(int showproc) |
---|
| 909 | { |
---|
| 910 | idhdl hh=basePack->idroot; |
---|
| 911 | PrintS("====== Top ==============\n"); |
---|
| 912 | while (hh!=NULL) |
---|
| 913 | { |
---|
| 914 | if (showproc || (IDTYP(hh)!=PROC_CMD)) |
---|
| 915 | { |
---|
| 916 | if (IDDATA(hh)==(void *)currRing) PrintS("(R)"); |
---|
| 917 | else if (IDDATA(hh)==(void *)currPack) PrintS("(P)"); |
---|
| 918 | else PrintS(" "); |
---|
| 919 | Print("::%s, typ %s level %d data %lx", |
---|
| 920 | IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh)); |
---|
| 921 | if ((IDTYP(hh)==RING_CMD) |
---|
| 922 | || (IDTYP(hh)==QRING_CMD)) |
---|
| 923 | Print(" ref: %d\n",IDRING(hh)->ref); |
---|
| 924 | else |
---|
| 925 | PrintLn(); |
---|
| 926 | } |
---|
| 927 | hh=IDNEXT(hh); |
---|
| 928 | } |
---|
| 929 | hh=basePack->idroot; |
---|
| 930 | while (hh!=NULL) |
---|
| 931 | { |
---|
| 932 | if (IDDATA(hh)==(void *)basePack) |
---|
| 933 | Print("(T)::%s, typ %s level %d data %lx\n", |
---|
| 934 | IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh)); |
---|
| 935 | else |
---|
| 936 | if ((IDTYP(hh)==RING_CMD) |
---|
| 937 | || (IDTYP(hh)==QRING_CMD) |
---|
| 938 | || (IDTYP(hh)==PACKAGE_CMD)) |
---|
| 939 | { |
---|
| 940 | Print("====== %s ==============\n",IDID(hh)); |
---|
| 941 | idhdl h2=IDRING(hh)->idroot; |
---|
| 942 | while (h2!=NULL) |
---|
| 943 | { |
---|
| 944 | if (showproc || (IDTYP(h2)!=PROC_CMD)) |
---|
| 945 | { |
---|
| 946 | if ((IDDATA(h2)==(void *)currRing) |
---|
| 947 | && ((IDTYP(h2)==RING_CMD)||(IDTYP(h2)==QRING_CMD))) |
---|
| 948 | PrintS("(R)"); |
---|
| 949 | else if (IDDATA(h2)==(void *)currPack) PrintS("(P)"); |
---|
| 950 | else PrintS(" "); |
---|
| 951 | Print("%s::%s, typ %s level %d data %lx\n", |
---|
| 952 | IDID(hh),IDID(h2),Tok2Cmdname(IDTYP(h2)),IDLEV(h2),(long)IDDATA(h2)); |
---|
| 953 | } |
---|
| 954 | h2=IDNEXT(h2); |
---|
| 955 | } |
---|
| 956 | } |
---|
| 957 | hh=IDNEXT(hh); |
---|
| 958 | } |
---|
| 959 | Print("currRing:%lx, currPack:%lx,basePack:%lx\n",(long)currRing,(long)currPack,(long)basePack); |
---|
| 960 | iiCheckPack(currPack); |
---|
| 961 | } |
---|
[8b2ef5] | 962 | #endif |
---|
[aefd2f] | 963 | |
---|
[8b2ef5] | 964 | #ifndef NDEBUG |
---|
[8d38c87] | 965 | void checkall() |
---|
| 966 | { |
---|
| 967 | idhdl hh=basePack->idroot; |
---|
| 968 | while (hh!=NULL) |
---|
| 969 | { |
---|
| 970 | omCheckAddr(hh); |
---|
| 971 | omCheckAddr((ADDRESS)IDID(hh)); |
---|
| 972 | if (RingDependend(IDTYP(hh))) Print("%s typ %d in Top\n",IDID(hh),IDTYP(hh)); |
---|
| 973 | hh=IDNEXT(hh); |
---|
| 974 | } |
---|
| 975 | hh=basePack->idroot; |
---|
| 976 | while (hh!=NULL) |
---|
| 977 | { |
---|
| 978 | if (IDTYP(hh)==PACKAGE_CMD) |
---|
| 979 | { |
---|
| 980 | idhdl h2=IDPACKAGE(hh)->idroot; |
---|
| 981 | while (h2!=NULL) |
---|
| 982 | { |
---|
| 983 | omCheckAddr(h2); |
---|
| 984 | omCheckAddr((ADDRESS)IDID(h2)); |
---|
| 985 | if (RingDependend(IDTYP(h2))) Print("%s typ %d in %s\n",IDID(h2),IDTYP(h2),IDID(hh)); |
---|
| 986 | h2=IDNEXT(h2); |
---|
| 987 | } |
---|
| 988 | } |
---|
| 989 | hh=IDNEXT(hh); |
---|
| 990 | } |
---|
| 991 | } |
---|
| 992 | #endif |
---|
| 993 | |
---|
| 994 | #include <sys/types.h> |
---|
| 995 | #include <sys/stat.h> |
---|
| 996 | #include <unistd.h> |
---|
| 997 | |
---|
| 998 | extern "C" |
---|
| 999 | int singular_fstat(int fd, struct stat *buf) |
---|
| 1000 | { |
---|
| 1001 | return fstat(fd,buf); |
---|
| 1002 | } |
---|
| 1003 | |
---|
[8de3388] | 1004 | /*2 |
---|
| 1005 | * the global exit routine of Singular |
---|
| 1006 | */ |
---|
| 1007 | #ifdef HAVE_MPSR |
---|
| 1008 | void (*MP_Exit_Env_Ptr)()=NULL; |
---|
| 1009 | #endif |
---|
| 1010 | |
---|
| 1011 | extern "C" { |
---|
| 1012 | |
---|
| 1013 | void m2_end(int i) |
---|
| 1014 | { |
---|
| 1015 | fe_reset_input_mode(); |
---|
| 1016 | #ifdef PAGE_TEST |
---|
| 1017 | mmEndStat(); |
---|
| 1018 | #endif |
---|
| 1019 | fe_reset_input_mode(); |
---|
| 1020 | idhdl h = IDROOT; |
---|
| 1021 | while(h != NULL) |
---|
| 1022 | { |
---|
| 1023 | if(IDTYP(h) == LINK_CMD) |
---|
| 1024 | { |
---|
| 1025 | idhdl hh=h->next; |
---|
| 1026 | killhdl(h, currPack); |
---|
| 1027 | h = hh; |
---|
| 1028 | } |
---|
| 1029 | else |
---|
| 1030 | { |
---|
| 1031 | h = h->next; |
---|
| 1032 | } |
---|
| 1033 | } |
---|
| 1034 | if (i<=0) |
---|
| 1035 | { |
---|
| 1036 | if (TEST_V_QUIET) |
---|
| 1037 | { |
---|
| 1038 | if (i==0) |
---|
| 1039 | printf("Auf Wiedersehen.\n"); |
---|
| 1040 | else |
---|
| 1041 | printf("\n$Bye.\n"); |
---|
| 1042 | } |
---|
| 1043 | //#ifdef sun |
---|
| 1044 | // #ifndef __svr4__ |
---|
| 1045 | // _cleanup(); |
---|
| 1046 | // _exit(0); |
---|
| 1047 | // #endif |
---|
| 1048 | //#endif |
---|
| 1049 | exit(0); |
---|
| 1050 | } |
---|
| 1051 | else |
---|
| 1052 | { |
---|
[1edbcdd] | 1053 | if(!singular_in_batchmode) |
---|
| 1054 | { |
---|
| 1055 | printf("\nhalt %d\n",i); |
---|
| 1056 | } |
---|
[8de3388] | 1057 | } |
---|
| 1058 | #ifdef HAVE_MPSR |
---|
| 1059 | if (MP_Exit_Env_Ptr!=NULL) (*MP_Exit_Env_Ptr)(); |
---|
| 1060 | #endif |
---|
| 1061 | exit(i); |
---|
| 1062 | } |
---|
| 1063 | } |
---|
[9f82971] | 1064 | |
---|
| 1065 | const char *singular_date=__DATE__ " " __TIME__; |
---|
| 1066 | |
---|
| 1067 | extern "C" |
---|
| 1068 | { |
---|
| 1069 | void omSingOutOfMemoryFunc() |
---|
| 1070 | { |
---|
| 1071 | fprintf(stderr, "\nSingular error: no more memory\n"); |
---|
| 1072 | omPrintStats(stderr); |
---|
| 1073 | m2_end(14); |
---|
| 1074 | /* should never get here */ |
---|
| 1075 | exit(1); |
---|
| 1076 | } |
---|
| 1077 | } |
---|
| 1078 | |
---|
[d3b70ae] | 1079 | /*2 |
---|
| 1080 | * initialize components of Singular |
---|
| 1081 | */ |
---|
| 1082 | void siInit(char *name) |
---|
[9f82971] | 1083 | { |
---|
[3645fc] | 1084 | #ifdef HAVE_FACTORY |
---|
[5374da] | 1085 | // factory default settings: ----------------------------------------------- |
---|
[3645fc] | 1086 | On(SW_USE_NTL); |
---|
| 1087 | On(SW_USE_NTL_GCD_0); // On -> seg11 in Old/algnorm, Old/factor... |
---|
| 1088 | On(SW_USE_NTL_GCD_P); // On -> cyle in Short/brnoeth_s: fixed |
---|
| 1089 | On(SW_USE_EZGCD); |
---|
| 1090 | On(SW_USE_CHINREM_GCD); |
---|
| 1091 | //On(SW_USE_FF_MOD_GCD); |
---|
| 1092 | On(SW_USE_EZGCD_P); |
---|
| 1093 | On(SW_USE_QGCD); |
---|
| 1094 | Off(SW_USE_NTL_SORT); // may be changed by an command line option |
---|
[5374da] | 1095 | factoryError=WerrorS; |
---|
[3645fc] | 1096 | #endif |
---|
| 1097 | |
---|
[5374da] | 1098 | // memory initialization: ----------------------------------------------- |
---|
| 1099 | om_Opts.OutOfMemoryFunc = omSingOutOfMemoryFunc; |
---|
| 1100 | #ifndef OM_NDEBUG |
---|
| 1101 | #ifndef __OPTIMIZE__ |
---|
| 1102 | om_Opts.ErrorHook = dErrorBreak; |
---|
| 1103 | #endif |
---|
| 1104 | #endif |
---|
| 1105 | omInitInfo(); |
---|
| 1106 | #ifdef OM_SING_KEEP |
---|
| 1107 | om_Opts.Keep = OM_SING_KEEP; |
---|
| 1108 | #endif |
---|
| 1109 | |
---|
| 1110 | // interpreter tables etc.: ----------------------------------------------- |
---|
[3645fc] | 1111 | #ifdef INIT_BUG |
---|
| 1112 | jjInitTab1(); |
---|
| 1113 | #endif |
---|
[5374da] | 1114 | memset(&sLastPrinted,0,sizeof(sleftv)); |
---|
| 1115 | sLastPrinted.rtyp=NONE; |
---|
[047597] | 1116 | |
---|
| 1117 | extern int iiInitArithmetic(); iiInitArithmetic(); // iparith.cc |
---|
| 1118 | |
---|
[5374da] | 1119 | basePack=(package)omAlloc0(sizeof(*basePack)); |
---|
| 1120 | currPack=basePack; |
---|
| 1121 | idhdl h; |
---|
| 1122 | h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE); |
---|
| 1123 | IDPACKAGE(h)->language = LANG_TOP; |
---|
| 1124 | IDPACKAGE(h)=basePack; |
---|
| 1125 | currPackHdl=h; |
---|
| 1126 | basePackHdl=h; |
---|
[047597] | 1127 | |
---|
| 1128 | coeffs_BIGINT = nInitChar(n_Q,NULL); |
---|
| 1129 | |
---|
| 1130 | #if 1 |
---|
| 1131 | // def HAVE_POLYEXTENSIONS |
---|
| 1132 | if(TRUE) |
---|
| 1133 | { |
---|
| 1134 | n_coeffType type = nRegister(n_algExt, naInitChar); |
---|
| 1135 | assume(type == n_algExt); |
---|
| 1136 | |
---|
| 1137 | type = nRegister(n_transExt, ntInitChar); |
---|
| 1138 | assume(type == n_transExt); |
---|
| 1139 | } |
---|
| 1140 | #endif |
---|
[5374da] | 1141 | |
---|
| 1142 | // random generator: ----------------------------------------------- |
---|
[d3b70ae] | 1143 | int t=initTimer(); |
---|
| 1144 | if (t==0) t=1; |
---|
| 1145 | initRTimer(); |
---|
| 1146 | siSeed=t; |
---|
| 1147 | #ifdef HAVE_FACTORY |
---|
| 1148 | factoryseed(t); |
---|
| 1149 | #endif |
---|
| 1150 | siRandomStart=t; |
---|
[3645fc] | 1151 | feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart); |
---|
[e3c0c1d] | 1152 | |
---|
[5374da] | 1153 | // ressource table: ---------------------------------------------------- |
---|
[3645fc] | 1154 | // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed |
---|
[9f82971] | 1155 | // hack such that all shared' libs in the bindir are loaded correctly |
---|
| 1156 | feInitResources(name); |
---|
| 1157 | |
---|
[5374da] | 1158 | // singular links: -------------------------------------------------- |
---|
[9f82971] | 1159 | slStandardInit(); |
---|
| 1160 | myynest=0; |
---|
[3645fc] | 1161 | |
---|
[5374da] | 1162 | // loading standard.lib ----------------------------------------------- |
---|
[9f82971] | 1163 | if (! feOptValue(FE_OPT_NO_STDLIB)) |
---|
| 1164 | { |
---|
| 1165 | int vv=verbose; |
---|
| 1166 | verbose &= ~Sy_bit(V_LOAD_LIB); |
---|
| 1167 | iiLibCmd(omStrDup("standard.lib"), TRUE,TRUE,TRUE); |
---|
| 1168 | verbose=vv; |
---|
| 1169 | } |
---|
| 1170 | errorreported = 0; |
---|
| 1171 | } |
---|
| 1172 | |
---|
[13a8de] | 1173 | /* |
---|
[c8c436] | 1174 | #ifdef LIBSINGULAR |
---|
| 1175 | #ifdef HAVE_FACTORY |
---|
| 1176 | // the init routines of factory need mmInit |
---|
| 1177 | int mmInit( void ) |
---|
| 1178 | { |
---|
| 1179 | return 1; |
---|
| 1180 | } |
---|
| 1181 | #endif |
---|
| 1182 | #endif |
---|
[13a8de] | 1183 | */ |
---|