2230{
2233
2236
2240
2241 mpz_t t_zaehler, t_nenner;
2242 mpz_init(t_zaehler);
2243 mpz_init(t_nenner);
2244
2245 mpz_t s_zaehler, s_nenner, temp, MwWd;
2246 mpz_init(s_zaehler);
2247 mpz_init(s_nenner);
2248 mpz_init(temp);
2249 mpz_init(MwWd);
2250
2251 mpz_t sing_int;
2252 mpz_init(sing_int);
2253 mpz_set_ui(sing_int, 2147483647);
2254
2255 mpz_t sing_int_half;
2256 mpz_init(sing_int_half);
2257 mpz_set_ui(sing_int_half, 3*(1073741824/2));
2258
2259 mpz_t deg_w0_p1, deg_d0_p1;
2260 mpz_init(deg_w0_p1);
2261 mpz_init(deg_d0_p1);
2262
2263 mpz_t sztn, sntz;
2264 mpz_init(sztn);
2265 mpz_init(sntz);
2266
2267 mpz_t t_null;
2268 mpz_init(t_null);
2269
2270 mpz_t ggt;
2271 mpz_init(ggt);
2272
2273 mpz_t dcw;
2274 mpz_init(dcw);
2275
2276 int gcd_tmp;
2277
2278
2281
2282
2284 {
2285 for (
j=0;
j<nRing;
j++)
2286 {
2287 (*diff_weight1)[
j] = (*curr_weight)[
j];
2288 }
2290 {
2291 for(
j=0;
j<nRing;
j++)
2292 {
2293 (*curr_weight)[
j] = (*diff_weight1)[
j];
2294 }
2295 for(
j=0;
j<nRing;
j++)
2296 {
2297 (*diff_weight1)[
j] = ((*diff_weight1)[
j] + 5) / 10;
2298 }
2299 }
2300
2302 {
2303 for(
j=0;
j<nRing;
j++)
2304 {
2305 (*diff_weight1)[
j] = (*curr_weight)[
j];
2306 }
2309 {
2310 (*curr_weight)[
j] = (*diff_weight1)[
j];
2312 (*diff_weight1)[
j] = ((*diff_weight1)[
j] + 5) / 10;
2313 }
2314 }
2315
2316 }
2317 intvec* diff_weight =
MivSub(target_weight, curr_weight);
2318
2319
2320 for (
j=0;
j<nG;
j++)
2321 {
2324 {
2328 delete ivtemp;
2329
2332 {
2335 mpz_sub(s_zaehler, deg_w0_p1, MwWd);
2336 if(mpz_cmp(s_zaehler, t_null) != 0)
2337 {
2339 mpz_sub(s_nenner, MwWd, deg_d0_p1);
2340
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))
2345 {
2346
2347 if (mpz_cmp(s_zaehler, t_null) < 0)
2348 {
2349 mpz_neg(s_zaehler, s_zaehler);
2350 mpz_neg(s_nenner, s_nenner);
2351 }
2352
2353
2354 cancel(s_zaehler, s_nenner);
2355
2356 if(mpz_cmp(t_nenner, t_null) != 0)
2357 {
2358 mpz_mul(sztn, s_zaehler, t_nenner);
2359 mpz_mul(sntz, s_nenner, t_zaehler);
2360
2361 if(mpz_cmp(sztn,sntz) < 0)
2362 {
2363 mpz_add(t_nenner, t_null, s_nenner);
2364 mpz_add(t_zaehler,t_null, s_zaehler);
2365 }
2366 }
2367 else
2368 {
2369 mpz_add(t_nenner, t_null, s_nenner);
2370 mpz_add(t_zaehler,t_null, s_zaehler);
2371 }
2372 }
2373 }
2375 delete ivtemp;
2376 }
2377 }
2378 }
2379
2380 mpz_t *
vec=(mpz_t*)
omAlloc(nRing*
sizeof(mpz_t));
2381
2382
2383
2384
2385 if(mpz_cmp(t_nenner, t_null) == 0)
2386 {
2387#ifndef SING_NDEBUG
2388 PrintS(
"\n//MwalkNextWeightCC: t_nenner=0\n");
2389#endif
2390 delete diff_weight;
2391 diff_weight =
ivCopy(curr_weight);
2392 goto FINISH;
2393 }
2394
2395
2396 if(mpz_cmp_si(t_nenner, 1)==0 && mpz_cmp_si(t_zaehler,1)==0)
2397 {
2398 delete diff_weight;
2399 diff_weight =
ivCopy(target_weight);
2400 goto FINISH;
2401 }
2402
2403
2404
2405
2406 gcd_tmp = (*curr_weight)[0];
2407
2408 for (
j=1;
j<nRing;
j++)
2409 {
2410 gcd_tmp =
gcd(gcd_tmp, (*curr_weight)[
j]);
2411 if(gcd_tmp == 1)
2412 {
2413 break;
2414 }
2415 }
2416 if(gcd_tmp != 1)
2417 {
2418 for (
j=0;
j<nRing;
j++)
2419 {
2420 gcd_tmp =
gcd(gcd_tmp, (*diff_weight)[
j]);
2421 if(gcd_tmp == 1)
2422 {
2423 break;
2424 }
2425 }
2426 }
2427 if(gcd_tmp != 1)
2428 {
2429 for (
j=0;
j<nRing;
j++)
2430 {
2431 (*curr_weight)[
j] = (*curr_weight)[
j]/gcd_tmp;
2432 (*diff_weight)[
j] = (*diff_weight)[
j]/gcd_tmp;
2433 }
2434 }
2435
2436#ifdef NEXT_VECTORS_CC
2437 Print(
"\n// gcd of the weight vectors (current and target) = %d", gcd_tmp);
2440
2441 PrintS(
"\n// t_zaehler: "); mpz_out_str( stdout, 10, t_zaehler);
2442 PrintS(
", t_nenner: "); mpz_out_str( stdout, 10, t_nenner);
2443#endif
2444
2445
2446
2447
2448
2449
2450 for (
j=0;
j<nRing;
j++)
2451 {
2452 mpz_set_si(dcw, (*curr_weight)[
j]);
2453 mpz_mul(s_nenner, t_nenner, dcw);
2454
2455 if( (*diff_weight)[
j]>0)
2456 {
2457 mpz_mul_ui(s_zaehler, t_zaehler, (*diff_weight)[
j]);
2458 }
2459 else
2460 {
2461 mpz_mul_ui(s_zaehler, t_zaehler, -(*diff_weight)[
j]);
2462 mpz_neg(s_zaehler, s_zaehler);
2463 }
2464 mpz_add(sntz, s_nenner, s_zaehler);
2465 mpz_init_set(
vec[
j], sntz);
2466
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]);
2479#endif
2480
2482 {
2483 mpz_set(ggt, sntz);
2484 }
2485 else
2486 {
2487 if(mpz_cmp_si(ggt,1) != 0)
2488 {
2489 mpz_gcd(ggt, ggt, sntz);
2490 }
2491 }
2492 }
2493
2494 if(mpz_cmp_si(ggt,1) != 0)
2495 {
2496 for (
j=0;
j<nRing;
j++)
2497 {
2499 }
2500 }
2501#ifdef NEXT_VECTORS_CC
2502 PrintS(
"\n// gcd of elements of the vector: ");
2503 mpz_out_str( stdout, 10, ggt);
2504#endif
2505
2506 for (
j=0;
j<nRing;
j++)
2507 {
2508 (*diff_weight)[
j] = mpz_get_si(
vec[
j]);
2509 }
2510
2511
2512
2513 for (
j=0;
j<nRing;
j++)
2514 {
2515 if(mpz_cmp(
vec[
j], sing_int)>=0)
2516 {
2518 {
2520 PrintS(
"\n// ** OVERFLOW in \"MwalkNextWeightCC\": ");
2521 mpz_out_str( stdout, 10,
vec[
j]);
2522 PrintS(
" is greater than 2147483647 (max. integer representation)\n");
2523
2524 }
2525 }
2526 }
2527
2528 FINISH:
2529 delete diff_weight1;
2530 mpz_clear(t_zaehler);
2531 mpz_clear(t_nenner);
2532 mpz_clear(s_zaehler);
2533 mpz_clear(s_nenner);
2534 mpz_clear(sntz);
2535 mpz_clear(sztn);
2536 mpz_clear(temp);
2537 mpz_clear(MwWd);
2538 mpz_clear(deg_w0_p1);
2539 mpz_clear(deg_d0_p1);
2540 mpz_clear(ggt);
2542 mpz_clear(sing_int_half);
2543 mpz_clear(sing_int);
2544 mpz_clear(dcw);
2545 mpz_clear(t_null);
2546
2548 {
2550 }
2553 {
2556 {
2559 }
2560 }
2561return diff_weight;
2562}
intvec * ivCopy(const intvec *o)
static int MivAbsMaxArg(intvec *vec)
static void cancel(mpz_t zaehler, mpz_t nenner)
static intvec * MExpPol(poly f)
static intvec * MivSub(intvec *a, intvec *b)
static long MivDotProduct(intvec *a, intvec *b)