2248 mpz_t t_zaehler, t_nenner;
2249 mpz_init(t_zaehler);
2252 mpz_t s_zaehler, s_nenner, temp, MwWd;
2253 mpz_init(s_zaehler);
2260 mpz_set_si(sing_int, 2147483647);
2262 mpz_t sing_int_half;
2263 mpz_init(sing_int_half);
2264 mpz_set_si(sing_int_half, 3*(1073741824/2));
2266 mpz_t deg_w0_p1, deg_d0_p1;
2267 mpz_init(deg_w0_p1);
2268 mpz_init(deg_d0_p1);
2292 for (j=0; j<nRing; j++)
2294 (*diff_weight1)[
j] = (*curr_weight)[
j];
2298 for(j=0; j<nRing; j++)
2300 (*curr_weight)[
j] = (*diff_weight1)[
j];
2302 for(j=0; j<nRing; j++)
2304 (*diff_weight1)[
j] = floor(0.1*(*diff_weight1)[j] + 0.5);
2310 for(j=0; j<nRing; j++)
2312 (*diff_weight1)[
j] = (*curr_weight)[
j];
2317 (*curr_weight)[
j] = (*diff_weight1)[
j];
2319 (*diff_weight1)[
j] = floor(0.1*(*diff_weight1)[j] + 0.5);
2324 intvec* diff_weight =
MivSub(target_weight, curr_weight);
2327 for (j=0; j<nG; j++)
2342 mpz_sub(s_zaehler, deg_w0_p1, MwWd);
2343 if(mpz_cmp(s_zaehler, t_null) != 0)
2346 mpz_sub(s_nenner, MwWd, deg_d0_p1);
2348 if( (mpz_cmp(s_zaehler,t_null) > 0 &&
2349 mpz_cmp(s_nenner, s_zaehler)>=0) ||
2350 (mpz_cmp(s_zaehler, t_null) < 0 &&
2351 mpz_cmp(s_nenner, s_zaehler)<=0))
2354 if (mpz_cmp(s_zaehler, t_null) < 0)
2356 mpz_neg(s_zaehler, s_zaehler);
2357 mpz_neg(s_nenner, s_nenner);
2361 cancel(s_zaehler, s_nenner);
2363 if(mpz_cmp(t_nenner, t_null) != 0)
2365 mpz_mul(sztn, s_zaehler, t_nenner);
2366 mpz_mul(sntz, s_nenner, t_zaehler);
2368 if(mpz_cmp(sztn,sntz) < 0)
2370 mpz_add(t_nenner, t_null, s_nenner);
2371 mpz_add(t_zaehler,t_null, s_zaehler);
2376 mpz_add(t_nenner, t_null, s_nenner);
2377 mpz_add(t_zaehler,t_null, s_zaehler);
2387 mpz_t *
vec=(mpz_t*)
omAlloc(nRing*
sizeof(mpz_t));
2392 if(mpz_cmp(t_nenner, t_null) == 0)
2395 Print(
"\n//MwalkNextWeightCC: t_nenner=0\n");
2398 diff_weight =
ivCopy(curr_weight);
2403 if(mpz_cmp_si(t_nenner, 1)==0 && mpz_cmp_si(t_zaehler,1)==0)
2406 diff_weight =
ivCopy(target_weight);
2413 gcd_tmp = (*curr_weight)[0];
2415 for (j=1; j<nRing; j++)
2417 gcd_tmp =
gcd(gcd_tmp, (*curr_weight)[j]);
2425 for (j=0; j<nRing; j++)
2427 gcd_tmp =
gcd(gcd_tmp, (*diff_weight)[j]);
2436 for (j=0; j<nRing; j++)
2438 (*curr_weight)[
j] = (*curr_weight)[
j]/gcd_tmp;
2439 (*diff_weight)[
j] = (*diff_weight)[
j]/gcd_tmp;
2443 #ifdef NEXT_VECTORS_CC 2444 Print(
"\n// gcd of the weight vectors (current and target) = %d", gcd_tmp);
2448 PrintS(
"\n// t_zaehler: "); mpz_out_str( stdout, 10, t_zaehler);
2449 PrintS(
", t_nenner: "); mpz_out_str( stdout, 10, t_nenner);
2457 for (j=0; j<nRing; j++)
2459 mpz_set_si(dcw, (*curr_weight)[j]);
2460 mpz_mul(s_nenner, t_nenner, dcw);
2462 if( (*diff_weight)[j]>0)
2464 mpz_mul_ui(s_zaehler, t_zaehler, (*diff_weight)[j]);
2468 mpz_mul_ui(s_zaehler, t_zaehler, -(*diff_weight)[j]);
2469 mpz_neg(s_zaehler, s_zaehler);
2471 mpz_add(sntz, s_nenner, s_zaehler);
2472 mpz_init_set(vec[j], sntz);
2474 #ifdef NEXT_VECTORS_CC 2475 Print(
"\n// j = %d ==> ", j);
2477 mpz_out_str( stdout, 10, t_nenner);
2478 Print(
" * %d)", (*curr_weight)[j]);
2479 Print(
" + ("); mpz_out_str( stdout, 10, t_zaehler);
2480 Print(
" * %d) = ", (*diff_weight)[j]);
2481 mpz_out_str( stdout, 10, s_nenner);
2483 mpz_out_str( stdout, 10, s_zaehler);
2484 PrintS(
" = "); mpz_out_str( stdout, 10, sntz);
2485 Print(
" ==> vector[%d]: ", j); mpz_out_str(stdout, 10, vec[j]);
2494 if(mpz_cmp_si(ggt,1) != 0)
2496 mpz_gcd(ggt, ggt, sntz);
2501 if(mpz_cmp_si(ggt,1) != 0)
2503 for (j=0; j<nRing; j++)
2505 mpz_divexact(vec[j], vec[j], ggt);
2508 #ifdef NEXT_VECTORS_CC 2509 PrintS(
"\n// gcd of elements of the vector: ");
2510 mpz_out_str( stdout, 10, ggt);
2513 for (j=0; j<nRing; j++)
2515 (*diff_weight)[
j] = mpz_get_si(vec[j]);
2520 for (j=0; j<nRing; j++)
2522 if(mpz_cmp(vec[j], sing_int)>=0)
2527 PrintS(
"\n// ** OVERFLOW in \"MwalkNextWeightCC\": ");
2528 mpz_out_str( stdout, 10, vec[j]);
2529 PrintS(
" is greater than 2147483647 (max. integer representation)\n");
2536 delete diff_weight1;
2537 mpz_clear(t_zaehler);
2538 mpz_clear(t_nenner);
2539 mpz_clear(s_zaehler);
2540 mpz_clear(s_nenner);
2545 mpz_clear(deg_w0_p1);
2546 mpz_clear(deg_d0_p1);
2549 mpz_clear(sing_int_half);
2550 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)
static long MivDotProduct(intvec *a, intvec *b)
static int MivAbsMaxArg(intvec *vec)
static void cancel(mpz_t zaehler, mpz_t nenner)
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)