2249 mpz_t t_zaehler, t_nenner;
2250 mpz_init(t_zaehler);
2253 mpz_t s_zaehler, s_nenner, temp, MwWd;
2254 mpz_init(s_zaehler);
2261 mpz_set_si(sing_int, 2147483647);
2263 mpz_t sing_int_half;
2264 mpz_init(sing_int_half);
2265 mpz_set_si(sing_int_half, 3*(1073741824/2));
2267 mpz_t deg_w0_p1, deg_d0_p1;
2268 mpz_init(deg_w0_p1);
2269 mpz_init(deg_d0_p1);
2293 for (j=0; j<nRing; j++)
2295 (*diff_weight1)[
j] = (*curr_weight)[
j];
2299 for(j=0; j<nRing; j++)
2301 (*curr_weight)[
j] = (*diff_weight1)[
j];
2303 for(j=0; j<nRing; j++)
2305 (*diff_weight1)[
j] = floor(0.1*(*diff_weight1)[j] + 0.5);
2311 for(j=0; j<nRing; j++)
2313 (*diff_weight1)[
j] = (*curr_weight)[
j];
2318 (*curr_weight)[
j] = (*diff_weight1)[
j];
2320 (*diff_weight1)[
j] = floor(0.1*(*diff_weight1)[j] + 0.5);
2325 intvec* diff_weight =
MivSub(target_weight, curr_weight);
2328 for (j=0; j<nG; j++)
2343 mpz_sub(s_zaehler, deg_w0_p1, MwWd);
2344 if(mpz_cmp(s_zaehler, t_null) != 0)
2347 mpz_sub(s_nenner, MwWd, deg_d0_p1);
2349 if( (mpz_cmp(s_zaehler,t_null) > 0 &&
2350 mpz_cmp(s_nenner, s_zaehler)>=0) ||
2351 (mpz_cmp(s_zaehler, t_null) < 0 &&
2352 mpz_cmp(s_nenner, s_zaehler)<=0))
2355 if (mpz_cmp(s_zaehler, t_null) < 0)
2357 mpz_neg(s_zaehler, s_zaehler);
2358 mpz_neg(s_nenner, s_nenner);
2362 cancel(s_zaehler, s_nenner);
2364 if(mpz_cmp(t_nenner, t_null) != 0)
2366 mpz_mul(sztn, s_zaehler, t_nenner);
2367 mpz_mul(sntz, s_nenner, t_zaehler);
2369 if(mpz_cmp(sztn,sntz) < 0)
2371 mpz_add(t_nenner, t_null, s_nenner);
2372 mpz_add(t_zaehler,t_null, s_zaehler);
2377 mpz_add(t_nenner, t_null, s_nenner);
2378 mpz_add(t_zaehler,t_null, s_zaehler);
2388 mpz_t *
vec=(mpz_t*)
omAlloc(nRing*
sizeof(mpz_t));
2393 if(mpz_cmp(t_nenner, t_null) == 0)
2396 PrintS(
"\n//MwalkNextWeightCC: t_nenner=0\n");
2399 diff_weight =
ivCopy(curr_weight);
2404 if(mpz_cmp_si(t_nenner, 1)==0 && mpz_cmp_si(t_zaehler,1)==0)
2407 diff_weight =
ivCopy(target_weight);
2414 gcd_tmp = (*curr_weight)[0];
2416 for (j=1; j<nRing; j++)
2418 gcd_tmp =
gcd(gcd_tmp, (*curr_weight)[j]);
2426 for (j=0; j<nRing; j++)
2428 gcd_tmp =
gcd(gcd_tmp, (*diff_weight)[j]);
2437 for (j=0; j<nRing; j++)
2439 (*curr_weight)[
j] = (*curr_weight)[
j]/gcd_tmp;
2440 (*diff_weight)[
j] = (*diff_weight)[
j]/gcd_tmp;
2444 #ifdef NEXT_VECTORS_CC 2445 Print(
"\n// gcd of the weight vectors (current and target) = %d", gcd_tmp);
2449 PrintS(
"\n// t_zaehler: "); mpz_out_str( stdout, 10, t_zaehler);
2450 PrintS(
", t_nenner: "); mpz_out_str( stdout, 10, t_nenner);
2458 for (j=0; j<nRing; j++)
2460 mpz_set_si(dcw, (*curr_weight)[j]);
2461 mpz_mul(s_nenner, t_nenner, dcw);
2463 if( (*diff_weight)[j]>0)
2465 mpz_mul_ui(s_zaehler, t_zaehler, (*diff_weight)[j]);
2469 mpz_mul_ui(s_zaehler, t_zaehler, -(*diff_weight)[j]);
2470 mpz_neg(s_zaehler, s_zaehler);
2472 mpz_add(sntz, s_nenner, s_zaehler);
2473 mpz_init_set(vec[j], sntz);
2475 #ifdef NEXT_VECTORS_CC 2476 Print(
"\n// j = %d ==> ", j);
2478 mpz_out_str( stdout, 10, t_nenner);
2479 Print(
" * %d)", (*curr_weight)[j]);
2480 PrintS(
" + ("); mpz_out_str( stdout, 10, t_zaehler);
2481 Print(
" * %d) = ", (*diff_weight)[j]);
2482 mpz_out_str( stdout, 10, s_nenner);
2484 mpz_out_str( stdout, 10, s_zaehler);
2485 PrintS(
" = "); mpz_out_str( stdout, 10, sntz);
2486 Print(
" ==> vector[%d]: ", j); mpz_out_str(stdout, 10, vec[j]);
2495 if(mpz_cmp_si(ggt,1) != 0)
2497 mpz_gcd(ggt, ggt, sntz);
2502 if(mpz_cmp_si(ggt,1) != 0)
2504 for (j=0; j<nRing; j++)
2506 mpz_divexact(vec[j], vec[j], ggt);
2509 #ifdef NEXT_VECTORS_CC 2510 PrintS(
"\n// gcd of elements of the vector: ");
2511 mpz_out_str( stdout, 10, ggt);
2514 for (j=0; j<nRing; j++)
2516 (*diff_weight)[
j] = mpz_get_si(vec[j]);
2521 for (j=0; j<nRing; j++)
2523 if(mpz_cmp(vec[j], sing_int)>=0)
2528 PrintS(
"\n// ** OVERFLOW in \"MwalkNextWeightCC\": ");
2529 mpz_out_str( stdout, 10, vec[j]);
2530 PrintS(
" is greater than 2147483647 (max. integer representation)\n");
2537 delete diff_weight1;
2538 mpz_clear(t_zaehler);
2539 mpz_clear(t_nenner);
2540 mpz_clear(s_zaehler);
2541 mpz_clear(s_nenner);
2546 mpz_clear(deg_w0_p1);
2547 mpz_clear(deg_d0_p1);
2550 mpz_clear(sing_int_half);
2551 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)