Changeset e368746 in git
- Timestamp:
- Jun 6, 2011, 3:33:48 PM (12 years ago)
- Branches:
- (u'spielwiese', '91fdef05f09f54b8d58d92a472e9c4a43aa4656f')
- Children:
- c227a2fe328d29d1cfbd56bc8d8824aed8aa2d38
- Parents:
- 1bebbfe6863848ca47716f2e6bab1742430df913
- Location:
- factory
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/cf_gcd_smallp.cc
r1bebbf re368746 3862 3862 return !noChange; 3863 3863 int * liftBounds; 3864 noChange= false; 3864 3865 if (U.level() > 2) 3865 3866 { … … 3869 3870 liftBounds[i]= degree (shiftedU, Variable (i + 2)) + 1; 3870 3871 factors= henselLift2 (UEval, factors, liftBounds, U.level() - 1, false, 3871 shiftedLCsEval1, shiftedLCsEval2, Pi, diophant );3872 shiftedLCsEval1, shiftedLCsEval2, Pi, diophant, noChange); 3872 3873 delete [] liftBounds; 3874 if (noChange) 3875 return !noChange; 3873 3876 } 3874 3877 G[1]= factors.getFirst(); -
factory/facHensel.cc
r1bebbf re368746 1186 1186 int m= (int) ceil ((double) (degB + 1)/2.0) + 1; 1187 1187 CFList splitA= split (A, m, x); 1188 CFList splitB= split (B, m, x);1189 1188 if (splitA.length() == 3) 1190 1189 splitA.insert (0); … … 1309 1308 CanonicalForm A= mod (F, M); 1310 1309 CanonicalForm B= mod (G, M); 1310 1311 if (B.inCoeffDomain()) 1312 { 1313 divrem (A, B, Q, R); 1314 return; 1315 } 1316 if (A.inCoeffDomain() && !B.inCoeffDomain()) 1317 { 1318 Q= 0; 1319 R= A; 1320 return; 1321 } 1322 1323 if (B.level() < A.level()) 1324 { 1325 divrem (A, B, Q, R); 1326 return; 1327 } 1328 if (A.level() > B.level()) 1329 { 1330 R= A; 1331 Q= 0; 1332 return; 1333 } 1334 if (B.level() == 1 && B.isUnivariate()) 1335 { 1336 divrem (A, B, Q, R); 1337 return; 1338 } 1339 if (!(B.level() == 1 && B.isUnivariate()) && (A.level() == 1 && A.isUnivariate())) 1340 { 1341 Q= 0; 1342 R= A; 1343 return; 1344 } 1345 1311 1346 Variable x= Variable (1); 1312 1347 int degB= degree (B, x); … … 1529 1564 if (k != j - k + 1) 1530 1565 { 1531 if ( one.exp() == j - k + 1 && two.exp() == j - k + 1)1566 if ((one.hasTerms() && one.exp() == j - k + 1) && (two.hasTerms() && two.exp() == j - k + 1)) 1532 1567 { 1533 1568 tmp[0] += mulNTL ((bufFactors[0] [k] + one.coeff()), (bufFactors[1] [k] + … … 1536 1571 two++; 1537 1572 } 1538 else if (one. exp() == j - k + 1)1573 else if (one.hasTerms() && one.exp() == j - k + 1) 1539 1574 { 1540 1575 tmp[0] += mulNTL ((bufFactors[0] [k] + one.coeff()), bufFactors[1] [k]) - … … 1542 1577 one++; 1543 1578 } 1544 else if (two. exp() == j - k + 1)1579 else if (two.hasTerms() && two.exp() == j - k + 1) 1545 1580 { 1546 1581 tmp[0] += mulNTL (bufFactors[0] [k], (bufFactors[1] [k] + two.coeff())) - … … 1594 1629 one= bufFactors [l + 1]; 1595 1630 two= Pi [l - 1]; 1596 if (two. exp() == j + 1)1631 if (two.hasTerms() && two.exp() == j + 1) 1597 1632 { 1598 1633 if (degBuf > 0 && degPi > 0) … … 1613 1648 if (k != j - k + 1) 1614 1649 { 1615 if (one.exp() == j - k + 1 && two.exp() == j - k + 1) 1650 if ((one.hasTerms() && one.exp() == j - k + 1) && 1651 (two.hasTerms() && two.exp() == j - k + 1)) 1616 1652 { 1617 1653 tmp[l] += mulNTL ((bufFactors[l + 1] [k] + one.coeff()), (Pi[l - 1] [k] + … … 1620 1656 two++; 1621 1657 } 1622 else if (one. exp() == j - k + 1)1658 else if (one.hasTerms() && one.exp() == j - k + 1) 1623 1659 { 1624 1660 tmp[l] += mulNTL ((bufFactors[l + 1] [k] + one.coeff()), Pi[l - 1] [k]) - … … 1626 1662 one++; 1627 1663 } 1628 else if (two. exp() == j - k + 1)1664 else if (two.hasTerms() && two.exp() == j - k + 1) 1629 1665 { 1630 1666 tmp[l] += mulNTL (bufFactors[l + 1] [k], (Pi[l - 1] [k] + two.coeff())) - … … 1644 1680 void 1645 1681 henselLift12 (const CanonicalForm& F, CFList& factors, int l, CFArray& Pi, 1646 CFList& diophant, CFMatrix& M) 1647 { 1648 sortList (factors, Variable (1)); 1682 CFList& diophant, CFMatrix& M, bool sort) 1683 { 1684 if (sort) 1685 sortList (factors, Variable (1)); 1649 1686 Pi= CFArray (factors.length() - 1); 1650 1687 CFListIterator j= factors; … … 2018 2055 if (k != j - k + 1) 2019 2056 { 2020 if (one.exp() == j - k + 1 && two.exp() == j - k + 1) 2057 if ((one.hasTerms() && one.exp() == j - k + 1) && 2058 (two.hasTerms() && two.exp() == j - k + 1)) 2021 2059 { 2022 2060 tmp[0] += mulMod ((bufFactors[0] [k] + one.coeff()), … … 2026 2064 two++; 2027 2065 } 2028 else if (one. exp() == j - k + 1)2066 else if (one.hasTerms() && one.exp() == j - k + 1) 2029 2067 { 2030 2068 tmp[0] += mulMod ((bufFactors[0] [k] + one.coeff()), … … 2032 2070 one++; 2033 2071 } 2034 else if (two. exp() == j - k + 1)2072 else if (two.hasTerms() && two.exp() == j - k + 1) 2035 2073 { 2036 2074 tmp[0] += mulMod (bufFactors[0] [k], (bufFactors[1] [k] + … … 2084 2122 one= bufFactors [l + 1]; 2085 2123 two= Pi [l - 1]; 2086 if (two. exp() == j + 1)2124 if (two.hasTerms() && two.exp() == j + 1) 2087 2125 { 2088 2126 if (degBuf > 0 && degPi > 0) … … 2103 2141 if (k != j - k + 1) 2104 2142 { 2105 if (one.exp() == j - k + 1 && two.exp() == j - k + 1) 2143 if ((one.hasTerms() && one.exp() == j - k + 1) && 2144 (two.hasTerms() && two.exp() == j - k + 1)) 2106 2145 { 2107 2146 tmp[l] += mulMod ((bufFactors[l + 1] [k] + one.coeff()), … … 2111 2150 two++; 2112 2151 } 2113 else if (one. exp() == j - k + 1)2152 else if (one.hasTerms() && one.exp() == j - k + 1) 2114 2153 { 2115 2154 tmp[l] += mulMod ((bufFactors[l + 1] [k] + one.coeff()), … … 2117 2156 one++; 2118 2157 } 2119 else if (two. exp() == j - k + 1)2158 else if (two.hasTerms() && two.exp() == j - k + 1) 2120 2159 { 2121 2160 tmp[l] += mulMod (bufFactors[l + 1] [k], … … 2245 2284 CFList 2246 2285 henselLift (const CFList& eval, const CFList& factors, const int* l, const int 2247 lLength )2286 lLength, bool sort) 2248 2287 { 2249 2288 CFList diophant; 2250 2289 CFList buf= factors; 2251 2290 buf.insert (LC (eval.getFirst(), 1)); 2252 sortList (buf, Variable (1)); 2291 if (sort) 2292 sortList (buf, Variable (1)); 2253 2293 CFArray Pi; 2254 2294 CFMatrix M= CFMatrix (l[1], factors.length()); … … 2345 2385 for (k= 1; k <= (int) ceil (j/2.0); k++) 2346 2386 { 2347 if ( k != j - k + 1)2387 if (one.hasTerms() && two.hasTerms()) 2348 2388 { 2349 if (one.exp() == j - k + 1 && two.exp() == j - k + 1) 2389 if (k != j - k + 1) 2390 { 2391 if ((one.hasTerms() && one.exp() == j - k + 1) && + 2392 (two.hasTerms() && two.exp() == j - k + 1)) 2350 2393 { 2351 2394 tmp[0] += mulNTL ((bufFactors[0][k]+one.coeff()),(bufFactors[1][k] + … … 2354 2397 two++; 2355 2398 } 2356 else if (one. exp() == j - k + 1)2399 else if (one.hasTerms() && one.exp() == j - k + 1) 2357 2400 { 2358 2401 tmp[0] += mulNTL ((bufFactors[0][k]+one.coeff()), bufFactors[1] [k]) - … … 2360 2403 one++; 2361 2404 } 2362 else if (two. exp() == j - k + 1)2405 else if (two.hasTerms() && two.exp() == j - k + 1) 2363 2406 { 2364 2407 tmp[0] += mulNTL (bufFactors[0][k],(bufFactors[1][k] + two.coeff())) - … … 2369 2412 else 2370 2413 tmp[0] += M (k + 1, 1); 2414 } 2371 2415 } 2372 2416 } … … 2395 2439 2396 2440 Pi [0] += tmp[0]*xToJ*F.mvar(); 2397 2398 /*// update Pi [l]2399 int degPi, degBuf;2400 for (int l= 1; l < factors.length() - 1; l++)2401 {2402 degPi= degree (Pi [l - 1], x);2403 degBuf= degree (bufFactors[l + 1], x);2404 if (degPi > 0 && degBuf > 0)2405 M (j + 1, l + 1)= mulNTL (Pi [l - 1] [j], bufFactors[l + 1] [j]);2406 if (j == 1)2407 {2408 if (degPi > 0 && degBuf > 0)2409 Pi [l] += xToJ*(mulNTL (Pi [l - 1] [0] + Pi [l - 1] [j],2410 bufFactors[l + 1] [0] + buf[l + 1]) - M (j + 1, l +1) -2411 M (1, l + 1));2412 else if (degPi > 0)2413 Pi [l] += xToJ*(mulNTL (Pi [l - 1] [j], bufFactors[l + 1]));2414 else if (degBuf > 0)2415 Pi [l] += xToJ*(mulNTL (Pi [l - 1], buf[l + 1]));2416 }2417 else2418 {2419 if (degPi > 0 && degBuf > 0)2420 {2421 uIZeroJ= mulNTL (uIZeroJ, bufFactors [l + 1] [0]);2422 uIZeroJ += mulNTL (Pi [l - 1] [0], buf [l + 1]);2423 }2424 else if (degPi > 0)2425 uIZeroJ= mulNTL (uIZeroJ, bufFactors [l + 1]);2426 else if (degBuf > 0)2427 {2428 uIZeroJ= mulNTL (uIZeroJ, bufFactors [l + 1] [0]);2429 uIZeroJ += mulNTL (Pi [l - 1], buf[l + 1]);2430 }2431 Pi[l] += xToJ*uIZeroJ;2432 }2433 one= bufFactors [l + 1];2434 two= Pi [l - 1];2435 if (two.exp() == j + 1)2436 {2437 if (degBuf > 0 && degPi > 0)2438 {2439 tmp[l] += mulNTL (two.coeff(), bufFactors[l + 1][0]);2440 two++;2441 }2442 else if (degPi > 0)2443 {2444 tmp[l] += mulNTL (two.coeff(), bufFactors[l + 1]);2445 two++;2446 }2447 }2448 if (degBuf > 0 && degPi > 0)2449 {2450 for (k= 1; k <= (int) ceil (j/2.0); k++)2451 {2452 if (k != j - k + 1)2453 {2454 if (one.exp() == j - k + 1 && two.exp() == j - k + 1)2455 {2456 tmp[l] += mulNTL ((bufFactors[l + 1][k]+one.coeff()),(Pi[l-1] [k] +2457 two.coeff())) - M (k + 1, l + 1) - M (j - k + 2, l + 1);2458 one++;2459 two++;2460 }2461 else if (one.exp() == j - k + 1)2462 {2463 tmp[l] += mulNTL ((bufFactors[l+1][k]+one.coeff()),Pi[l - 1] [k]) -2464 M (k + 1, l + 1);2465 one++;2466 }2467 else if (two.exp() == j - k + 1)2468 {2469 tmp[l] += mulNTL (bufFactors[l+1][k],(Pi[l-1] [k] + two.coeff())) -2470 M (k + 1, l + 1);2471 two++;2472 }2473 }2474 else2475 tmp[l] += M (k + 1, l + 1);2476 }2477 }2478 Pi[l] += tmp[l]*xToJ*F.mvar();2479 }*/2480 2441 return; 2481 2442 } … … 2543 2504 CFList 2544 2505 diophantine (const CFList& recResult, const CFList& factors, 2545 const CFList& products, const CFList& M, const CanonicalForm& E) 2506 const CFList& products, const CFList& M, const CanonicalForm& E, 2507 bool& bad) 2546 2508 { 2547 2509 if (M.isEmpty()) … … 2574 2536 CanonicalForm bufE= mod (E, y); 2575 2537 CFList recDiophantine= diophantine (recResult, bufFactors, bufProducts, buf, 2576 bufE); 2538 bufE, bad); 2539 2540 if (bad) 2541 return CFList(); 2577 2542 2578 2543 CanonicalForm e= E; 2579 2544 CFListIterator j= products; 2580 2545 for (CFListIterator i= recDiophantine; i.hasItem(); i++, j++) 2581 e -= mulMod (i.getItem(), j.getItem(), M);2546 e -= i.getItem()*j.getItem(); 2582 2547 2583 2548 CFList result= recDiophantine; … … 2594 2559 CFListIterator k= result; 2595 2560 recDiophantine= diophantine (recResult, bufFactors, bufProducts, buf, 2596 coeffE); 2561 coeffE, bad); 2562 if (bad) 2563 return CFList(); 2597 2564 CFListIterator l= products; 2598 2565 for (j= recDiophantine; j.hasItem(); j++, k++, l++) 2599 2566 { 2600 2567 k.getItem() += j.getItem()*power (y, i); 2601 e -= mulMod (j.getItem()*power (y, i), l.getItem(), M);2568 e -= j.getItem()*power (y, i)*l.getItem(); 2602 2569 } 2603 2570 } … … 2605 2572 break; 2606 2573 } 2574 if (!e.isZero()) 2575 { 2576 bad= true; 2577 return CFList(); 2578 } 2607 2579 return result; 2608 2580 } 2609 2581 2610 // non monic case2611 static inline2612 CFList2613 multiRecDiophantine2 (const CanonicalForm& F, const CFList& factors,2614 const CFList& recResult, const CFList& M, const int d)2615 {2616 Variable y= F.mvar();2617 CFList result;2618 CFListIterator i;2619 CanonicalForm e= 1;2620 CFListIterator j= factors;2621 CFList p;2622 CFArray bufFactors= CFArray (factors.length());2623 CanonicalForm yToD= power (y, d);2624 int k= 0;2625 for (CFListIterator i= factors; i.hasItem(); i++, k++)2626 bufFactors [k]= i.getItem();2627 CanonicalForm b;2628 CFList buf= M;2629 buf.removeLast();2630 buf.append (yToD);2631 for (k= 0; k < factors.length(); k++) //TODO compute b's faster2632 {2633 b= 1;2634 if (fdivides (bufFactors[k], F))2635 b= F/bufFactors[k];2636 else2637 {2638 for (int l= 0; l < factors.length(); l++)2639 {2640 if (l == k)2641 continue;2642 else2643 {2644 b= mulMod (b, bufFactors[l], buf);2645 }2646 }2647 }2648 p.append (b);2649 }2650 j= p;2651 for (CFListIterator i= recResult; i.hasItem(); i++, j++)2652 e -= mulMod (i.getItem(), j.getItem(), M);2653 if (e.isZero())2654 return recResult;2655 CanonicalForm coeffE;2656 result= recResult;2657 CanonicalForm g;2658 buf.removeLast();2659 for (int i= 1; i < d; i++)2660 {2661 if (degree (e, y) > 0)2662 coeffE= e[i];2663 else2664 coeffE= 0;2665 if (!coeffE.isZero())2666 {2667 CFListIterator k= result;2668 CFListIterator l= p;2669 j= recResult;2670 int ii= 0;2671 CanonicalForm dummy;2672 CFList recDiophantine;2673 CFList buf2, buf3;2674 buf2= factors;2675 buf3= p;2676 for (CFListIterator iii= buf2; iii.hasItem(); iii++)2677 iii.getItem()= mod (iii.getItem(), y);2678 for (CFListIterator iii= buf3; iii.hasItem(); iii++)2679 iii.getItem()= mod (iii.getItem(), y);2680 recDiophantine= diophantine (recResult, buf2, buf3, buf, coeffE);2681 CFListIterator iter= recDiophantine;2682 for (; j.hasItem(); j++, k++, l++, ii++, iter++)2683 {2684 k.getItem() += iter.getItem()*power (y, i);2685 e -= mulMod (iter.getItem()*power (y, i), l.getItem(), M);2686 }2687 }2688 if (e.isZero())2689 break;2690 }2691 2692 #ifdef DEBUGOUTPUT2693 CanonicalForm test= 0;2694 j= p;2695 for (CFListIterator i= result; i.hasItem(); i++, j++)2696 test += mod (i.getItem()*j.getItem(), power (y, d));2697 DEBOUTLN (cerr, "test= " << test);2698 #endif2699 return result;2700 }2701 2702 // so far only tested for two! factor Hensel lifting2703 2582 static inline 2704 2583 void 2705 2584 henselStep2 (const CanonicalForm& F, const CFList& factors, CFArray& bufFactors, 2706 2585 const CFList& diophant, CFMatrix& M, CFArray& Pi, 2707 const CFList& products, int j, const CFList& MOD )2586 const CFList& products, int j, const CFList& MOD, bool& noOneToOne) 2708 2587 { 2709 2588 CanonicalForm E; … … 2735 2614 2736 2615 // actual lifting 2737 CFList diophantine2= diophantine (diophant, factors, products, MOD, E); 2616 CFList diophantine2= diophantine (diophant, factors, products, MOD, E, 2617 noOneToOne); 2618 2619 if (noOneToOne) 2620 return; 2738 2621 2739 2622 int k= 0; … … 2780 2663 if (k != j - k + 1) 2781 2664 { 2782 if (one.exp() == j - k + 1 && two.exp() == j - k + 1) 2665 if ((one.hasTerms() && one.exp() == j - k + 1) && 2666 (two.hasTerms() && two.exp() == j - k + 1)) 2783 2667 { 2784 2668 tmp[0] += mulMod ((bufFactors[0] [k] + one.coeff()), … … 2788 2672 two++; 2789 2673 } 2790 else if (one. exp() == j - k + 1)2674 else if (one.hasTerms() && one.exp() == j - k + 1) 2791 2675 { 2792 2676 tmp[0] += mulMod ((bufFactors[0] [k] + one.coeff()), … … 2794 2678 one++; 2795 2679 } 2796 else if (two. exp() == j - k + 1)2680 else if (two.hasTerms() && two.exp() == j - k + 1) 2797 2681 { 2798 2682 tmp[0] += mulMod (bufFactors[0] [k], (bufFactors[1] [k] + … … 2838 2722 degBuf= degree (bufFactors[l + 1], x); 2839 2723 if (degPi > 0 && degBuf > 0) 2724 { 2840 2725 M (j + 1, l + 1)= mulMod (Pi [l - 1] [j], bufFactors[l + 1] [j], MOD); 2841 if (j == 1) 2842 { 2843 if (degPi > 0 && degBuf > 0) 2844 Pi [l] += xToJ*(mulMod ((Pi [l - 1] [0] + Pi [l - 1] [j]), 2845 (bufFactors[l + 1] [0] + buf[l + 1]), MOD) - M (j + 1, l +1)- 2846 M (1, l + 1)); 2847 else if (degPi > 0) 2848 Pi [l] += xToJ*(mulMod (Pi [l - 1] [j], bufFactors[l + 1], MOD)); 2849 else if (degBuf > 0) 2850 Pi [l] += xToJ*(mulMod (Pi [l - 1], buf[l + 1], MOD)); 2851 } 2852 else 2853 { 2854 if (degPi > 0 && degBuf > 0) 2855 { 2856 uIZeroJ= mulMod (uIZeroJ, bufFactors [l + 1] [0], MOD); 2857 uIZeroJ += mulMod (Pi [l - 1] [0], buf [l + 1], MOD); 2858 } 2859 else if (degPi > 0) 2860 uIZeroJ= mulMod (uIZeroJ, bufFactors [l + 1], MOD); 2861 else if (degBuf > 0) 2862 { 2863 uIZeroJ= mulMod (uIZeroJ, bufFactors [l + 1] [0], MOD); 2864 uIZeroJ += mulMod (Pi [l - 1], buf[l + 1], MOD); 2865 } 2866 Pi[l] += xToJ*uIZeroJ; 2867 } 2726 if (j + 2 <= M.rows()) 2727 M (j + 2, l + 1)= mulMod (Pi [l - 1] [j + 1], bufFactors[l + 1] [j + 1], 2728 MOD); 2729 } 2730 2731 if (degPi > 0 && degBuf > 0) 2732 uIZeroJ= mulMod (Pi[l -1] [0], buf[l + 1], MOD) + 2733 mulMod (uIZeroJ, bufFactors[l+1] [0], MOD); 2734 else if (degPi > 0) 2735 uIZeroJ= mulMod (uIZeroJ, bufFactors[l + 1], MOD); 2736 else if (degBuf > 0) 2737 uIZeroJ= mulMod (Pi[l - 1], buf[1], MOD); 2738 else 2739 uIZeroJ= 0; 2740 2741 Pi [l] += xToJ*uIZeroJ; 2742 2868 2743 one= bufFactors [l + 1]; 2869 2744 two= Pi [l - 1]; 2870 if (two.exp() == j + 1)2871 {2872 if (degBuf > 0 && degPi > 0)2873 {2874 tmp[l] += mulMod (two.coeff(), bufFactors[l + 1][0], MOD);2875 two++;2876 }2877 else if (degPi > 0)2878 {2879 tmp[l] += mulMod (two.coeff(), bufFactors[l + 1], MOD);2880 two++;2881 }2882 }2883 2745 if (degBuf > 0 && degPi > 0) 2884 2746 { 2747 while (one.hasTerms() && one.exp() > j) one++; 2748 while (two.hasTerms() && two.exp() > j) two++; 2885 2749 for (k= 1; k <= (int) ceil (j/2.0); k++) 2886 2750 { 2887 2751 if (k != j - k + 1) 2888 2752 { 2889 if (one.exp() == j - k + 1 && two.exp() == j - k + 1) 2753 if ((one.hasTerms() && one.exp() == j - k + 1) && 2754 (two.hasTerms() && two.exp() == j - k + 1)) 2890 2755 { 2891 2756 tmp[l] += mulMod ((bufFactors[l + 1] [k] + one.coeff()), … … 2895 2760 two++; 2896 2761 } 2897 else if (one. exp() == j - k + 1)2762 else if (one.hasTerms() && one.exp() == j - k + 1) 2898 2763 { 2899 2764 tmp[l] += mulMod ((bufFactors[l + 1] [k] + one.coeff()), … … 2901 2766 one++; 2902 2767 } 2903 else if (two. exp() == j - k + 1)2768 else if (two.hasTerms() && two.exp() == j - k + 1) 2904 2769 { 2905 tmp[l] += mulMod (bufFactors[l + 1] [k], 2770 tmp[l] += mulMod (bufFactors[l + 1] [k], 2906 2771 (Pi[l - 1] [k] + two.coeff()), MOD) - M (k + 1, l + 1); 2907 2772 two++; 2908 }2773 } 2909 2774 } 2910 2775 else … … 2912 2777 } 2913 2778 } 2779 2780 if (degPi >= j + 1 && degBuf >= j + 1) 2781 { 2782 if (j + 2 <= M.rows()) 2783 tmp [l] += mulMod ((Pi [l - 1] [j + 1]+ Pi [l - 1] [0]), 2784 (bufFactors [l + 1] [j + 1] + bufFactors [l + 1] [0]) 2785 , MOD) - M(1,l+1) - M (j + 2,l+1); 2786 } 2787 else if (degPi >= j + 1) 2788 { 2789 if (degBuf > 0) 2790 tmp[l] += mulMod (Pi [l - 1] [j+1], bufFactors [l + 1] [0], MOD); 2791 else 2792 tmp[l] += mulMod (Pi [l - 1] [j+1], bufFactors [l + 1], MOD); 2793 } 2794 else if (degBuf >= j + 1) 2795 { 2796 if (degPi > 0) 2797 tmp[l] += mulMod (Pi [l - 1] [0], bufFactors [l + 1] [j + 1], MOD); 2798 else 2799 tmp[l] += mulMod (Pi [l - 1], bufFactors [l + 1] [j + 1], MOD); 2800 } 2801 2914 2802 Pi[l] += tmp[l]*xToJ*F.mvar(); 2915 2803 } 2916 2917 2804 return; 2918 2805 } … … 2932 2819 } 2933 2820 2934 // so far only for two factor Hensel lifting2935 2821 CFList 2936 2822 henselLift232 (const CFList& eval, const CFList& factors, int* l, CFList& 2937 2823 diophant, CFArray& Pi, CFMatrix& M, const CFList& LCs1, 2938 const CFList& LCs2 )2824 const CFList& LCs2, bool& bad) 2939 2825 { 2940 2826 CFList buf= factors; … … 2977 2863 { 2978 2864 if (degree (bufFactors[i], y) > 0) 2979 products.append ( M (1, 1)/bufFactors[i] [0]);2980 else 2981 products.append ( M (1, 1)/bufFactors[i]);2865 products.append (eval.getFirst()/bufFactors[i] [0]); 2866 else 2867 products.append (eval.getFirst()/bufFactors[i]); 2982 2868 } 2983 2869 2984 2870 for (int d= 1; d < l[1]; d++) 2985 henselStep2 (j.getItem(), buf, bufFactors, diophant, M, Pi, products, d, MOD); 2871 { 2872 henselStep2 (j.getItem(), buf, bufFactors, diophant, M, Pi, products, d, MOD, bad); 2873 if (bad) 2874 return CFList(); 2875 } 2986 2876 CFList result; 2987 2877 for (k= 0; k < factors.length(); k++) … … 2994 2884 henselLift2 (const CFList& F, const CFList& factors, const CFList& MOD, CFList& 2995 2885 diophant, CFArray& Pi, CFMatrix& M, const int lOld, int& 2996 lNew, const CFList& LCs1, const CFList& LCs2 )2886 lNew, const CFList& LCs1, const CFList& LCs2, bool& bad) 2997 2887 { 2998 2888 int k= 0; … … 3020 2910 if (degree (bufFactors[i], y) > 0) 3021 2911 { 3022 ASSERT (fdivides (bufFactors[i][0], M (1, 1)), "expected exact division"); 3023 products.append (M (1, 1)/bufFactors[i] [0]); 3024 } 3025 else 3026 { 3027 ASSERT (fdivides (bufFactors[i], M (1, 1)), "expected exact division"); 3028 products.append (M (1, 1)/bufFactors[i]); 2912 if (!fdivides (bufFactors[i] [0], F.getFirst())) 2913 { 2914 bad= true; 2915 return CFList(); 2916 } 2917 products.append (F.getFirst()/bufFactors[i] [0]); 2918 } 2919 else 2920 { 2921 if (!fdivides (bufFactors[i], F.getFirst())) 2922 { 2923 bad= true; 2924 return CFList(); 2925 } 2926 products.append (F.getFirst()/bufFactors[i]); 3029 2927 } 3030 2928 } 3031 2929 3032 2930 for (int d= 1; d < lNew; d++) 3033 henselStep2 (F.getLast(),buf,bufFactors, diophant, M, Pi, products, d, MOD); 2931 { 2932 henselStep2 (F.getLast(), buf, bufFactors, diophant, M, Pi, products, d, MOD, bad); 2933 if (bad) 2934 return CFList(); 2935 } 3034 2936 3035 2937 CFList result; … … 3039 2941 } 3040 2942 3041 // so far only for two! factor Hensel lifting3042 2943 CFList 3043 2944 henselLift2 (const CFList& eval, const CFList& factors, int* l, const int 3044 2945 lLength, bool sort, const CFList& LCs1, const CFList& LCs2, 3045 const CFArray& Pi, const CFList& diophant )2946 const CFArray& Pi, const CFList& diophant, bool& bad) 3046 2947 { 3047 2948 CFList bufDiophant= diophant; … … 3051 2952 CFArray bufPi= Pi; 3052 2953 CFMatrix M= CFMatrix (l[1], factors.length()); 3053 CFList result= henselLift232(eval, buf, l, bufDiophant, bufPi, M, LCs1, LCs2); 2954 CFList result= henselLift232(eval, buf, l, bufDiophant, bufPi, M, LCs1, LCs2, 2955 bad); 2956 if (bad) 2957 return CFList(); 2958 3054 2959 if (eval.length() == 2) 3055 2960 return result; … … 3077 2982 M= CFMatrix (l[i], factors.length()); 3078 2983 result= henselLift2 (bufEval, result, MOD, bufDiophant, bufPi, M, l[i - 1], 3079 l[i], bufLCs1, bufLCs2); 2984 l[i], bufLCs1, bufLCs2, bad); 2985 if (bad) 2986 return CFList(); 3080 2987 MOD.append (power (Variable (i + 2), l[i])); 3081 2988 bufEval.removeFirst(); … … 3086 2993 } 3087 2994 2995 CFList 2996 nonMonicHenselLift23 (const CanonicalForm& F, const CFList& factors, const 2997 CFList& LCs, CFList& diophant, CFArray& Pi, int liftBound, 2998 int bivarLiftBound, bool& bad) 2999 { 3000 CFList bufFactors2= factors; 3001 3002 Variable y= Variable (2); 3003 for (CFListIterator i= bufFactors2; i.hasItem(); i++) 3004 i.getItem()= mod (i.getItem(), y); 3005 3006 CanonicalForm bufF= F; 3007 bufF= mod (bufF, y); 3008 bufF= mod (bufF, Variable (3)); 3009 3010 diophant= diophantine (bufF, bufFactors2); 3011 3012 CFMatrix M= CFMatrix (liftBound, bufFactors2.length() - 1); 3013 3014 Pi= CFArray (bufFactors2.length() - 1); 3015 3016 CFArray bufFactors= CFArray (bufFactors2.length()); 3017 CFListIterator j= LCs; 3018 int i= 0; 3019 for (CFListIterator k= factors; k.hasItem(); j++, k++, i++) 3020 bufFactors[i]= replaceLC (k.getItem(), j.getItem()); 3021 3022 //initialise Pi 3023 Variable v= Variable (3); 3024 CanonicalForm yToL= power (y, bivarLiftBound); 3025 if (degree (bufFactors[0], v) > 0 && degree (bufFactors [1], v) > 0) 3026 { 3027 M (1, 1)= mulMod2 (bufFactors [0] [0], bufFactors[1] [0], yToL); 3028 Pi [0]= M (1,1) + (mulMod2 (bufFactors [0] [1], bufFactors[1] [0], yToL) + 3029 mulMod2 (bufFactors [0] [0], bufFactors [1] [1], yToL))*v; 3030 } 3031 else if (degree (bufFactors[0], v) > 0) 3032 { 3033 M (1,1)= mulMod2 (bufFactors [0] [0], bufFactors [1], yToL); 3034 Pi [0]= M(1,1) + mulMod2 (bufFactors [0] [1], bufFactors[1], yToL)*v; 3035 } 3036 else if (degree (bufFactors[1], v) > 0) 3037 { 3038 M (1,1)= mulMod2 (bufFactors [0], bufFactors [1] [0], yToL); 3039 Pi [0]= M (1,1) + mulMod2 (bufFactors [0], bufFactors[1] [1], yToL)*v; 3040 } 3041 else 3042 { 3043 M (1,1)= mulMod2 (bufFactors [0], bufFactors [1], yToL); 3044 Pi [0]= M (1,1); 3045 } 3046 3047 for (i= 1; i < Pi.size(); i++) 3048 { 3049 if (degree (Pi[i-1], v) > 0 && degree (bufFactors [i+1], v) > 0) 3050 { 3051 M (1,i+1)= mulMod2 (Pi[i-1] [0], bufFactors[i+1] [0], yToL); 3052 Pi [i]= M (1,i+1) + (mulMod2 (Pi[i-1] [1], bufFactors[i+1] [0], yToL) + 3053 mulMod2 (Pi[i-1] [0], bufFactors [i+1] [1], yToL))*v; 3054 } 3055 else if (degree (Pi[i-1], v) > 0) 3056 { 3057 M (1,i+1)= mulMod2 (Pi[i-1] [0], bufFactors [i+1], yToL); 3058 Pi [i]= M(1,i+1) + mulMod2 (Pi[i-1] [1], bufFactors[i+1], yToL)*v; 3059 } 3060 else if (degree (bufFactors[i+1], v) > 0) 3061 { 3062 M (1,i+1)= mulMod2 (Pi[i-1], bufFactors [i+1] [0], yToL); 3063 Pi [i]= M (1,i+1) + mulMod2 (Pi[i-1], bufFactors[i+1] [1], yToL)*v; 3064 } 3065 else 3066 { 3067 M (1,i+1)= mulMod2 (Pi [i-1], bufFactors [i+1], yToL); 3068 Pi [i]= M (1,i+1); 3069 } 3070 } 3071 3072 CFList products; 3073 bufF= mod (F, Variable (3)); 3074 for (CFListIterator k= factors; k.hasItem(); k++) 3075 products.append (bufF/k.getItem()); 3076 3077 CFList MOD= CFList (power (v, liftBound)); 3078 MOD.insert (yToL); 3079 for (int d= 1; d < liftBound; d++) 3080 { 3081 henselStep2 (F, factors, bufFactors, diophant, M, Pi, products, d, MOD, bad); 3082 if (bad) 3083 return CFList(); 3084 } 3085 3086 CFList result; 3087 for (i= 0; i < factors.length(); i++) 3088 result.append (bufFactors[i]); 3089 return result; 3090 } 3091 3092 CFList 3093 nonMonicHenselLift (const CFList& F, const CFList& factors, const CFList& LCs, 3094 CFList& diophant, CFArray& Pi, CFMatrix& M, const int lOld, 3095 int& lNew, const CFList& MOD, bool& noOneToOne 3096 ) 3097 { 3098 3099 int k= 0; 3100 CFArray bufFactors= CFArray (factors.length()); 3101 CFListIterator j= LCs; 3102 for (CFListIterator i= factors; i.hasItem(); i++, j++, k++) 3103 bufFactors [k]= replaceLC (i.getItem(), j.getItem()); 3104 3105 Variable y= F.getLast().mvar(); 3106 Variable x= F.getFirst().mvar(); 3107 CanonicalForm xToLOld= power (x, lOld); 3108 3109 Pi [0]= mod (Pi[0], xToLOld); 3110 M (1, 1)= Pi [0]; 3111 3112 if (degree (bufFactors[0], y) > 0 && degree (bufFactors [1], y) > 0) 3113 Pi [0] += (mulMod (bufFactors [0] [1], bufFactors[1] [0], MOD) + 3114 mulMod (bufFactors [0] [0], bufFactors [1] [1], MOD))*y; 3115 else if (degree (bufFactors[0], y) > 0) 3116 Pi [0] += mulMod (bufFactors [0] [1], bufFactors[1], MOD)*y; 3117 else if (degree (bufFactors[1], y) > 0) 3118 Pi [0] += mulMod (bufFactors [0], bufFactors[1] [1], MOD)*y; 3119 3120 for (int i= 1; i < Pi.size(); i++) 3121 { 3122 Pi [i]= mod (Pi [i], xToLOld); 3123 M (1, i + 1)= Pi [i]; 3124 3125 if (degree (Pi[i-1], y) > 0 && degree (bufFactors [i+1], y) > 0) 3126 Pi [i] += (mulMod (Pi[i-1] [1], bufFactors[i+1] [0], MOD) + 3127 mulMod (Pi[i-1] [0], bufFactors [i+1] [1], MOD))*y; 3128 else if (degree (Pi[i-1], y) > 0) 3129 Pi [i] += mulMod (Pi[i-1] [1], bufFactors[i+1], MOD)*y; 3130 else if (degree (bufFactors[i+1], y) > 0) 3131 Pi [i] += mulMod (Pi[i-1], bufFactors[i+1] [1], MOD)*y; 3132 } 3133 3134 CFList products; 3135 CanonicalForm bufF= F.getFirst(); 3136 3137 for (int i= 0; i < bufFactors.size(); i++) 3138 { 3139 if (degree (bufFactors[i], y) > 0) 3140 { 3141 if (!fdivides (bufFactors[i] [0], bufF)) 3142 { 3143 noOneToOne= true; 3144 return factors; 3145 } 3146 products.append (bufF/bufFactors[i] [0]); 3147 } 3148 else 3149 { 3150 if (!fdivides (bufFactors[i], bufF)) 3151 { 3152 noOneToOne= true; 3153 return factors; 3154 } 3155 products.append (bufF/bufFactors[i]); 3156 } 3157 } 3158 3159 for (int d= 1; d < lNew; d++) 3160 { 3161 henselStep2 (F.getLast(), factors, bufFactors, diophant, M, Pi, products, d, 3162 MOD, noOneToOne); 3163 if (noOneToOne) 3164 return CFList(); 3165 } 3166 3167 CFList result; 3168 for (k= 0; k < factors.length(); k++) 3169 result.append (bufFactors[k]); 3170 return result; 3171 } 3172 3173 CFList 3174 nonMonicHenselLift (const CFList& eval, const CFList& factors, 3175 CFList* const& LCs, CFList& diophant, CFArray& Pi, 3176 int* liftBound, int length, bool& noOneToOne 3177 ) 3178 { 3179 CFList bufDiophant= diophant; 3180 CFList buf= factors; 3181 CFArray bufPi= Pi; 3182 CFMatrix M= CFMatrix (liftBound[1], factors.length() - 1); 3183 int k= 0; 3184 3185 CFList result= 3186 nonMonicHenselLift23 (eval.getFirst(), factors, LCs [0], diophant, bufPi, 3187 liftBound[1], liftBound[0], noOneToOne); 3188 3189 if (noOneToOne) 3190 return CFList(); 3191 3192 if (eval.length() == 1) 3193 return result; 3194 3195 k++; 3196 CFList MOD; 3197 for (int i= 0; i < 2; i++) 3198 MOD.append (power (Variable (i + 2), liftBound[i])); 3199 3200 CFListIterator j= eval; 3201 CFList bufEval; 3202 bufEval.append (j.getItem()); 3203 j++; 3204 3205 for (int i= 2; i <= length && j.hasItem(); i++, j++, k++) 3206 { 3207 bufEval.append (j.getItem()); 3208 M= CFMatrix (liftBound[i], factors.length() - 1); 3209 result= nonMonicHenselLift (bufEval, result, LCs [i-1], diophant, bufPi, M, 3210 liftBound[i-1], liftBound[i], MOD, noOneToOne); 3211 if (noOneToOne) 3212 return result; 3213 MOD.append (power (Variable (i + 2), liftBound[i])); 3214 bufEval.removeFirst(); 3215 } 3216 3217 return result; 3218 } 3219 3088 3220 #endif 3089 3221 /* HAVE_NTL */ -
factory/facHensel.h
r1bebbf re368746 243 243 CFArray& Pi, ///< [in,out] stores intermediate results 244 244 CFList& diophant, ///< [in,out] result of diophantine() 245 CFMatrix& M ///< [in,out] stores intermediate results 245 CFMatrix& M, ///< [in,out] stores intermediate results 246 bool sort= true ///< [in] sort factors by degree in 247 ///< Variable(1) 246 248 ); 247 249 … … 383 385 ///< leading coefficient 384 386 const int* l, ///< [in] lifting bounds 385 const int lLength ///< [in] length of l 387 const int lLength, ///< [in] length of l 388 bool sort= true ///< [in] sort factors by degree in 389 ///< Variable(1) 386 390 ); 387 391 … … 422 426 ///< factor 423 427 const CFArray& Pi, ///< [in] intermediate result 424 const CFList& diophant///< [in] result of diophantine 428 const CFList& diophant,///< [in] result of diophantine 429 bool& noOneToOne ///< [in,out] check for one to one 430 ///< correspondence 425 431 ); 426 432 433 /// Hensel lifting of non monic factors, needs correct leading coefficients of 434 /// factors and a one to one corresponds between bivariate and multivariate 435 /// factors to succeed 436 /// 437 /// @return @a nonMonicHenselLift returns a list of lifted factors 438 /// such that prod (factors) == eval.getLast() if there is a one to one 439 /// correspondence 440 CFList 441 nonMonicHenselLift (const CFList& eval, ///< [in] a list of polys the last 442 ///< element is a compressed 443 ///< multivariate poly, last but one 444 ///< element equals the last elements 445 ///< modulo its main variable and so 446 ///< on. The first element is a 447 ///< compressed poly in 3 variables 448 const CFList& factors, ///< [in] a list of bivariate factors 449 CFList* const& LCs, ///< [in] leading coefficients, 450 ///< evaluated in the same way as 451 ///< eval 452 CFList& diophant, ///< [in, out] solution of univariate 453 ///< diophantine equation 454 CFArray& Pi, ///< [in, out] buffer intermediate 455 ///< results 456 int* liftBound, ///< [in] lifting bounds 457 int length, ///< [in] length of lifting bounds 458 bool& noOneToOne ///< [in, out] check for one to one 459 ///< correspondence 460 ); 427 461 #endif 428 462 /* FAC_HENSEL_H */
Note: See TracChangeset
for help on using the changeset viewer.