2241 mpz_t t_zaehler, t_nenner;
2242 mpz_init(t_zaehler);
2245 mpz_t s_zaehler, s_nenner, temp, MwWd;
2246 mpz_init(s_zaehler);
2253 mpz_set_ui(sing_int, 2147483647);
2255 mpz_t sing_int_half;
2256 mpz_init(sing_int_half);
2257 mpz_set_ui(sing_int_half, 3*(1073741824/2));
2259 mpz_t deg_w0_p1, deg_d0_p1;
2260 mpz_init(deg_w0_p1);
2261 mpz_init(deg_d0_p1);
2285 for (j=0; j<nRing; j++)
2287 (*diff_weight1)[
j] = (*curr_weight)[
j];
2291 for(j=0; j<nRing; j++)
2293 (*curr_weight)[
j] = (*diff_weight1)[
j];
2295 for(j=0; j<nRing; j++)
2297 (*diff_weight1)[
j] = ((*diff_weight1)[
j] + 5) / 10;
2303 for(j=0; j<nRing; j++)
2305 (*diff_weight1)[
j] = (*curr_weight)[
j];
2310 (*curr_weight)[
j] = (*diff_weight1)[
j];
2312 (*diff_weight1)[
j] = ((*diff_weight1)[
j] + 5) / 10;
2317 intvec* diff_weight =
MivSub(target_weight, curr_weight);
2320 for (j=0; j<nG; j++)
2335 mpz_sub(s_zaehler, deg_w0_p1, MwWd);
2336 if(mpz_cmp(s_zaehler, t_null) != 0)
2339 mpz_sub(s_nenner, MwWd, deg_d0_p1);
2341 if( (mpz_cmp(s_zaehler,t_null) > 0 &&
2342 mpz_cmp(s_nenner, s_zaehler)>=0) ||
2343 (mpz_cmp(s_zaehler, t_null) < 0 &&
2344 mpz_cmp(s_nenner, s_zaehler)<=0))
2347 if (mpz_cmp(s_zaehler, t_null) < 0)
2349 mpz_neg(s_zaehler, s_zaehler);
2350 mpz_neg(s_nenner, s_nenner);
2354 cancel(s_zaehler, s_nenner);
2356 if(mpz_cmp(t_nenner, t_null) != 0)
2358 mpz_mul(sztn, s_zaehler, t_nenner);
2359 mpz_mul(sntz, s_nenner, t_zaehler);
2361 if(mpz_cmp(sztn,sntz) < 0)
2363 mpz_add(t_nenner, t_null, s_nenner);
2364 mpz_add(t_zaehler,t_null, s_zaehler);
2369 mpz_add(t_nenner, t_null, s_nenner);
2370 mpz_add(t_zaehler,t_null, s_zaehler);
2380 mpz_t *
vec=(mpz_t*)
omAlloc(nRing*
sizeof(mpz_t));
2385 if(mpz_cmp(t_nenner, t_null) == 0)
2388 PrintS(
"\n//MwalkNextWeightCC: t_nenner=0\n");
2391 diff_weight =
ivCopy(curr_weight);
2396 if(mpz_cmp_si(t_nenner, 1)==0 && mpz_cmp_si(t_zaehler,1)==0)
2399 diff_weight =
ivCopy(target_weight);
2406 gcd_tmp = (*curr_weight)[0];
2408 for (j=1; j<nRing; j++)
2410 gcd_tmp =
gcd(gcd_tmp, (*curr_weight)[j]);
2418 for (j=0; j<nRing; j++)
2420 gcd_tmp =
gcd(gcd_tmp, (*diff_weight)[j]);
2429 for (j=0; j<nRing; j++)
2431 (*curr_weight)[
j] = (*curr_weight)[
j]/gcd_tmp;
2432 (*diff_weight)[
j] = (*diff_weight)[
j]/gcd_tmp;
2436 #ifdef NEXT_VECTORS_CC 2437 Print(
"\n// gcd of the weight vectors (current and target) = %d", gcd_tmp);
2441 PrintS(
"\n// t_zaehler: "); mpz_out_str( stdout, 10, t_zaehler);
2442 PrintS(
", t_nenner: "); mpz_out_str( stdout, 10, t_nenner);
2450 for (j=0; j<nRing; j++)
2452 mpz_set_si(dcw, (*curr_weight)[j]);
2453 mpz_mul(s_nenner, t_nenner, dcw);
2455 if( (*diff_weight)[j]>0)
2457 mpz_mul_ui(s_zaehler, t_zaehler, (*diff_weight)[j]);
2461 mpz_mul_ui(s_zaehler, t_zaehler, -(*diff_weight)[j]);
2462 mpz_neg(s_zaehler, s_zaehler);
2464 mpz_add(sntz, s_nenner, s_zaehler);
2465 mpz_init_set(vec[j], sntz);
2467 #ifdef NEXT_VECTORS_CC 2468 Print(
"\n// j = %d ==> ", j);
2470 mpz_out_str( stdout, 10, t_nenner);
2471 Print(
" * %d)", (*curr_weight)[j]);
2472 PrintS(
" + ("); mpz_out_str( stdout, 10, t_zaehler);
2473 Print(
" * %d) = ", (*diff_weight)[j]);
2474 mpz_out_str( stdout, 10, s_nenner);
2476 mpz_out_str( stdout, 10, s_zaehler);
2477 PrintS(
" = "); mpz_out_str( stdout, 10, sntz);
2478 Print(
" ==> vector[%d]: ", j); mpz_out_str(stdout, 10, vec[j]);
2487 if(mpz_cmp_si(ggt,1) != 0)
2489 mpz_gcd(ggt, ggt, sntz);
2494 if(mpz_cmp_si(ggt,1) != 0)
2496 for (j=0; j<nRing; j++)
2498 mpz_divexact(vec[j], vec[j], ggt);
2501 #ifdef NEXT_VECTORS_CC 2502 PrintS(
"\n// gcd of elements of the vector: ");
2503 mpz_out_str( stdout, 10, ggt);
2506 for (j=0; j<nRing; j++)
2508 (*diff_weight)[
j] = mpz_get_si(vec[j]);
2513 for (j=0; j<nRing; j++)
2515 if(mpz_cmp(vec[j], sing_int)>=0)
2520 PrintS(
"\n// ** OVERFLOW in \"MwalkNextWeightCC\": ");
2521 mpz_out_str( stdout, 10, vec[j]);
2522 PrintS(
" is greater than 2147483647 (max. integer representation)\n");
2529 delete diff_weight1;
2530 mpz_clear(t_zaehler);
2531 mpz_clear(t_nenner);
2532 mpz_clear(s_zaehler);
2533 mpz_clear(s_nenner);
2538 mpz_clear(deg_w0_p1);
2539 mpz_clear(deg_d0_p1);
2542 mpz_clear(sing_int_half);
2543 mpz_clear(sing_int);
static int test_w_in_ConeCC(ideal G, intvec *iv)
static int MivAbsMax(intvec *vec)
intvec * ivCopy(const intvec *o)
static intvec * MivSub(intvec *a, intvec *b)
VAR BOOLEAN Overflow_Error
static long MivDotProduct(intvec *a, intvec *b)
static int MivAbsMaxArg(intvec *vec)
static void cancel(mpz_t zaehler, mpz_t nenner)
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
BOOLEAN rComplete(ring r, int force)
this needs to be called whenever a new ring is created: new fields in ring are created (like VarOffse...
void PrintS(const char *s)
static long gcd(const long a, const long b)
static intvec * MExpPol(poly f)
static void p_Setm(poly p, const ring r)
static void ivString(intvec *iv, const char *ch)