2250 mpz_t t_zaehler, t_nenner;
2251 mpz_init(t_zaehler);
2254 mpz_t s_zaehler, s_nenner, temp, MwWd;
2255 mpz_init(s_zaehler);
2262 mpz_set_si(sing_int, 2147483647);
2264 mpz_t sing_int_half;
2265 mpz_init(sing_int_half);
2266 mpz_set_si(sing_int_half, 3*(1073741824/2));
2268 mpz_t deg_w0_p1, deg_d0_p1;
2269 mpz_init(deg_w0_p1);
2270 mpz_init(deg_d0_p1);
2294 for (j=0; j<nRing; j++)
2296 (*diff_weight1)[
j] = (*curr_weight)[
j];
2300 for(j=0; j<nRing; j++)
2302 (*curr_weight)[
j] = (*diff_weight1)[
j];
2304 for(j=0; j<nRing; j++)
2306 (*diff_weight1)[
j] = floor(0.1*(*diff_weight1)[j] + 0.5);
2312 for(j=0; j<nRing; j++)
2314 (*diff_weight1)[
j] = (*curr_weight)[
j];
2319 (*curr_weight)[
j] = (*diff_weight1)[
j];
2321 (*diff_weight1)[
j] = floor(0.1*(*diff_weight1)[j] + 0.5);
2326 intvec* diff_weight =
MivSub(target_weight, curr_weight);
2329 for (j=0; j<nG; j++)
2344 mpz_sub(s_zaehler, deg_w0_p1, MwWd);
2345 if(mpz_cmp(s_zaehler, t_null) != 0)
2348 mpz_sub(s_nenner, MwWd, deg_d0_p1);
2350 if( (mpz_cmp(s_zaehler,t_null) > 0 &&
2351 mpz_cmp(s_nenner, s_zaehler)>=0) ||
2352 (mpz_cmp(s_zaehler, t_null) < 0 &&
2353 mpz_cmp(s_nenner, s_zaehler)<=0))
2356 if (mpz_cmp(s_zaehler, t_null) < 0)
2358 mpz_neg(s_zaehler, s_zaehler);
2359 mpz_neg(s_nenner, s_nenner);
2363 cancel(s_zaehler, s_nenner);
2365 if(mpz_cmp(t_nenner, t_null) != 0)
2367 mpz_mul(sztn, s_zaehler, t_nenner);
2368 mpz_mul(sntz, s_nenner, t_zaehler);
2370 if(mpz_cmp(sztn,sntz) < 0)
2372 mpz_add(t_nenner, t_null, s_nenner);
2373 mpz_add(t_zaehler,t_null, s_zaehler);
2378 mpz_add(t_nenner, t_null, s_nenner);
2379 mpz_add(t_zaehler,t_null, s_zaehler);
2389 mpz_t *
vec=(mpz_t*)
omAlloc(nRing*
sizeof(mpz_t));
2394 if(mpz_cmp(t_nenner, t_null) == 0)
2397 Print(
"\n//MwalkNextWeightCC: t_nenner=0\n");
2400 diff_weight =
ivCopy(curr_weight);
2405 if(mpz_cmp_si(t_nenner, 1)==0 && mpz_cmp_si(t_zaehler,1)==0)
2408 diff_weight =
ivCopy(target_weight);
2415 gcd_tmp = (*curr_weight)[0];
2417 for (j=1; j<nRing; j++)
2419 gcd_tmp =
gcd(gcd_tmp, (*curr_weight)[j]);
2427 for (j=0; j<nRing; j++)
2429 gcd_tmp =
gcd(gcd_tmp, (*diff_weight)[j]);
2438 for (j=0; j<nRing; j++)
2440 (*curr_weight)[
j] = (*curr_weight)[
j]/gcd_tmp;
2441 (*diff_weight)[
j] = (*diff_weight)[
j]/gcd_tmp;
2445 #ifdef NEXT_VECTORS_CC 2446 Print(
"\n// gcd of the weight vectors (current and target) = %d", gcd_tmp);
2450 PrintS(
"\n// t_zaehler: "); mpz_out_str( stdout, 10, t_zaehler);
2451 PrintS(
", t_nenner: "); mpz_out_str( stdout, 10, t_nenner);
2459 for (j=0; j<nRing; j++)
2461 mpz_set_si(dcw, (*curr_weight)[j]);
2462 mpz_mul(s_nenner, t_nenner, dcw);
2464 if( (*diff_weight)[j]>0)
2466 mpz_mul_ui(s_zaehler, t_zaehler, (*diff_weight)[j]);
2470 mpz_mul_ui(s_zaehler, t_zaehler, -(*diff_weight)[j]);
2471 mpz_neg(s_zaehler, s_zaehler);
2473 mpz_add(sntz, s_nenner, s_zaehler);
2474 mpz_init_set(vec[j], sntz);
2476 #ifdef NEXT_VECTORS_CC 2477 Print(
"\n// j = %d ==> ", j);
2479 mpz_out_str( stdout, 10, t_nenner);
2480 Print(
" * %d)", (*curr_weight)[j]);
2481 Print(
" + ("); mpz_out_str( stdout, 10, t_zaehler);
2482 Print(
" * %d) = ", (*diff_weight)[j]);
2483 mpz_out_str( stdout, 10, s_nenner);
2485 mpz_out_str( stdout, 10, s_zaehler);
2486 PrintS(
" = "); mpz_out_str( stdout, 10, sntz);
2487 Print(
" ==> vector[%d]: ", j); mpz_out_str(stdout, 10, vec[j]);
2496 if(mpz_cmp_si(ggt,1) != 0)
2498 mpz_gcd(ggt, ggt, sntz);
2503 if(mpz_cmp_si(ggt,1) != 0)
2505 for (j=0; j<nRing; j++)
2507 mpz_divexact(vec[j], vec[j], ggt);
2510 #ifdef NEXT_VECTORS_CC 2511 PrintS(
"\n// gcd of elements of the vector: ");
2512 mpz_out_str( stdout, 10, ggt);
2515 for (j=0; j<nRing; j++)
2517 (*diff_weight)[
j] = mpz_get_si(vec[j]);
2522 for (j=0; j<nRing; j++)
2524 if(mpz_cmp(vec[j], sing_int)>=0)
2529 PrintS(
"\n// ** OVERFLOW in \"MwalkNextWeightCC\": ");
2530 mpz_out_str( stdout, 10, vec[j]);
2531 PrintS(
" is greater than 2147483647 (max. integer representation)\n");
2538 delete diff_weight1;
2539 mpz_clear(t_zaehler);
2540 mpz_clear(t_nenner);
2541 mpz_clear(s_zaehler);
2542 mpz_clear(s_nenner);
2547 mpz_clear(deg_w0_p1);
2548 mpz_clear(deg_d0_p1);
2551 mpz_clear(sing_int_half);
2552 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)