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