Changeset 1130ffc in git
- Timestamp:
- Oct 25, 2012, 2:25:59 PM (11 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '0604212ebb110535022efecad887940825b97c3f')
- Children:
- 139f6f800b915490dfaa914ef7676d29a3236b92186df6b3fe891f605e0e3e7324333e7713165436
- Parents:
- becbea965e6c5de8e8ab195c7f480cabc295ac0cd91423947d67c2ab2eaf1aae4a61f9f2988e9510
- Location:
- factory
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/algext.cc
rbecbea r1130ffc 15 15 16 16 #include "cf_assert.h" 17 #include "timing.h" 17 18 18 19 #include "templates/ftmpl_functions.h" … … 29 30 #include "NTLconvert.h" 30 31 #endif 32 33 TIMING_DEFINE_PRINT(alg_content_p) 34 TIMING_DEFINE_PRINT(alg_content) 35 TIMING_DEFINE_PRINT(alg_compress) 36 TIMING_DEFINE_PRINT(alg_termination) 37 TIMING_DEFINE_PRINT(alg_termination_p) 38 TIMING_DEFINE_PRINT(alg_reconstruction) 39 TIMING_DEFINE_PRINT(alg_newton_p) 40 TIMING_DEFINE_PRINT(alg_recursion_p) 41 TIMING_DEFINE_PRINT(alg_gcd_p) 42 TIMING_DEFINE_PRINT(alg_euclid_p) 31 43 32 44 /// compressing two polynomials F and G, M is used for compressing, … … 430 442 return; 431 443 } 444 TIMING_START (alg_compress) 432 445 CFMap MM,NN; 433 446 int lev= myCompress (F, G, MM, NN, topLevel); … … 439 452 CanonicalForm f=MM(F); 440 453 CanonicalForm g=MM(G); 454 TIMING_END_AND_PRINT (alg_compress, "time to compress in alg gcd: ") 441 455 // here: f,g are compressed 442 456 // compute largest variable in f or g (least one is Variable(1)) … … 447 461 if(mv == 1) // f,g univariate 448 462 { 463 TIMING_START (alg_euclid_p) 449 464 tryEuclid(f,g,M,result,fail); 465 TIMING_END_AND_PRINT (alg_euclid_p, "time for euclidean alg mod p: ") 450 466 if(fail) 451 467 return; … … 453 469 return; 454 470 } 471 TIMING_START (alg_content_p) 455 472 // here: mv > 1 456 473 CanonicalForm cf = tryvcontent(f, Variable(2), M, fail); // cf is univariate poly in var(1) … … 472 489 if(fail) 473 490 return; 491 TIMING_END_AND_PRINT (alg_content_p, "time for content in alg gcd mod p: ") 474 492 if(f.inCoeffDomain()) 475 493 { … … 495 513 N = leadDeg(g, N); 496 514 CanonicalForm gamma; 515 TIMING_START (alg_euclid_p) 497 516 tryEuclid( firstLC(f), firstLC(g), M, gamma, fail ); 517 TIMING_END_AND_PRINT (alg_euclid_p, "time for gcd of lcs in alg mod p: ") 498 518 if(fail) 499 519 return; … … 517 537 if(gamma_image.isZero()) // skip lc-bad points var(1)-alpha 518 538 continue; 539 TIMING_START (alg_recursion_p) 519 540 tryBrownGCD( f(alpha, x), g(alpha, x), M, g_image, fail, false ); // recursive call with one var less 541 TIMING_END_AND_PRINT (alg_recursion_p, 542 "time for recursive calls in alg gcd mod p: ") 520 543 if(fail) 521 544 return; … … 541 564 g_image *= gamma_image; // multiply by multiple of image lc(gcd) 542 565 g_image= reduce (g_image, M); 566 TIMING_START (alg_newton_p) 543 567 gnew= tryNewtonInterp (alpha, g_image, m, gm, x, M, fail); 568 TIMING_END_AND_PRINT (alg_newton_p, 569 "time for Newton interpolation in alg gcd mod p: ") 544 570 // gnew = gm mod m 545 571 // gnew = g_image mod var(1)-alpha … … 550 576 if((firstLC(gnew) == gamma) || (gnew == gm)) // gnew did not change 551 577 { 578 TIMING_START (alg_termination_p) 552 579 cf = tryvcontent(gnew, Variable(2), M, fail); 553 580 if(fail) … … 569 596 { 570 597 result = NN(reduce (c*g_image, M)); 598 TIMING_END_AND_PRINT (alg_termination_p, 599 "time for successful termination test in alg gcd mod p: ") 571 600 return; 572 601 } 573 602 } 603 TIMING_END_AND_PRINT (alg_termination_p, 604 "time for unsuccessful termination test in alg gcd mod p: ") 574 605 } 575 606 gm = gnew; … … 665 696 f = F * bCommonDen(F); 666 697 g = G * bCommonDen(G); 698 TIMING_START (alg_content) 667 699 CanonicalForm contf= myicontent (f); 668 700 CanonicalForm contg= myicontent (g); … … 670 702 g /= contg; 671 703 CanonicalForm gcdcfcg= myicontent (contf, contg); 704 TIMING_END_AND_PRINT (alg_content, "time for content in alg gcd: ") 672 705 Variable a, b; 673 706 if(hasFirstAlgVar(f,a)) … … 727 760 mipo /= mipo.lc(); 728 761 // here: mipo is monic 762 TIMING_START (alg_gcd_p) 729 763 tryBrownGCD( mapinto(f), mapinto(g), mipo, Dp, fail ); 764 TIMING_END_AND_PRINT (alg_gcd_p, "time for alg gcd mod p: ") 730 765 if( fail ) // mipo splits in char p 731 766 continue; … … 756 791 D = tmp; 757 792 On( SW_RATIONAL ); 793 TIMING_START (alg_reconstruction) 758 794 tmp = Farey( D, q ); // Farey 759 795 tmp *= bCommonDen (tmp); 796 TIMING_END_AND_PRINT (alg_reconstruction, 797 "time for rational reconstruction in alg gcd: ") 760 798 setReduce(a,true); // reduce expressions modulo mipo 761 799 On( SW_RATIONAL ); // needed by fdivides … … 764 802 else 765 803 equal= true; // modular image did not add any new information 804 TIMING_START (alg_termination) 766 805 if(equal && fdivides( tmp, f ) && fdivides( tmp, g )) // trial division 767 806 { … … 769 808 setReduce(a,true); 770 809 if (off_rational) Off(SW_RATIONAL); else On(SW_RATIONAL); 810 TIMING_END_AND_PRINT (alg_termination, 811 "time for successful termination test in alg gcd: ") 771 812 return tmp*gcdcfcg; 772 813 } 814 TIMING_END_AND_PRINT (alg_termination, 815 "time for unsuccessful termination test in alg gcd: ") 773 816 Off( SW_RATIONAL ); 774 817 setReduce(a,false); // do not reduce expressions modulo mipo -
factory/cfNewtonPolygon.cc
rbecbea r1130ffc 879 879 if (isRat) 880 880 On (SW_RATIONAL); 881 if (tmp == 1) 882 { 883 for (int i= 0; i < sizeOfNewtonPolygon; i++) 884 delete [] newtonPolyg [i]; 885 delete [] newtonPolyg; 886 } 881 for (int i= 0; i < sizeOfNewtonPolygon; i++) 882 delete [] newtonPolyg [i]; 883 delete [] newtonPolyg; 887 884 return (tmp==1); 888 885 } -
factory/cf_gcd.cc
rbecbea r1130ffc 3 3 #include "config.h" 4 4 5 #include "timing.h" 5 6 #include "cf_assert.h" 6 7 #include "debug.h" … … 572 573 Variable v = f.mvar(); 573 574 Hi = power( LC( pi1, v ), delta ); 575 int maxNumVars= tmax (getNumVars (pi), getNumVars (pi1)); 576 577 if (!(pi.isUnivariate() && pi1.isUnivariate())) 578 { 579 if (size (Hi)*size (pi)/(maxNumVars*3) > 500) //maybe this needs more tuning 580 { 581 On (SW_USE_FF_MOD_GCD); 582 C *= gcd (pi, pi1); 583 Off (SW_USE_FF_MOD_GCD); 584 return C; 585 } 586 } 587 574 588 if ( (delta+1) % 2 ) 575 589 bi = 1; 576 590 else 577 591 bi = -1; 578 int maxNumVars= tmax (getNumVars (pi), getNumVars (pi1)); 579 CanonicalForm oldPi= pi, oldPi1= pi1; 592 CanonicalForm oldPi= pi, oldPi1= pi1, powHi; 580 593 while ( degree( pi1, v ) > 0 ) 581 594 { … … 604 617 { 605 618 delta = degree( pi, v ) - degree( pi1, v ); 619 powHi= power (Hi, delta-1); 606 620 if ( (delta+1) % 2 ) 607 bi = LC( pi, v ) * pow er( Hi, delta );621 bi = LC( pi, v ) * powHi*Hi; 608 622 else 609 bi = -LC( pi, v ) * power( Hi, delta ); 610 Hi = power( LC( pi1, v ), delta ) / power( Hi, delta-1 ); 623 bi = -LC( pi, v ) * powHi*Hi; 624 Hi = power( LC( pi1, v ), delta ) / powHi; 625 if (!(pi.isUnivariate() && pi1.isUnivariate())) 626 { 627 if (size (Hi)*size (pi)/(maxNumVars*3) > 500) //maybe this needs more tuning 628 { 629 On (SW_USE_FF_MOD_GCD); 630 C *= gcd (oldPi, oldPi1); 631 Off (SW_USE_FF_MOD_GCD); 632 return C; 633 } 634 } 611 635 } 612 636 } … … 1156 1180 } 1157 1181 1182 TIMING_DEFINE_PRINT(chinrem_termination) 1183 TIMING_DEFINE_PRINT(chinrem_recursion) 1184 TIMING_DEFINE_PRINT(chinrem_reconstruction) 1185 1158 1186 CanonicalForm chinrem_gcd ( const CanonicalForm & FF, const CanonicalForm & GG ) 1159 1187 { … … 1223 1251 fp= mapinto (f); 1224 1252 gp= mapinto (g); 1253 TIMING_START (chinrem_recursion) 1225 1254 #ifdef HAVE_NTL 1226 1255 if (size (fp)/maxNumVars > 500 && size (gp)/maxNumVars > 500) … … 1237 1266 cogp= gp/Dp; 1238 1267 #endif 1268 TIMING_END_AND_PRINT (chinrem_recursion, 1269 "time for gcd mod p in modular gcd: "); 1239 1270 Dp /=Dp.lc(); 1240 1271 cofp /= lc (cofp); … … 1287 1318 if ( i >= 0 ) 1288 1319 { 1320 TIMING_START (chinrem_reconstruction); 1289 1321 Dn= Farey(D,q); 1290 1322 cofn= Farey(cof,q); 1291 1323 cogn= Farey(cog,q); 1324 TIMING_END_AND_PRINT (chinrem_reconstruction, 1325 "time for rational reconstruction in modular gcd: "); 1292 1326 int is_rat= isOn (SW_RATIONAL); 1293 1327 On (SW_RATIONAL); … … 1303 1337 equal= true; 1304 1338 //Dn /=vcontent(Dn,Variable(1)); 1339 TIMING_START (chinrem_termination); 1305 1340 if ((terminationTest (f,g, cofn, cogn, Dn)) || 1306 1341 ((equal || q > b) && fdivides (Dn, f) && fdivides (Dn, g))) 1307 1342 { 1343 TIMING_END_AND_PRINT (chinrem_termination, 1344 "time for successful termination in modular gcd: "); 1308 1345 //printf(" -> success\n"); 1309 1346 return Dn*gcdcfcg; 1310 1347 } 1348 TIMING_END_AND_PRINT (chinrem_termination, 1349 "time for unsuccessful termination in modular gcd: "); 1311 1350 equal= false; 1312 1351 //else: try more primes -
factory/cf_gcd_smallp.cc
rbecbea r1130ffc 45 45 TIMING_DEFINE_PRINT(gcd_recursion) 46 46 TIMING_DEFINE_PRINT(newton_interpolation) 47 TIMING_DEFINE_PRINT(termination_test) 48 TIMING_DEFINE_PRINT(ez_p_compress) 49 TIMING_DEFINE_PRINT(ez_p_hensel_lift) 50 TIMING_DEFINE_PRINT(ez_p_eval) 51 TIMING_DEFINE_PRINT(ez_p_content) 47 52 48 53 bool … … 797 802 if ((uni_lcoeff (H) == gcdlcAlcB) || (G_m == H)) 798 803 { 804 TIMING_START (termination_test); 799 805 if (gcdlcAlcB.isOne()) 800 806 cH= 1; … … 831 837 coF= N ((cA/gcdcAcB)*ppCoF); 832 838 coG= N ((cB/gcdcAcB)*ppCoG); 839 TIMING_END_AND_PRINT (termination_test, 840 "time for successful termination test Fq: "); 833 841 return N(gcdcAcB*ppH); 834 842 } … … 846 854 } 847 855 coF= N ((cA/gcdcAcB)*ppCoF); 848 coG= N ((cB/gcdcAcB)*ppCoG);; 856 coG= N ((cB/gcdcAcB)*ppCoG); 857 TIMING_END_AND_PRINT (termination_test, 858 "time for successful termination test Fq: "); 849 859 return N(gcdcAcB*ppH); 850 860 } 861 TIMING_END_AND_PRINT (termination_test, 862 "time for unsuccessful termination test Fq: "); 851 863 } 852 864 … … 1237 1249 if ((uni_lcoeff (H) == gcdlcAlcB) || (G_m == H)) 1238 1250 { 1251 TIMING_START (termination_test); 1239 1252 if (gcdlcAlcB.isOne()) 1240 1253 cH= 1; … … 1270 1283 coG= N ((cB/gcdcAcB)*ppCoG); 1271 1284 setCharacteristic (p, k, gf_name_buf); 1285 TIMING_END_AND_PRINT (termination_test, 1286 "time for successful termination GF: "); 1272 1287 return N(gcdcAcB*ppH); 1273 1288 } … … 1288 1303 coF= N ((cA/gcdcAcB)*ppCoF); 1289 1304 coG= N ((cB/gcdcAcB)*ppCoG); 1305 TIMING_END_AND_PRINT (termination_test, 1306 "time for successful termination GF: "); 1290 1307 return N(gcdcAcB*ppH); 1291 1308 } 1292 1309 } 1310 TIMING_END_AND_PRINT (termination_test, 1311 "time for unsuccessful termination GF: "); 1293 1312 } 1294 1313 … … 1744 1763 if ((uni_lcoeff (H) == gcdlcAlcB) || (G_m == H)) 1745 1764 { 1765 TIMING_START (termination_test); 1746 1766 if (gcdlcAlcB.isOne()) 1747 1767 cH= 1; … … 1769 1789 coF= N ((cA/gcdcAcB)*ppCoF); 1770 1790 coG= N ((cB/gcdcAcB)*ppCoG); 1791 TIMING_END_AND_PRINT (termination_test, 1792 "time for successful termination Fp: "); 1771 1793 return N(gcdcAcB*ppH); 1772 1794 } 1795 TIMING_END_AND_PRINT (termination_test, 1796 "time for unsuccessful termination Fp: "); 1773 1797 } 1774 1798 … … 4450 4474 CFMap M,N; 4451 4475 int smallestDegLev; 4476 TIMING_START (ez_p_compress) 4452 4477 int best_level= compress4EZGCD (F, G, M, N, smallestDegLev); 4453 4478 … … 4456 4481 F= M (F); 4457 4482 G= M (G); 4458 4483 TIMING_END_AND_PRINT (ez_p_compress, "time for compression in EZ_P: ") 4484 4485 TIMING_START (ez_p_content) 4459 4486 f = content( F, x ); g = content( G, x ); 4460 4487 d = gcd( f, g ); 4461 4488 F /= f; G /= g; 4489 TIMING_END_AND_PRINT (ez_p_content, "time to extract content in EZ_P: ") 4462 4490 4463 4491 if( F.isUnivariate() && G.isUnivariate() ) … … 4598 4626 while( !gcdfound ) 4599 4627 { 4628 TIMING_START (ez_p_eval); 4600 4629 if( !findeval_P( F, G, Fb, Gb, Db, b, delta, degF, degG, maxeval, count, o, 4601 4630 maxeval/maxNumVars, t )) … … 4620 4649 return N (d*result); 4621 4650 } 4651 TIMING_END_AND_PRINT (ez_p_eval, "time for eval point search in EZ_P1: "); 4622 4652 delta = degree( Db ); 4623 4653 if( delta == 0 ) … … 4632 4662 { 4633 4663 bt = b; 4664 TIMING_START (ez_p_eval); 4634 4665 if( !findeval_P(F,G,Fbt,Gbt,Dbt, bt, delta, degF, degG, maxeval, count, o, 4635 4666 maxeval/maxNumVars, t )) … … 4654 4685 return N (d*result); 4655 4686 } 4687 TIMING_END_AND_PRINT (ez_p_eval, "time for eval point search in EZ_P2: "); 4656 4688 int dd = degree( Dbt ); 4657 4689 if( dd == 0 ) … … 4807 4839 } 4808 4840 4841 TIMING_START (ez_p_hensel_lift); 4809 4842 gcdfound= Hensel_P (B*lcD, DD, b, lcDD); 4810 4811 if (gcdfound == -1) 4812 { 4813 Off (SW_USE_EZGCD_P); 4814 result= gcd (F,G); 4815 On (SW_USE_EZGCD_P); 4816 if (passToGF) 4817 { 4818 CanonicalForm mipo= gf_mipo; 4819 setCharacteristic (p); 4820 Variable alpha= rootOf (mipo.mapinto()); 4821 result= GF2FalphaRep (result, alpha); 4843 TIMING_END_AND_PRINT (ez_p_hensel_lift, "time for Hensel lift in EZ_P: "); 4844 4845 if (gcdfound == -1) //things became dense 4846 { 4847 if (algExtension) 4848 { 4849 result= GCD_Fp_extension (F, G, a); 4850 if (extOfExt) 4851 result= mapDown (result, primElem, imPrimElem, oldA, dest, source); 4852 return N (d*result); 4822 4853 } 4823 if (k > 1) 4824 { 4825 result= GFMapDown (result, k); 4826 setCharacteristic (p, k, gf_name); 4854 if (CFFactory::gettype() == GaloisFieldDomain) 4855 { 4856 result= GCD_GF (F, G); 4857 if (passToGF) 4858 { 4859 CanonicalForm mipo= gf_mipo; 4860 setCharacteristic (p); 4861 Variable alpha= rootOf (mipo.mapinto()); 4862 result= GF2FalphaRep (result, alpha); 4863 } 4864 if (k > 1) 4865 { 4866 result= GFMapDown (result, k); 4867 setCharacteristic (p, k, gf_name); 4868 } 4869 return N (d*result); 4827 4870 } 4828 if (extOfExt) 4829 result= mapDown (result, primElem, imPrimElem, oldA, dest, source); 4830 return N (d*result); 4871 else 4872 return N (d*GCD_small_p (F,G)); 4831 4873 } 4832 4874 4833 4875 if (gcdfound == 1) 4834 4876 { 4877 TIMING_START (termination_test); 4835 4878 contcand= content (DD[2], Variable (1)); 4836 4879 cand = DD[2] / contcand; … … 4839 4882 else 4840 4883 gcdfound = fdivides( cand, F ) && cand*(DD[1]/(lcD/contcand)) == G; 4884 TIMING_END_AND_PRINT (termination_test, 4885 "time for termination test EZ_P: "); 4841 4886 4842 4887 if (passToGF && gcdfound) -
factory/facAlgExt.cc
rbecbea r1130ffc 29 29 #include "fac_sqrfree.h" 30 30 31 TIMING_DEFINE_PRINT(fac_alg_resultant) 32 TIMING_DEFINE_PRINT(fac_alg_norm) 33 TIMING_DEFINE_PRINT(fac_alg_factor_norm) 34 TIMING_DEFINE_PRINT(fac_alg_gcd) 35 TIMING_DEFINE_PRINT(fac_alg_sqrf) 36 TIMING_DEFINE_PRINT(fac_alg_factor_sqrf) 37 31 38 // squarefree part of F 32 39 CanonicalForm … … 53 60 int degmipo= degree (mipo); 54 61 CanonicalForm norm; 62 TIMING_START (fac_alg_resultant); 55 63 if (degg >= 8 || degmipo >= 8) 56 64 norm= resultantZ (g, mipo, x); 57 65 else 58 66 norm= resultant (g, mipo, x); 67 TIMING_END_AND_PRINT (fac_alg_resultant, "time to compute resultant0: "); 59 68 60 69 i= 0; … … 72 81 g= F (y - i*alpha, y); 73 82 g *= bCommonDen (g); 83 TIMING_START (fac_alg_resultant); 74 84 if (degg >= 8 || degmipo >= 8) 75 85 norm= resultantZ (g (x, alpha), mipo, x); 76 86 else 77 87 norm= resultant (g (x, alpha), mipo, x); 88 TIMING_END_AND_PRINT (fac_alg_resultant,"time to compute resultant1: "); 78 89 } 79 90 else … … 81 92 g= F (y + i*alpha, y); 82 93 g *= bCommonDen (g); 94 TIMING_START (fac_alg_resultant); 83 95 if (degg >= 8 || degmipo >= 8) 84 96 norm= resultantZ (g (x, alpha), mipo, x); 85 97 else 86 98 norm= resultant (g (x, alpha), mipo, x); 99 TIMING_END_AND_PRINT (fac_alg_resultant,"time to compute resultant2: "); 87 100 } 88 101 if (degree (gcd (deriv (norm, y), norm)) <= 0) … … 108 121 CanonicalForm f= F*bCommonDen (F); 109 122 int shift; 123 TIMING_START (fac_alg_norm); 110 124 CanonicalForm norm= sqrfNorm (f, alpha, shift); 125 TIMING_END_AND_PRINT (fac_alg_norm, "time to compute sqrf norm: "); 111 126 ASSERT (degree (norm, alpha) <= 0, "wrong norm computed"); 127 TIMING_START (fac_alg_factor_norm); 112 128 CFFList normFactors= factorize (norm); 129 TIMING_END_AND_PRINT (fac_alg_factor_norm, "time to factor norm: "); 113 130 CFList factors; 114 131 if (normFactors.length() <= 2) … … 125 142 { 126 143 ASSERT (i.getItem().exp() == 1, "norm not squarefree"); 144 TIMING_START (fac_alg_gcd); 127 145 if (shift == 0) 128 146 factor= gcd (buf, i.getItem().factor()); … … 130 148 factor= gcd (buf, i.getItem().factor() (f.mvar() + shift*alpha, f.mvar())); 131 149 buf /= factor; 150 TIMING_END_AND_PRINT (fac_alg_gcd, "time to recover factors: "); 132 151 factors.append (factor); 133 152 } … … 149 168 bool save_rat=!isOn (SW_RATIONAL); 150 169 On (SW_RATIONAL); 170 TIMING_START (fac_alg_sqrf); 151 171 CFFList sqrf= sqrFreeZ (F); 172 TIMING_END_AND_PRINT (fac_alg_sqrf, "time for sqrf factors in Q(a)[x]: "); 152 173 CFList factorsSqrf; 153 174 CFFList factors; … … 158 179 { 159 180 if (i.getItem().factor().inCoeffDomain()) continue; 181 TIMING_START (fac_alg_factor_sqrf); 160 182 factorsSqrf= AlgExtSqrfFactorize (i.getItem().factor(), alpha); 183 TIMING_END_AND_PRINT (fac_alg_factor_sqrf, 184 "time to factor sqrf factors in Q(a)[x]: "); 161 185 for (j= factorsSqrf; j.hasItem(); j++) 162 186 { -
factory/facBivar.cc
rbecbea r1130ffc 13 13 #include "config.h" 14 14 15 #include " assert.h"15 #include "cf_assert.h" 16 16 #include "debug.h" 17 17 #include "timing.h" … … 28 28 TIMING_DEFINE_PRINT(fac_bi_hensel_lift) 29 29 TIMING_DEFINE_PRINT(fac_bi_factor_recombination) 30 TIMING_DEFINE_PRINT(fac_bi_evaluation) 31 TIMING_DEFINE_PRINT(fac_bi_shift_to_zero) 30 32 31 33 // bound on coeffs of f (cf. Musser: Multivariate Polynomial Factorization, … … 186 188 } 187 189 188 CFList189 earlyFactorDetection0 (CanonicalForm& F, CFList& factors,int& adaptedLiftBound,190 DegreePattern& degs, bool& success, int deg)191 {192 DegreePattern bufDegs1= degs;193 DegreePattern bufDegs2;194 CFList result;195 CFList T= factors;196 CanonicalForm buf= F;197 CanonicalForm LCBuf= LC (buf, Variable (1));198 CanonicalForm g, quot;199 CanonicalForm M= power (F.mvar(), deg);200 adaptedLiftBound= 0;201 int d= degree (F) + degree (LCBuf, F.mvar());202 for (CFListIterator i= factors; i.hasItem(); i++)203 {204 if (!bufDegs1.find (degree (i.getItem(), 1)))205 continue;206 else207 {208 g= i.getItem() (0, 1);209 g *= LCBuf;210 g= mod (g, M);211 if (fdivides (LC (g), LCBuf))212 {213 g= mulMod2 (i.getItem(), LCBuf, M);214 g /= content (g, Variable (1));215 if (fdivides (g, buf, quot))216 {217 result.append (g);218 buf= quot;219 d -= degree (g) + degree (LC (g, Variable (1)), F.mvar());220 LCBuf= LC (buf, Variable (1));221 T= Difference (T, CFList (i.getItem()));222 223 // compute new possible degree pattern224 bufDegs2= DegreePattern (T);225 bufDegs1.intersect (bufDegs2);226 bufDegs1.refine ();227 if (bufDegs1.getLength() <= 1)228 {229 result.append (buf);230 break;231 }232 }233 }234 }235 }236 adaptedLiftBound= d + 1;237 if (d < deg)238 {239 factors= T;240 degs= bufDegs1;241 F= buf;242 success= true;243 }244 if (bufDegs1.getLength() <= 1)245 degs= bufDegs1;246 return result;247 }248 249 250 CFList251 henselLiftAndEarly0 (CanonicalForm& A, bool& earlySuccess, CFList&252 earlyFactors, DegreePattern& degs, int& liftBound,253 const CFList& uniFactors, const CanonicalForm& eval)254 {255 int sizeOfLiftPre;256 int * liftPre= getLiftPrecisions (A, sizeOfLiftPre, degree (LC (A, 1), 2));257 258 Variable x= Variable (1);259 Variable y= Variable (2);260 CFArray Pi;261 CFList diophant;262 CFList bufUniFactors= uniFactors;263 bufUniFactors.insert (LC (A, x));264 CFMatrix M= CFMatrix (liftBound, bufUniFactors.length() - 1);265 earlySuccess= false;266 int newLiftBound= 0;267 int smallFactorDeg= tmin (11, liftPre [sizeOfLiftPre- 1] + 1);//this is a tunable parameter268 if (smallFactorDeg >= liftBound || degree (A,y) <= 4)269 henselLift12 (A, bufUniFactors, liftBound, Pi, diophant, M);270 else if (sizeOfLiftPre > 1 && sizeOfLiftPre < 30)271 {272 henselLift12 (A, bufUniFactors, smallFactorDeg, Pi, diophant, M);273 earlyFactors= earlyFactorDetection0 (A, bufUniFactors, newLiftBound,274 degs, earlySuccess,275 smallFactorDeg);276 if (degs.getLength() > 1 && !earlySuccess &&277 smallFactorDeg != liftPre [sizeOfLiftPre-1] + 1)278 {279 if (newLiftBound > liftPre[sizeOfLiftPre-1]+1)280 {281 bufUniFactors.insert (LC (A, x));282 henselLiftResume12 (A, bufUniFactors, smallFactorDeg,283 liftPre[sizeOfLiftPre-1] + 1, Pi, diophant, M);284 earlyFactors= earlyFactorDetection0 (A, bufUniFactors, newLiftBound,285 degs, earlySuccess, liftPre[sizeOfLiftPre-1] + 1);286 }287 }288 else if (earlySuccess)289 liftBound= newLiftBound;290 int i= sizeOfLiftPre - 1;291 while (degs.getLength() > 1 && !earlySuccess && i - 1 >= 0)292 {293 if (newLiftBound > liftPre[i] + 1)294 {295 bufUniFactors.insert (LC (A, x));296 henselLiftResume12 (A, bufUniFactors, liftPre[i] + 1,297 liftPre[i-1] + 1, Pi, diophant, M);298 earlyFactors= earlyFactorDetection0 (A, bufUniFactors, newLiftBound,299 degs, earlySuccess, liftPre[i-1] + 1);300 }301 else302 {303 liftBound= newLiftBound;304 break;305 }306 i--;307 }308 if (earlySuccess)309 liftBound= newLiftBound;310 //after here all factors are lifted to liftPre[sizeOfLiftPre-1]311 }312 else313 {314 henselLift12 (A, bufUniFactors, smallFactorDeg, Pi, diophant, M);315 earlyFactors= earlyFactorDetection0 (A, bufUniFactors, newLiftBound,316 degs, earlySuccess,317 smallFactorDeg);318 int i= 1;319 while ((degree (A,y)/4)*i + 4 <= smallFactorDeg)320 i++;321 if (degs.getLength() > 1 && !earlySuccess)322 {323 bufUniFactors.insert (LC (A, x));324 henselLiftResume12 (A, bufUniFactors, smallFactorDeg,325 (degree (A, y)/4)*i + 4, Pi, diophant, M);326 earlyFactors= earlyFactorDetection0 (A, bufUniFactors, newLiftBound,327 degs, earlySuccess, (degree (A, y)/4)*i + 4);328 }329 while (degs.getLength() > 1 && !earlySuccess && i < 4)330 {331 if (newLiftBound > (degree (A, y)/4)*i + 4)332 {333 bufUniFactors.insert (LC (A, x));334 henselLiftResume12 (A, bufUniFactors, (degree (A,y)/4)*i + 4,335 (degree (A, y)/4)*(i+1) + 4, Pi, diophant, M);336 earlyFactors= earlyFactorDetection0 (A, bufUniFactors, newLiftBound,337 degs, earlySuccess, (degree (A, y)/4)*(i+1) + 4);338 }339 else340 {341 liftBound= newLiftBound;342 break;343 }344 i++;345 }346 if (earlySuccess)347 liftBound= newLiftBound;348 }349 350 return bufUniFactors;351 }352 353 190 CFList biFactorize (const CanonicalForm& F, const Variable& v) 354 191 { … … 499 336 { 500 337 bufAeval= A; 338 TIMING_START (fac_bi_evaluation); 501 339 bufAeval= evalPoint (A, bufEvaluation); 340 TIMING_END_AND_PRINT (fac_bi_evaluation, "time for eval point over Q: "); 502 341 503 342 bufAeval2= buf; 343 TIMING_START (fac_bi_evaluation); 504 344 bufAeval2= evalPoint (buf, bufEvaluation2); 345 TIMING_END_AND_PRINT (fac_bi_evaluation, 346 "time for eval point over Q in y: "); 505 347 506 348 // univariate factorization 507 TIMING_START (uni_factorize); 508 349 TIMING_START (fac_uni_factorizer); 509 350 if (extension) 510 351 bufUniFactors= conv (factorize (bufAeval, v)); 511 352 else 512 353 bufUniFactors= conv (factorize (bufAeval, true)); 513 TIMING_END_AND_PRINT ( uni_factorize,514 "time for univariate factorization : ");354 TIMING_END_AND_PRINT (fac_uni_factorizer, 355 "time for univariate factorization over Q: "); 515 356 DEBOUTLN (cerr, "prod (bufUniFactors)== bufAeval " << 516 357 (prod (bufUniFactors) == bufAeval)); 517 358 518 TIMING_START ( uni_factorize);359 TIMING_START (fac_uni_factorizer); 519 360 if (extension) 520 361 bufUniFactors2= conv (factorize (bufAeval2, v)); 521 362 else 522 363 bufUniFactors2= conv (factorize (bufAeval2, true)); 523 TIMING_END_AND_PRINT ( uni_factorize,524 "time for univariate factorization in y : ");364 TIMING_END_AND_PRINT (fac_uni_factorizer, 365 "time for univariate factorization in y over Q: "); 525 366 DEBOUTLN (cerr, "prod (bufuniFactors2)== bufAeval2 " << 526 367 (prod (bufUniFactors2) == bufAeval2)); … … 709 550 (A, earlySuccess, earlyFactors, degs, liftBound, 710 551 uniFactors, dummy, evaluation, b); 711 TIMING_END_AND_PRINT (fac_bi_hensel_lift, "time for hensel lifting: "); 552 TIMING_END_AND_PRINT (fac_bi_hensel_lift, 553 "time for bivariate hensel lifting over Q: "); 712 554 DEBOUTLN (cerr, "lifted factors= " << uniFactors); 713 555 … … 728 570 Off (SW_RATIONAL); 729 571 572 TIMING_START (fac_bi_factor_recombination); 730 573 factors= factorRecombination (uniFactors, A, MODl, degs, 1, 731 574 uniFactors.length()/2, b); 575 TIMING_END_AND_PRINT (fac_bi_factor_recombination, 576 "time for bivariate factor recombination over Q: "); 732 577 733 578 On (SW_RATIONAL); -
factory/facBivar.h
rbecbea r1130ffc 14 14 #define FAC_BIVAR_H 15 15 16 #include <config.h> 17 18 #include "assert.h" 16 #include "config.h" 17 18 #include "cf_assert.h" 19 #include "timing.h" 19 20 20 21 #include "facFqBivarUtil.h" … … 26 27 #include "algext.h" 27 28 #include "fac_util.h" 29 30 TIMING_DEFINE_PRINT(fac_bi_sqrf) 31 TIMING_DEFINE_PRINT(fac_bi_factor_sqrf) 28 32 29 33 /// @return @a biFactorize returns a list of factors of F. If F is not monic … … 196 200 vec_ZZ S; 197 201 F= compress (F, M, S); 202 TIMING_START (fac_bi_sqrf); 198 203 CFFList sqrfFactors= sqrFree (F); 204 TIMING_END_AND_PRINT (fac_bi_sqrf, 205 "time for bivariate sqrf factors over Q: "); 199 206 for (CFFListIterator i= sqrfFactors; i.hasItem(); i++) 200 207 { 208 TIMING_START (fac_bi_factor_sqrf); 201 209 CFList tmp= ratBiSqrfFactorize (i.getItem().factor(), v); 210 TIMING_END_AND_PRINT (fac_bi_factor_sqrf, 211 "time to factor bivariate sqrf factors over Q: "); 202 212 for (CFListIterator j= tmp; j.hasItem(); j++) 203 213 { -
factory/facFactorize.cc
rbecbea r1130ffc 29 29 #include "facSparseHensel.h" 30 30 31 TIMING_DEFINE_PRINT(fac_bi_factorize )31 TIMING_DEFINE_PRINT(fac_bi_factorizer) 32 32 TIMING_DEFINE_PRINT(fac_hensel_lift) 33 33 TIMING_DEFINE_PRINT(fac_factor_recombination) 34 TIMING_DEFINE_PRINT(fac_shift_to_zero) 35 TIMING_DEFINE_PRINT(fac_precompute_leadcoeff) 36 TIMING_DEFINE_PRINT(fac_evaluation) 37 TIMING_DEFINE_PRINT(fac_recover_factors) 38 TIMING_DEFINE_PRINT(fac_preprocess_and_content) 39 TIMING_DEFINE_PRINT(fac_bifactor_total) 40 TIMING_DEFINE_PRINT(fac_luckswang) 41 TIMING_DEFINE_PRINT(fac_lcheuristic) 42 TIMING_DEFINE_PRINT(fac_cleardenom) 43 TIMING_DEFINE_PRINT(fac_content) 44 TIMING_DEFINE_PRINT(fac_compress) 34 45 35 46 #ifdef HAVE_NTL … … 149 160 Aeval [j]= factors; 150 161 } 151 else if (!Aeval[j].isEmpty())152 Aeval[j]=CFList();153 162 } 154 163 } 155 156 int157 testFactors (const CanonicalForm& G, const CFList& uniFactors,158 CanonicalForm& sqrfPartF, CFList& factors,159 CFFList*& bufSqrfFactors, CFList& evalSqrfPartF,160 const CFArray& evalPoint)161 {162 CanonicalForm tmp;163 CFListIterator j;164 for (CFListIterator i= uniFactors; i.hasItem(); i++)165 {166 tmp= i.getItem();167 if (i.hasItem())168 i++;169 else170 break;171 for (j= i; j.hasItem(); j++)172 {173 if (tmp == j.getItem())174 return 0;175 }176 }177 178 CanonicalForm F= G;179 CFFList sqrfFactorization= sqrFree (F);180 181 sqrfPartF= 1;182 for (CFFListIterator i= sqrfFactorization; i.hasItem(); i++)183 sqrfPartF *= i.getItem().factor();184 185 evalSqrfPartF= evaluateAtEval (sqrfPartF, evalPoint);186 187 CanonicalForm test= evalSqrfPartF.getFirst() (evalPoint[0], 2);188 189 if (degree (test) != degree (sqrfPartF, 1) || test.inCoeffDomain())190 return 0;191 192 CFFList sqrfFactors;193 CFList tmp2;194 int k= 0;195 factors= uniFactors;196 CFFListIterator iter;197 for (CFListIterator i= factors; i.hasItem(); i++, k++)198 {199 tmp= 1;200 sqrfFactors= sqrFree (i.getItem());201 202 for (iter= sqrfFactors; iter.hasItem(); iter++)203 {204 tmp2.append (iter.getItem().factor());205 tmp *= iter.getItem().factor();206 }207 i.getItem()= tmp/Lc(tmp);208 bufSqrfFactors [k]= sqrfFactors;209 }210 211 for (int i= 0; i < factors.length() - 1; i++)212 {213 for (int k= i + 1; k < factors.length(); k++)214 {215 gcdFreeBasis (bufSqrfFactors [i], bufSqrfFactors[k]);216 }217 }218 219 factors= CFList();220 for (int i= 0; i < uniFactors.length(); i++)221 {222 if (i == 0)223 {224 for (iter= bufSqrfFactors [i]; iter.hasItem(); iter++)225 {226 if (iter.getItem().factor().inCoeffDomain())227 continue;228 iter.getItem()= CFFactor (iter.getItem().factor()/229 Lc (iter.getItem().factor()),230 iter.getItem().exp());231 factors.append (iter.getItem().factor());232 }233 }234 else235 {236 for (iter= bufSqrfFactors [i]; iter.hasItem(); iter++)237 {238 if (iter.getItem().factor().inCoeffDomain())239 continue;240 iter.getItem()= CFFactor (iter.getItem().factor()/241 Lc (iter.getItem().factor()),242 iter.getItem().exp());243 if (!find (factors, iter.getItem().factor()))244 factors.append (iter.getItem().factor());245 }246 }247 }248 249 test= prod (factors);250 tmp= evalSqrfPartF.getFirst() (evalPoint[0],2);251 if (test/Lc (test) != tmp/Lc (tmp))252 return 0;253 else254 return 1;255 }256 257 CFList258 precomputeLeadingCoeff (const CanonicalForm& LCF, const CFList& LCFFactors,259 const CFList& evaluation,CFList*& differentSecondVarLCs,260 int length, Variable& y261 )262 {263 y= Variable (1);264 if (LCF.inCoeffDomain())265 {266 CFList result;267 for (int i= 1; i <= LCFFactors.length() + 1; i++)268 result.append (1);269 return result;270 }271 272 CFMap N, M;273 CFArray dummy= CFArray (2);274 dummy [0]= LCF;275 dummy [1]= Variable (2);276 compress (dummy, M, N);277 CanonicalForm F= M (LCF);278 if (LCF.isUnivariate())279 {280 CFList result;281 int LCFLevel= LCF.level();282 bool found= false;283 if (LCFLevel == 2)284 {285 //bivariate leading coefficients are already the true leading coefficients286 result= LCFFactors;287 found= true;288 }289 else290 {291 CFListIterator j;292 for (int i= 0; i < length; i++)293 {294 for (j= differentSecondVarLCs[i]; j.hasItem(); j++)295 {296 if (j.getItem().level() == LCFLevel)297 {298 found= true;299 break;300 }301 }302 if (found)303 {304 result= differentSecondVarLCs [i];305 break;306 }307 }308 if (!found)309 result= LCFFactors;310 }311 if (found)312 result.insert (Lc (LCF));313 else314 {315 for (CFListIterator i= result; i.hasItem(); i++)316 i.getItem() *= LCF;317 result.insert (LCF);318 }319 return result;320 }321 322 CFList factors= LCFFactors;323 324 for (CFListIterator i= factors; i.hasItem(); i++)325 i.getItem()= M (i.getItem());326 327 CanonicalForm sqrfPartF;328 CFFList * bufSqrfFactors= new CFFList [factors.length()];329 CFList evalSqrfPartF, bufFactors;330 CFArray evalPoint= CFArray (evaluation.length() - 1);331 CFArray buf= CFArray (evaluation.length());332 CFArray swap= CFArray (evaluation.length());333 CFListIterator iter= evaluation;334 CanonicalForm vars=getVars (LCF)*Variable (2);335 for (int i= evaluation.length() +1; i > 1; i--, iter++)336 {337 buf[i-2]=iter.getItem();338 if (degree (vars, i) > 0)339 swap[M(Variable (i)).level()-1]=buf[i-2];340 }341 buf= swap;342 for (int i= 0; i < evaluation.length() - 1; i++)343 evalPoint[i]= buf[i+1];344 345 //TODO sqrfPartF einmal berechnen nicht stÀndig346 int pass= testFactors (F, factors, sqrfPartF,347 bufFactors, bufSqrfFactors, evalSqrfPartF, evalPoint);348 349 bool foundDifferent= false;350 Variable z;351 Variable x= y;352 int j= 0;353 if (!pass)354 {355 int lev= 0;356 CanonicalForm bufF;357 CFList bufBufFactors;358 for (int i= 0; i < length; i++)359 {360 if (!differentSecondVarLCs [i].isEmpty())361 {362 bool allConstant= true;363 for (iter= differentSecondVarLCs[i]; iter.hasItem(); iter++)364 {365 if (!iter.getItem().inCoeffDomain())366 {367 allConstant= false;368 y= Variable (iter.getItem().level());369 lev= M(y).level();370 }371 }372 if (allConstant)373 continue;374 375 bufFactors= differentSecondVarLCs [i];376 for (iter= bufFactors; iter.hasItem(); iter++)377 iter.getItem()= swapvar (iter.getItem(), x, y);378 bufF= F;379 z= Variable (lev);380 bufF= swapvar (bufF, x, z);381 bufBufFactors= bufFactors;382 evalPoint= CFArray (evaluation.length() - 1);383 for (int k= 0; k < evaluation.length()-1; k++)384 {385 if (N (Variable (k+1)).level() != y.level())386 evalPoint[k]= buf[k+1];387 else388 evalPoint[k]= buf[0];389 }390 pass= testFactors (bufF, bufBufFactors, sqrfPartF, bufFactors,391 bufSqrfFactors, evalSqrfPartF, evalPoint);392 if (pass)393 {394 foundDifferent= true;395 F= bufF;396 CFList l= factors;397 for (iter= l; iter.hasItem(); iter++)398 iter.getItem()= swapvar (iter.getItem(), x, y);399 differentSecondVarLCs [i]= l;400 j= i;401 break;402 }403 if (!pass && i == length - 1)404 {405 CFList result;406 result.append (LCF);407 for (int j= 1; j <= factors.length(); j++)408 result.append (1);409 result= distributeContent (result, differentSecondVarLCs, length);410 if (!result.getFirst().inCoeffDomain())411 {412 CFListIterator iter= result;413 CanonicalForm tmp= iter.getItem();414 iter++;415 for (; iter.hasItem(); iter++)416 iter.getItem() *= tmp;417 }418 419 y= Variable (1);420 delete [] bufSqrfFactors;421 return result;422 }423 }424 }425 }426 if (!pass)427 {428 CFList result;429 result.append (LCF);430 for (int j= 1; j <= factors.length(); j++)431 result.append (LCF);432 y= Variable (1);433 delete [] bufSqrfFactors;434 return result;435 }436 else437 factors= bufFactors;438 439 440 bufFactors= factors;441 442 CFMap MM, NN;443 dummy [0]= sqrfPartF;444 dummy [1]= 1;445 compress (dummy, MM, NN);446 sqrfPartF= MM (sqrfPartF);447 CanonicalForm varsSqrfPartF= getVars (sqrfPartF);448 for (CFListIterator iter= factors; iter.hasItem(); iter++)449 iter.getItem()= MM (iter.getItem());450 451 CFList evaluation2;452 for (int i= 2; i <= varsSqrfPartF.level(); i++)453 evaluation2.insert (evalPoint[NN (Variable (i)).level()-2]);454 455 CFList interMedResult;456 CanonicalForm oldSqrfPartF= sqrfPartF;457 sqrfPartF= shift2Zero (sqrfPartF, evalSqrfPartF, evaluation2);458 if (factors.length() > 1)459 {460 CanonicalForm LC1= LC (oldSqrfPartF, 1);461 CFList leadingCoeffs;462 for (int i= 0; i < factors.length(); i++)463 leadingCoeffs.append (LC1);464 465 CFList LC1eval= evaluateAtEval (LC1, evaluation2,2);466 CFList oldFactors= factors;467 for (CFListIterator i= oldFactors; i.hasItem(); i++)468 i.getItem() *= LC1eval.getFirst()/Lc (i.getItem());469 470 bool success= false;471 CanonicalForm oldSqrfPartFPowLC= oldSqrfPartF*power(LC1,factors.length()-1);472 CFList heuResult;473 if (size (oldSqrfPartFPowLC)/getNumVars (oldSqrfPartFPowLC) < 500 &&474 LucksWangSparseHeuristic (oldSqrfPartFPowLC,475 oldFactors, 2, leadingCoeffs, heuResult))476 {477 interMedResult= recoverFactors (oldSqrfPartF, heuResult);478 if (oldFactors.length() == interMedResult.length())479 success= true;480 }481 if (!success)482 {483 LC1= LC (evalSqrfPartF.getFirst(), 1);484 485 CFArray leadingCoeffs= CFArray (factors.length());486 for (int i= 0; i < factors.length(); i++)487 leadingCoeffs[i]= LC1;488 489 for (CFListIterator i= factors; i.hasItem(); i++)490 i.getItem() *= LC1 (0,2)/Lc (i.getItem());491 factors.insert (1);492 493 CanonicalForm494 newSqrfPartF= evalSqrfPartF.getFirst()*power (LC1, factors.length() - 2);495 496 int liftBound= degree (newSqrfPartF,2) + 1;497 498 CFMatrix M= CFMatrix (liftBound, factors.length() - 1);499 CFArray Pi;500 CFList diophant;501 nonMonicHenselLift12 (newSqrfPartF, factors, liftBound, Pi, diophant, M,502 leadingCoeffs, false);503 504 if (sqrfPartF.level() > 2)505 {506 int* liftBounds= new int [sqrfPartF.level() - 1];507 liftBounds [0]= liftBound;508 bool noOneToOne= false;509 CFList *leadingCoeffs2= new CFList [sqrfPartF.level()-2];510 LC1= LC (evalSqrfPartF.getLast(), 1);511 CFList LCs;512 for (int i= 0; i < factors.length(); i++)513 LCs.append (LC1);514 leadingCoeffs2 [sqrfPartF.level() - 3]= LCs;515 for (int i= sqrfPartF.level() - 1; i > 2; i--)516 {517 for (CFListIterator j= LCs; j.hasItem(); j++)518 j.getItem()= j.getItem() (0, i + 1);519 leadingCoeffs2 [i - 3]= LCs;520 }521 sqrfPartF *= power (LC1, factors.length()-1);522 523 int liftBoundsLength= sqrfPartF.level() - 1;524 for (int i= 1; i < liftBoundsLength; i++)525 liftBounds [i]= degree (sqrfPartF, i + 2) + 1;526 evalSqrfPartF= evaluateAtZero (sqrfPartF);527 evalSqrfPartF.removeFirst();528 factors= nonMonicHenselLift (evalSqrfPartF, factors, leadingCoeffs2,529 diophant, Pi, liftBounds, sqrfPartF.level() - 1, noOneToOne);530 delete [] leadingCoeffs2;531 delete [] liftBounds;532 }533 for (CFListIterator iter= factors; iter.hasItem(); iter++)534 iter.getItem()= reverseShift (iter.getItem(), evaluation2);535 536 interMedResult=537 recoverFactors (reverseShift(evalSqrfPartF.getLast(),evaluation2),538 factors);539 }540 }541 else542 {543 CanonicalForm contF=content (oldSqrfPartF,1);544 factors= CFList (oldSqrfPartF/contF);545 interMedResult= recoverFactors (oldSqrfPartF, factors);546 }547 548 for (CFListIterator iter= interMedResult; iter.hasItem(); iter++)549 iter.getItem()= NN (iter.getItem());550 551 CFList result;552 CFFListIterator k;553 CanonicalForm tmp;554 for (int i= 0; i < LCFFactors.length(); i++)555 {556 tmp= 1;557 for (k= bufSqrfFactors[i]; k.hasItem(); k++)558 {559 int pos= findItem (bufFactors, k.getItem().factor());560 if (pos)561 tmp *= power (getItem (interMedResult, pos), k.getItem().exp());562 }563 result.append (tmp);564 }565 566 for (CFListIterator i= result; i.hasItem(); i++)567 {568 F /= i.getItem();569 if (foundDifferent)570 i.getItem()= swapvar (i.getItem(), x, z);571 i.getItem()= N (i.getItem());572 }573 574 if (foundDifferent)575 {576 CFList l= differentSecondVarLCs [j];577 for (CFListIterator i= l; i.hasItem(); i++)578 i.getItem()= swapvar (i.getItem(), y, z);579 differentSecondVarLCs [j]= l;580 F= swapvar (F, x, z);581 }582 583 result.insert (N (F));584 585 result= distributeContent (result, differentSecondVarLCs, length);586 587 if (!result.getFirst().inCoeffDomain())588 {589 CFListIterator i= result;590 CanonicalForm tmp;591 if (foundDifferent)592 i.getItem()= swapvar (i.getItem(), Variable (2), y);593 594 tmp= i.getItem();595 596 i++;597 for (; i.hasItem(); i++)598 {599 if (foundDifferent)600 i.getItem()= swapvar (i.getItem(), Variable (2), y)*tmp;601 else602 i.getItem() *= tmp;603 }604 }605 else606 y= Variable (1);607 608 delete [] bufSqrfFactors;609 610 return result;611 }612 613 164 614 165 CFList … … 618 169 return CFList (F); 619 170 171 TIMING_START (fac_preprocess_and_content); 620 172 // compress and find main Variable 621 173 CFMap N; 174 TIMING_START (fac_compress) 622 175 CanonicalForm A= myCompress (F, N); 176 TIMING_END_AND_PRINT (fac_compress, "time to compress poly over Q: ") 623 177 624 178 //univariate case … … 646 200 647 201 // remove content 202 TIMING_START (fac_content); 648 203 CFList contentAi; 649 204 CanonicalForm lcmCont= lcmContent (A, contentAi); 650 205 A /= lcmCont; 206 TIMING_END_AND_PRINT (fac_content, "time to extract content over Q: "); 651 207 652 208 // trivial after content removal … … 674 230 675 231 // factorize content 232 TIMING_START (fac_content); 676 233 contentAFactors= multiFactorize (lcmCont, v); 234 TIMING_END_AND_PRINT (fac_content, "time to factor content over Q: "); 677 235 678 236 // univariate after content removal … … 690 248 691 249 A *= bCommonDen (A); 692 // check main variable693 250 CFList Aeval, list, evaluation, bufEvaluation, bufAeval; 694 251 int factorNums= 1; 695 CanonicalForm bivarEval;696 252 CFList biFactors, bufBiFactors; 697 253 CanonicalForm evalPoly; … … 702 258 int differentSecondVar= 0; 703 259 CanonicalForm bufA; 260 TIMING_END_AND_PRINT (fac_preprocess_and_content, 261 "time to preprocess poly and extract content over Q: "); 262 704 263 // several bivariate factorizations 264 TIMING_START (fac_bifactor_total); 705 265 REvaluation E (2, A.level(), IntRandom (25)); 706 266 for (int i= 0; i < factorNums; i++) … … 709 269 bufA= A; 710 270 bufAeval= CFList(); 271 TIMING_START (fac_evaluation); 711 272 bufEvaluation= evalPoints (bufA, bufAeval, E); 273 TIMING_END_AND_PRINT (fac_evaluation, 274 "time to find evaluation point over Q: "); 712 275 E.nextpoint(); 713 276 evalPoly= 0; 714 277 715 bivarEval= bufEvaluation.getLast(); 716 278 TIMING_START (fac_evaluation); 717 279 evaluationWRTDifferentSecondVars (bufAeval2, bufEvaluation, A); 280 TIMING_END_AND_PRINT (fac_evaluation, 281 "time to eval wrt diff second vars over Q: "); 718 282 719 283 for (int j= 0; j < lengthAeval2; j++) … … 725 289 bufLift= degree (A, y) + 1 + degree (LC(A, x), y); 726 290 727 TIMING_START (fac_bi_factorize );291 TIMING_START (fac_bi_factorizer); 728 292 bufBiFactors= ratBiSqrfFactorize (bufAeval.getFirst(), v); 729 TIMING_END_AND_PRINT (fac_bi_factorize ,293 TIMING_END_AND_PRINT (fac_bi_factorizer, 730 294 "time for bivariate factorization: "); 731 295 bufBiFactors.removeFirst(); … … 779 343 int minFactorsLength; 780 344 bool irred= false; 345 TIMING_START (fac_bi_factorizer); 781 346 factorizationWRTDifferentSecondVars (A, Aeval2, minFactorsLength, irred, v); 782 347 TIMING_END_AND_PRINT (fac_bi_factorizer, 348 "time for bivariate factorization wrt diff second vars over Q: "); 349 350 TIMING_END_AND_PRINT (fac_bifactor_total, 351 "total time for eval and bivar factors over Q: "); 783 352 if (irred) 784 353 { … … 839 408 840 409 Variable w; 841 CFList leadingCoeffs= precomputeLeadingCoeff (LC (A, 1), biFactorsLCs, 410 TIMING_START (fac_precompute_leadcoeff); 411 CFList leadingCoeffs= precomputeLeadingCoeff (LC (A, 1), biFactorsLCs, x, 842 412 evaluation, Aeval2, lengthAeval2, w); 843 413 … … 940 510 } 941 511 } 512 TIMING_END_AND_PRINT(fac_precompute_leadcoeff, 513 "time to precompute LC over Q: "); 514 515 TIMING_START (fac_luckswang); 942 516 CFList bufFactors= CFList(); 943 517 bool LCheuristic= false; … … 962 536 delete [] index; 963 537 delete [] Aeval2; 538 TIMING_END_AND_PRINT (fac_luckswang, 539 "time for successful LucksWang over Q: "); 964 540 return factors; 965 541 } … … 1300 876 delete [] index; 1301 877 } 878 TIMING_END_AND_PRINT (fac_luckswang, "time for LucksWang over Q: "); 879 880 TIMING_START (fac_lcheuristic); 1302 881 if (!LCheuristic && !LCmultiplierIsConst && bufFactors.isEmpty() 1303 882 && fdivides (getVars (LCmultiplier), testVars)) … … 1449 1028 } 1450 1029 } 1030 TIMING_END_AND_PRINT (fac_lcheuristic, "time for Lc heuristic over Q: "); 1451 1031 1452 1032 tryAgainWithoutHeu: 1453 1033 //shifting to zero 1034 TIMING_START (fac_shift_to_zero); 1035 CanonicalForm denA= bCommonDen (A); 1036 A *= denA; 1454 1037 A= shift2Zero (A, Aeval, evaluation); 1038 A /= denA; 1455 1039 1456 1040 for (iter= biFactors; iter.hasItem(); iter++) … … 1470 1054 } 1471 1055 } 1056 TIMING_END_AND_PRINT (fac_shift_to_zero, 1057 "time to shift evaluation point to zero: "); 1472 1058 1473 1059 CFArray Pi; … … 1481 1067 bool noOneToOne= false; 1482 1068 1069 TIMING_START (fac_cleardenom); 1483 1070 CFList commonDenominators; 1484 1071 for (iter=biFactors; iter.hasItem(); iter++) … … 1499 1086 for (iter= Aeval; iter.hasItem(); iter++) 1500 1087 { 1501 tmp2= bCommonDen (iter.getItem() );1088 tmp2= bCommonDen (iter.getItem()/denA); 1502 1089 Off (SW_RATIONAL); 1503 1090 tmp3= lcm (tmp2,tmp3); … … 1511 1098 1512 1099 for (iter= Aeval; iter.hasItem(); iter++) 1513 iter.getItem() *= tmp3*power (multiplier, biFactors.length() - 1) ;1100 iter.getItem() *= tmp3*power (multiplier, biFactors.length() - 1)/denA; 1514 1101 1515 1102 for (int i= 0; i < lengthAeval2; i++) … … 1519 1106 iter.getItem() *= iter2.getItem()*multiplier; 1520 1107 } 1521 1522 1108 TIMING_END_AND_PRINT (fac_cleardenom, "time to clear denominators: "); 1109 1110 TIMING_START (fac_hensel_lift); 1523 1111 factors= nonMonicHenselLift (Aeval, biFactors, leadingCoeffs2, diophant, 1524 1112 Pi, liftBounds, liftBoundsLength, noOneToOne); 1113 TIMING_END_AND_PRINT (fac_hensel_lift, 1114 "time for non monic hensel lifting over Q: "); 1525 1115 1526 1116 if (!noOneToOne) … … 1528 1118 int check= factors.length(); 1529 1119 A= oldA; 1120 TIMING_START (fac_recover_factors); 1530 1121 factors= recoverFactors (A, factors, evaluation); 1122 TIMING_END_AND_PRINT (fac_recover_factors, 1123 "time to recover factors over Q: "); 1531 1124 if (check != factors.length()) 1532 1125 noOneToOne= true; -
factory/facFactorize.h
rbecbea r1130ffc 14 14 #define FAC_FACTORIZE_H 15 15 16 // #include "config.h" 16 #include "config.h" 17 #include "timing.h" 17 18 18 19 #include "facBivar.h" 19 20 #include "facFqBivarUtil.h" 21 22 TIMING_DEFINE_PRINT (fac_squarefree) 23 TIMING_DEFINE_PRINT (fac_factor_squarefree) 20 24 21 25 /// Factorization over Q (a) … … 120 124 121 125 CFFList result; 126 TIMING_START (fac_squarefree); 122 127 CFFList sqrfFactors= sqrFree (F); 128 TIMING_END_AND_PRINT (fac_squarefree, 129 "time for squarefree factorization over Q: "); 130 131 CFList tmp; 123 132 for (CFFListIterator i= sqrfFactors; i.hasItem(); i++) 124 133 { 125 CFList tmp= ratSqrfFactorize (i.getItem().factor(), v); 134 TIMING_START (fac_factor_squarefree); 135 tmp= ratSqrfFactorize (i.getItem().factor(), v); 136 TIMING_END_AND_PRINT (fac_factor_squarefree, 137 "time to factorize sqrfree factor over Q: "); 126 138 for (CFListIterator j= tmp; j.hasItem(); j++) 127 139 { -
factory/facFqBivar.cc
rbecbea r1130ffc 46 46 TIMING_DEFINE_PRINT(fac_fq_bi_hensel_lift) 47 47 TIMING_DEFINE_PRINT(fac_fq_bi_factor_recombination) 48 TIMING_DEFINE_PRINT(fac_fq_bi_evaluation) 49 TIMING_DEFINE_PRINT(fac_fq_bi_shift_to_zero) 48 50 49 51 CanonicalForm prodMod0 (const CFList& L, const CanonicalForm& M, const modpk& b) … … 6082 6084 { 6083 6085 bufAeval= A; 6086 TIMING_START (fac_fq_bi_evaluation); 6084 6087 bufEvaluation= evalPoint (A, bufAeval, alpha, list, GF, fail); 6088 TIMING_END_AND_PRINT (fac_fq_bi_evaluation, "time to find eval point: "); 6085 6089 if (!derivXZero && !fail2 && !symmetric) 6086 6090 { … … 6091 6095 } 6092 6096 bufAeval2= buf; 6097 TIMING_START (fac_fq_bi_evaluation); 6093 6098 bufEvaluation2= evalPoint (buf, bufAeval2, alpha, list2, GF, fail2); 6099 TIMING_END_AND_PRINT (fac_fq_bi_evaluation, 6100 "time to find eval point wrt y: "); 6094 6101 } 6095 6102 // first try to change main variable if there is no valid evaluation point … … 6132 6139 bufUniFactors= uniFactorizer (bufAeval, alpha, GF); 6133 6140 TIMING_END_AND_PRINT (fac_fq_uni_factorizer, 6134 "time for univariate factorization : ");6141 "time for univariate factorization over Fq: "); 6135 6142 DEBOUTLN (cerr, "Lc (bufAeval)*prod (bufUniFactors)== bufAeval " << 6136 6143 (prod (bufUniFactors)*Lc (bufAeval) == bufAeval)); … … 6141 6148 bufUniFactors2= uniFactorizer (bufAeval2, alpha, GF); 6142 6149 TIMING_END_AND_PRINT (fac_fq_uni_factorizer, 6143 "time for univariate factorization in y : ");6150 "time for univariate factorization in y over Fq: "); 6144 6151 DEBOUTLN (cerr, "Lc (bufAeval2)*prod (bufUniFactors2)== bufAeval2 " << 6145 6152 (prod (bufUniFactors2)*Lc (bufAeval2) == bufAeval2)); … … 6291 6298 } 6292 6299 6300 TIMING_START (fac_fq_bi_shift_to_zero); 6293 6301 A= A (y + evaluation, y); 6302 TIMING_END_AND_PRINT (fac_fq_bi_shift_to_zero, 6303 "time to shift eval to zero: "); 6294 6304 6295 6305 int degMipo= 1; … … 6307 6317 (A, earlySuccess, earlyFactors, degs, liftBound, 6308 6318 uniFactors, info, evaluation); 6309 TIMING_END_AND_PRINT (fac_fq_bi_hensel_lift, "time for hensel lifting: "); 6319 TIMING_END_AND_PRINT (fac_fq_bi_hensel_lift, 6320 "time for bivariate hensel lifting over Fq: "); 6310 6321 DEBOUTLN (cerr, "lifted factors= " << uniFactors); 6311 6322 6312 6323 CanonicalForm MODl= power (y, liftBound); 6313 6324 6325 TIMING_START (fac_fq_bi_factor_recombination); 6314 6326 if (extension) 6315 6327 factors= extFactorRecombination (uniFactors, A, MODl, info, degs, … … 6318 6330 factors= factorRecombination (uniFactors, A, MODl, degs, 1, 6319 6331 uniFactors.length()/2); 6332 TIMING_END_AND_PRINT (fac_fq_bi_factor_recombination, 6333 "time for naive bivariate factor recombi over Fq: "); 6320 6334 6321 6335 if (earlySuccess) … … 6346 6360 factors= Union (lll, factors); 6347 6361 } 6348 TIMING_END_AND_PRINT (fac_fq_bi_hensel_lift, "time for hensel lifting: "); 6362 TIMING_END_AND_PRINT (fac_fq_bi_hensel_lift, 6363 "time to bivar lift and LLL recombi over Fq: "); 6349 6364 DEBOUTLN (cerr, "lifted factors= " << uniFactors); 6350 6365 } … … 6357 6372 (A, earlySuccess, earlyFactors, degs, liftBound, 6358 6373 uniFactors, info, evaluation); 6359 TIMING_END_AND_PRINT (fac_fq_bi_hensel_lift, "time for hensel lifting: "); 6374 TIMING_END_AND_PRINT (fac_fq_bi_hensel_lift, 6375 "time for bivar hensel lifting over Fq: "); 6360 6376 DEBOUTLN (cerr, "lifted factors= " << uniFactors); 6361 6377 … … 6363 6379 if (!extension) 6364 6380 { 6381 TIMING_START (fac_fq_bi_factor_recombination); 6365 6382 factors= factorRecombination (uniFactors, A, MODl, degs, 1, 3); 6383 TIMING_END_AND_PRINT (fac_fq_bi_factor_recombination, 6384 "time for small subset naive recombi over Fq: "); 6366 6385 6367 6386 int oldUniFactorsLength= uniFactors.length(); … … 6369 6388 { 6370 6389 CFList tmp; 6390 TIMING_START (fac_fq_bi_hensel_lift); 6371 6391 if (alpha.level() == 1) 6372 6392 tmp= increasePrecision (A, uniFactors, 0, uniFactors.length(), 1, … … 6384 6404 ); 6385 6405 } 6406 TIMING_END_AND_PRINT (fac_fq_bi_hensel_lift, 6407 "time to increase precision: "); 6386 6408 factors= Union (factors, tmp); 6387 6409 if (tmp.length() == 0 || (tmp.length() > 0 && uniFactors.length() != 0 -
factory/facFqBivar.h
rbecbea r1130ffc 15 15 #define FAC_FQ_BIVAR_H 16 16 17 // #include "config.h" 18 17 #include "config.h" 18 19 #include "timing.h" 19 20 #include "cf_assert.h" 20 21 … … 26 27 #include "cf_map.h" 27 28 #include "cfNewtonPolygon.h" 29 30 TIMING_DEFINE_PRINT(fac_fq_bi_sqrf) 31 TIMING_DEFINE_PRINT(fac_fq_bi_factor_sqrf) 28 32 29 33 static const double log2exp= 1.442695041; … … 273 277 F= compress (F, M, S); 274 278 279 TIMING_START (fac_fq_bi_sqrf); 275 280 CFFList sqrf= FpSqrf (F, false); 281 TIMING_END_AND_PRINT (fac_fq_bi_sqrf, 282 "time for bivariate sqrf factors over Fp: "); 276 283 CFList bufResult; 277 284 sqrf.removeFirst(); … … 279 286 for (CFFListIterator iter= sqrf; iter.hasItem(); iter++) 280 287 { 288 TIMING_START (fac_fq_bi_factor_sqrf); 281 289 bufResult= biFactorize (iter.getItem().factor(), info); 290 TIMING_END_AND_PRINT (fac_fq_bi_factor_sqrf, 291 "time to factor bivariate sqrf factors over Fp: "); 282 292 for (i= bufResult; i.hasItem(); i++) 283 293 result.append (CFFactor (N (decompress (i.getItem(), M, S)), … … 374 384 F= compress (F, M, S); 375 385 386 TIMING_START (fac_fq_bi_sqrf); 376 387 CFFList sqrf= FqSqrf (F, alpha, false); 388 TIMING_END_AND_PRINT (fac_fq_bi_sqrf, 389 "time for bivariate sqrf factors over Fq: "); 377 390 CFList bufResult; 378 391 sqrf.removeFirst(); … … 380 393 for (CFFListIterator iter= sqrf; iter.hasItem(); iter++) 381 394 { 395 TIMING_START (fac_fq_bi_factor_sqrf); 382 396 bufResult= biFactorize (iter.getItem().factor(), info); 397 TIMING_END_AND_PRINT (fac_fq_bi_factor_sqrf, 398 "time to factor bivariate sqrf factors over Fq: "); 383 399 for (i= bufResult; i.hasItem(); i++) 384 400 result.append (CFFactor (N (decompress (i.getItem(), M, S)), … … 476 492 F= compress (F, M, S); 477 493 494 TIMING_START (fac_fq_bi_sqrf); 478 495 CFFList sqrf= GFSqrf (F, false); 496 TIMING_END_AND_PRINT (fac_fq_bi_sqrf, 497 "time for bivariate sqrf factors over GF: "); 479 498 CFList bufResult; 480 499 sqrf.removeFirst(); … … 482 501 for (CFFListIterator iter= sqrf; iter.hasItem(); iter++) 483 502 { 503 TIMING_START (fac_fq_bi_factor_sqrf); 484 504 bufResult= biFactorize (iter.getItem().factor(), info); 505 TIMING_END_AND_PRINT (fac_fq_bi_factor_sqrf, 506 "time to factor bivariate sqrf factors over GF: "); 485 507 for (i= bufResult; i.hasItem(); i++) 486 508 result.append (CFFactor (N (decompress (i.getItem(), M, S)), -
factory/facFqFactorize.cc
rbecbea r1130ffc 38 38 TIMING_DEFINE_PRINT(fac_fq_hensel_lift) 39 39 TIMING_DEFINE_PRINT(fac_fq_factor_recombination) 40 TIMING_DEFINE_PRINT(fac_fq_shift_to_zero) 41 TIMING_DEFINE_PRINT(fac_fq_precompute_leadcoeff) 42 TIMING_DEFINE_PRINT(fac_fq_evaluation) 43 TIMING_DEFINE_PRINT(fac_fq_recover_factors) 44 TIMING_DEFINE_PRINT(fac_fq_preprocess_and_content) 45 TIMING_DEFINE_PRINT(fac_fq_bifactor_total) 46 TIMING_DEFINE_PRINT(fac_fq_luckswang) 47 TIMING_DEFINE_PRINT(fac_fq_lcheuristic) 48 TIMING_DEFINE_PRINT(fac_fq_content) 49 TIMING_DEFINE_PRINT(fac_fq_check_mainvar) 50 TIMING_DEFINE_PRINT(fac_fq_compress) 40 51 41 52 static inline … … 894 905 { 895 906 int i= A.level(); 896 contentAi.append (myContent (A, i)); 897 contentAi.append (myContent (A, i - 1)); 907 CanonicalForm buf= A; 908 contentAi.append (content (buf, i)); 909 buf /= contentAi.getLast(); 910 contentAi.append (content (buf, i - 1)); 898 911 CanonicalForm result= lcm (contentAi.getFirst(), contentAi.getLast()); 899 912 for (i= i - 2; i > 0; i--) 900 913 { 901 contentAi.append (content (A, i)); 914 contentAi.append (content (buf, i)); 915 buf /= contentAi.getLast(); 902 916 result= lcm (result, contentAi.getLast()); 903 917 } … … 1327 1341 1328 1342 CanonicalForm F= G; 1329 CFFList sqrfFactorization= squarefreeFactorization (F, alpha); 1343 CFFList sqrfFactorization; 1344 if (getCharacteristic() > 0) 1345 sqrfFactorization= squarefreeFactorization (F, alpha); 1346 else 1347 sqrfFactorization= sqrFree (F); 1330 1348 1331 1349 sqrfPartF= 1; … … 1348 1366 { 1349 1367 tmp= 1; 1350 sqrfFactors= squarefreeFactorization (i.getItem(), alpha); 1368 if (getCharacteristic() > 0) 1369 sqrfFactors= squarefreeFactorization (i.getItem(), alpha); 1370 else 1371 sqrfFactors= sqrFree (i.getItem()); 1351 1372 1352 1373 for (iter= sqrfFactors; iter.hasItem(); iter++) … … 2189 2210 return CFList (F); 2190 2211 2212 TIMING_START (fac_fq_preprocess_and_content); 2191 2213 // compress and find main Variable 2192 2214 CFMap N; 2215 TIMING_START (fac_fq_compress) 2193 2216 CanonicalForm A= myCompress (F, N); 2217 TIMING_END_AND_PRINT (fac_fq_compress, "time to compress poly over Fq: ") 2194 2218 2195 2219 A /= Lc (A); // make monic … … 2225 2249 2226 2250 // remove content 2251 TIMING_START (fac_fq_content); 2227 2252 CFList contentAi; 2228 2253 CanonicalForm lcmCont= lcmContent (A, contentAi); 2229 2254 A /= lcmCont; 2255 TIMING_END_AND_PRINT (fac_fq_content, "time to extract content over Fq: "); 2230 2256 2231 2257 // trivial after content removal … … 2253 2279 2254 2280 // factorize content 2281 TIMING_START (fac_fq_content); 2255 2282 contentAFactors= multiFactorize (lcmCont, info); 2283 TIMING_END_AND_PRINT (fac_fq_content, "time to factor content over Fq: "); 2256 2284 2257 2285 // univariate after content removal … … 2266 2294 2267 2295 // check main variable 2296 TIMING_START (fac_fq_check_mainvar); 2268 2297 int swapLevel= 0; 2269 2298 CanonicalForm derivZ; … … 2308 2337 } 2309 2338 } 2310 2339 TIMING_END_AND_PRINT (fac_fq_check_mainvar, 2340 "time to check main var over Fq: "); 2341 TIMING_END_AND_PRINT (fac_fq_preprocess_and_content, 2342 "time to preprocess poly and extract content over Fq: "); 2311 2343 2312 2344 CFList Aeval, list, evaluation, bufEvaluation, bufAeval; … … 2315 2347 int level; 2316 2348 int factorNums= 3; 2317 CanonicalForm bivarEval;2318 2349 CFList biFactors, bufBiFactors; 2319 2350 CanonicalForm evalPoly; … … 2329 2360 int differentSecondVar= 0; 2330 2361 // several bivariate factorizations 2362 TIMING_START (fac_fq_bifactor_total); 2331 2363 for (int i= 0; i < factorNums; i++) 2332 2364 { … … 2334 2366 bufA= A; 2335 2367 bufAeval= CFList(); 2368 TIMING_START (fac_fq_evaluation); 2336 2369 bufEvaluation= evalPoints (bufA, bufAeval, alpha, list, GF, fail); 2370 TIMING_END_AND_PRINT (fac_fq_evaluation, 2371 "time to find evaluation point over Fq: "); 2337 2372 evalPoly= 0; 2338 2373 … … 2379 2414 break; 2380 2415 2381 bivarEval= bufEvaluation.getLast(); 2382 2416 TIMING_START (fac_fq_evaluation); 2383 2417 evaluationWRTDifferentSecondVars (bufAeval2, bufEvaluation, A); 2418 TIMING_END_AND_PRINT (fac_fq_evaluation, 2419 "time for evaluation wrt diff second vars over Fq: "); 2384 2420 2385 2421 for (int j= 0; j < lengthAeval2; j++) … … 2456 2492 int minFactorsLength; 2457 2493 bool irred= false; 2494 TIMING_START (fac_fq_bi_factorizer); 2458 2495 factorizationWRTDifferentSecondVars (A, Aeval2, info, minFactorsLength,irred); 2459 2496 TIMING_END_AND_PRINT (fac_fq_bi_factorizer, 2497 "time for bivariate factorization wrt diff second vars over Fq: "); 2498 2499 TIMING_END_AND_PRINT (fac_fq_bifactor_total, 2500 "total time for eval and bivar factors over Fq: "); 2460 2501 if (irred) 2461 2502 { … … 2528 2569 2529 2570 Variable v; 2571 TIMING_START (fac_fq_precompute_leadcoeff); 2530 2572 CFList leadingCoeffs= precomputeLeadingCoeff (LC (A, 1), biFactorsLCs, alpha, 2531 2573 evaluation, Aeval2, lengthAeval2, v); … … 2627 2669 } 2628 2670 } 2671 TIMING_END_AND_PRINT(fac_fq_precompute_leadcoeff, 2672 "time to precompute LC over Fq: "); 2673 2674 TIMING_START (fac_fq_luckswang); 2629 2675 CFList bufFactors= CFList(); 2630 2676 bool LCheuristic= false; … … 2654 2700 delete [] index; 2655 2701 delete [] Aeval2; 2702 TIMING_END_AND_PRINT (fac_fq_luckswang, 2703 "time for successful LucksWang over Fq: "); 2656 2704 return factors; 2657 2705 } … … 2993 3041 delete [] index; 2994 3042 } 2995 3043 TIMING_END_AND_PRINT (fac_fq_luckswang, "time for LucksWang over Fq: "); 3044 3045 TIMING_START (fac_fq_lcheuristic); 2996 3046 if (!LCheuristic && !LCmultiplierIsConst && bufFactors.isEmpty() 2997 3047 && fdivides (getVars (LCmultiplier), testVars)) … … 3143 3193 } 3144 3194 } 3195 TIMING_END_AND_PRINT (fac_fq_lcheuristic, "time for Lc heuristic over Fq: "); 3145 3196 3146 3197 tryAgainWithoutHeu: 3198 TIMING_START (fac_fq_shift_to_zero); 3147 3199 A= shift2Zero (A, Aeval, evaluation); 3148 3200 … … 3163 3215 } 3164 3216 } 3217 TIMING_END_AND_PRINT (fac_fq_shift_to_zero, 3218 "time to shift evaluation point to zero: "); 3165 3219 3166 3220 CFArray Pi; … … 3173 3227 Aeval.removeFirst(); 3174 3228 bool noOneToOne= false; 3229 TIMING_START (fac_fq_hensel_lift); 3175 3230 factors= nonMonicHenselLift (Aeval, biFactors, leadingCoeffs2, diophant, 3176 3231 Pi, liftBounds, liftBoundsLength, noOneToOne); 3232 TIMING_END_AND_PRINT (fac_fq_hensel_lift, 3233 "time for non monic hensel lifting over Fq: "); 3177 3234 3178 3235 if (!noOneToOne) … … 3180 3237 int check= factors.length(); 3181 3238 A= oldA; 3239 TIMING_START (fac_fq_recover_factors); 3182 3240 factors= recoverFactors (A, factors, evaluation); 3241 TIMING_END_AND_PRINT (fac_fq_recover_factors, 3242 "time to recover factors over Fq: "); 3183 3243 if (check != factors.length()) 3184 3244 noOneToOne= true; … … 3239 3299 (A, MOD, liftBounds, earlySuccess, earlyFactors, 3240 3300 Aeval, biFactors, evaluation, info); 3241 TIMING_END_AND_PRINT (fac_fq_hensel_lift, "time for hensel lifting: "); 3301 TIMING_END_AND_PRINT (fac_fq_hensel_lift, 3302 "time for hensel lifting over Fq: "); 3242 3303 3243 3304 if (!extension) -
factory/facFqFactorize.h
rbecbea r1130ffc 15 15 #define FAC_FQ_FACTORIZE_H 16 16 17 // #include "config.h" 17 #include "config.h" 18 #include "timing.h" 18 19 19 20 #include "facFqBivar.h" … … 23 24 #include "facFqSquarefree.h" 24 25 #include "facFqBivarUtil.h" 26 27 28 TIMING_DEFINE_PRINT (fac_fq_squarefree) 29 TIMING_DEFINE_PRINT (fac_fq_factor_squarefree) 25 30 26 31 /// Factorization over a finite field … … 150 155 Variable a= Variable (1); 151 156 CanonicalForm LcF= Lc (F); 157 TIMING_START (fac_fq_squarefree); 152 158 CFFList sqrf= FpSqrf (F, false); 159 TIMING_END_AND_PRINT (fac_fq_squarefree, 160 "time for squarefree factorization over Fq: "); 153 161 CFFList result; 154 162 CFList bufResult; … … 157 165 for (CFFListIterator iter= sqrf; iter.hasItem(); iter++) 158 166 { 167 TIMING_START (fac_fq_factor_squarefree); 159 168 bufResult= multiFactorize (iter.getItem().factor(), info); 169 TIMING_END_AND_PRINT (fac_fq_factor_squarefree, 170 "time to factorize sqrfree factor over Fq: "); 160 171 for (i= bufResult; i.hasItem(); i++) 161 172 result.append (CFFactor (i.getItem(), iter.getItem().exp())); … … 227 238 ExtensionInfo info= ExtensionInfo (alpha, false); 228 239 CanonicalForm LcF= Lc (F); 240 TIMING_START (fac_fq_squarefree); 229 241 CFFList sqrf= FqSqrf (F, alpha, false); 242 TIMING_END_AND_PRINT (fac_fq_squarefree, 243 "time for squarefree factorization over Fq: "); 230 244 CFFList result; 231 245 CFList bufResult; … … 234 248 for (CFFListIterator iter= sqrf; iter.hasItem(); iter++) 235 249 { 250 TIMING_START (fac_fq_factor_squarefree); 236 251 bufResult= multiFactorize (iter.getItem().factor(), info); 252 TIMING_END_AND_PRINT (fac_fq_factor_squarefree, 253 "time to factorize sqrfree factor over Fq: "); 237 254 for (i= bufResult; i.hasItem(); i++) 238 255 result.append (CFFactor (i.getItem(), iter.getItem().exp())); … … 640 657 ); 641 658 659 /// computes a list l of length length(LCFFactors)+1 of polynomials such that 660 /// prod (l)=LCF, note that the first entry of l may be non constant. Intended 661 /// to be used to precompute coefficients of a polynomial f from its bivariate 662 /// factorizations. 663 /// 664 /// @return see above 665 CFList 666 precomputeLeadingCoeff (const CanonicalForm& LCF, ///<[in] a multivariate 667 ///< poly 668 const CFList& LCFFactors, ///<[in] a list of 669 ///< univariate factors 670 ///< of LCF of level 2 671 const Variable& alpha, ///<[in] algebraic var. 672 const CFList& evaluation, ///<[in] an evaluation 673 ///< point having 674 ///< lSecondVarLCs+1 675 ///< components 676 CFList* & differentSecondVarLCs,///<[in] LCs of factors 677 ///< of f wrt different 678 ///< second variables 679 int lSecondVarLCs, ///<[in] length of the 680 ///< above 681 Variable& y ///<[in,out] if y.level() 682 ///< is not 1 on output 683 ///< the second variable 684 ///< has been changed to 685 ///< y 686 ); 687 642 688 #endif 643 689 /* FAC_FQ_FACTORIZE_H */ -
factory/fac_ezgcd.cc
rbecbea r1130ffc 15 15 #include "config.h" 16 16 17 #include "timing.h" 17 18 #include "cf_assert.h" 18 19 #include "debug.h" … … 30 31 31 32 #ifdef HAVE_NTL 33 34 TIMING_DEFINE_PRINT(ez_eval) 35 TIMING_DEFINE_PRINT(ez_compress) 36 TIMING_DEFINE_PRINT(ez_hensel_lift) 37 TIMING_DEFINE_PRINT(ez_content) 38 TIMING_DEFINE_PRINT(ez_termination) 39 32 40 static 33 41 int compress4EZGCD (const CanonicalForm& F, const CanonicalForm& G, CFMap & M, … … 432 440 Off (SW_RATIONAL); 433 441 442 TIMING_START (ez_compress) 434 443 CFMap M,N; 435 444 int smallestDegLev; … … 444 453 F= M (F); 445 454 G= M (G); 455 TIMING_END_AND_PRINT (ez_compress, "time for compression in EZ: ") 446 456 447 457 DEBINCLEVEL( cerr, "ezgcd" ); 448 458 DEBOUTLN( cerr, "FF = " << FF ); 449 459 DEBOUTLN( cerr, "GG = " << GG ); 460 TIMING_START (ez_content) 450 461 f = content( F, x ); g = content( G, x ); d = gcd( f, g ); 451 462 d /= icontent (d); … … 453 464 DEBOUTLN( cerr, "g = " << g ); 454 465 F /= f; G /= g; 466 TIMING_END_AND_PRINT (ez_content, "time to extract content in EZ: ") 455 467 if ( F.isUnivariate() && G.isUnivariate() ) 456 468 { … … 500 512 DEBOUTLN( cerr, "F = " << F ); 501 513 DEBOUTLN( cerr, "G = " << G ); 514 TIMING_START (ez_eval) 502 515 if (!findeval( F, G, Fb, Gb, Db, b, delta, degF, degG, maxeval, count, 503 516 o, 25, l)) … … 512 525 return N (d*result); 513 526 } 527 TIMING_END_AND_PRINT (ez_eval, "time to find eval point in EZ1: ") 514 528 DEBOUTLN( cerr, "found evaluation b = " << b ); 515 529 DEBOUTLN( cerr, "F(b) = " << Fb ); … … 530 544 { 531 545 bt = b; 546 TIMING_START (ez_eval) 532 547 if (!findeval( F, G, Fbt, Gbt, Dbt, bt, delta, degF, degG, maxeval, count, 533 548 o, 25,l )) … … 542 557 return N (d*result); 543 558 } 559 TIMING_END_AND_PRINT (ez_eval, "time to find eval point in EZ2: ") 544 560 int dd=degree( Dbt ); 545 561 if ( dd /*degree( Dbt )*/ == 0 ) … … 636 652 DEBOUTLN( cerr, "(hensel) DD = " << DD ); 637 653 DEBOUTLN( cerr, "(hensel) lcDD = " << lcDD ); 654 TIMING_START (ez_hensel_lift) 638 655 gcdfound= Hensel (B*lcD, DD, b, lcDD); 656 TIMING_END_AND_PRINT (ez_hensel_lift, "time to hensel lift in EZ: ") 639 657 DEBOUTLN( cerr, "(hensel finished) DD = " << DD ); 640 658 … … 653 671 if (gcdfound) 654 672 { 673 TIMING_START (ez_termination) 655 674 contcand= content (DD[2], Variable (1)); 656 675 cand = DD[2] / contcand; … … 659 678 else 660 679 gcdfound = fdivides( cand, F ) && cand*(DD[1]/(lcD/contcand)) == G; 680 TIMING_END_AND_PRINT (ez_termination, 681 "time for termination test in EZ: ") 661 682 } 662 683 /// ---> A8 (gcdfound) -
factory/libfac/factor/timing.h
rbecbea r1130ffc 43 43 #if defined(WINNT) && ! defined(__GNUC__) 44 44 45 #define TIMING_START(t) { clock_t timing_ ## t ## _start, timing_ ## t ## _end; \ 46 timing_ ## t ## _start = clock(); 45 #define TIMING_START(t) timing_ ## t ## _start = clock(); 47 46 #define TIMING_END(t) timing_ ## t ## _end = clock(); \ 48 timing_ ## t ## _time += timing_ ## t ## _end - timing_ ## t ## _start; }47 timing_ ## t ## _time += timing_ ## t ## _end - timing_ ## t ## _start; 49 48 #define TIMING_END_AND_PRINT(t, msg) times( &timing_ ## t ## _end ); \ 50 49 fprintf( stderr, "%s%.2f sec\n", msg, \ 51 50 float( timing_ ## t ## _end - timing_ ## t ## _start ) / HZ ); \ 52 timing_ ## t ## _time += timing_ ## t ## _end - timing_ ## t ## _start; } 53 #define TIMING_DEFINE_PRINT(t) clock_t timing_ ## t ## _time; \ 54 void timing_print_ ## t ( char * msg ) { \ 51 timing_ ## t ## _time += timing_ ## t ## _end - timing_ ## t ## _start; 52 #define TIMING_DEFINE_PRINT(t) static clock_t timing_ ## t ## _start, timing_ ## t ## _end; \ 53 static clock_t timing_ ## t ## _time; \ 54 static void timing_print_ ## t ( char * msg ) { \ 55 55 fprintf( stderr, "%s%.2f sec\n", msg, float(timing_ ## t ## _time) / HZ ); \ 56 56 } \ 57 void timing_reset_ ## t () { \57 static void timing_reset_ ## t () { \ 58 58 timing_ ## t ## _time = 0; \ 59 59 } … … 61 61 #else /* ! WINNT */ 62 62 63 #define TIMING_START(t) { struct tms timing_ ## t ## _start, timing_ ## t ## _end; \ 64 times( &timing_ ## t ## _start ); 63 #define TIMING_START(t) times( &timing_ ## t ## _start ); 65 64 #define TIMING_END(t) times( &timing_ ## t ## _end ); \ 66 timing_ ## t ## _time += timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime; }65 timing_ ## t ## _time += timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime; 67 66 #define TIMING_END_AND_PRINT(t, msg) times( &timing_ ## t ## _end ); \ 68 67 fprintf( stderr, "%s%.2f sec\n", msg, \ 69 68 float( timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime ) / HZ ); \ 70 timing_ ## t ## _time += timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime; } 71 #define TIMING_DEFINE_PRINT(t) long timing_ ## t ## _time; \ 72 void timing_print_ ## t ( char * msg ) { \ 69 timing_ ## t ## _time += timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime; 70 #define TIMING_DEFINE_PRINT(t) static struct tms timing_ ## t ## _start, timing_ ## t ## _end; \ 71 static long timing_ ## t ## _time; \ 72 static void timing_print_ ## t ( char * msg ) { \ 73 73 fprintf( stderr, "%s%.2f sec\n", msg, float(timing_ ## t ## _time) / HZ ); \ 74 74 } \ 75 void timing_reset_ ## t () { \75 static void timing_reset_ ## t () { \ 76 76 timing_ ## t ## _time = 0; \ 77 77 } -
factory/timing.h
rbecbea r1130ffc 43 43 #if defined(WINNT) && ! defined(__GNUC__) 44 44 45 #define TIMING_START(t) { clock_t timing_ ## t ## _start, timing_ ## t ## _end; \ 46 timing_ ## t ## _start = clock(); 45 #define TIMING_START(t) timing_ ## t ## _start = clock(); 47 46 #define TIMING_END(t) timing_ ## t ## _end = clock(); \ 48 timing_ ## t ## _time += timing_ ## t ## _end - timing_ ## t ## _start; }47 timing_ ## t ## _time += timing_ ## t ## _end - timing_ ## t ## _start; 49 48 #define TIMING_END_AND_PRINT(t, msg) times( &timing_ ## t ## _end ); \ 50 49 fprintf( stderr, "%s%.2f sec\n", msg, \ 51 50 float( timing_ ## t ## _end - timing_ ## t ## _start ) / HZ ); \ 52 timing_ ## t ## _time += timing_ ## t ## _end - timing_ ## t ## _start; } 53 #define TIMING_DEFINE_PRINT(t) clock_t timing_ ## t ## _time; \ 54 void timing_print_ ## t ( char * msg ) { \ 51 timing_ ## t ## _time += timing_ ## t ## _end - timing_ ## t ## _start; 52 #define TIMING_DEFINE_PRINT(t) static clock_t timing_ ## t ## _start, timing_ ## t ## _end; \ 53 static clock_t timing_ ## t ## _time; \ 54 static void timing_print_ ## t ( char * msg ) { \ 55 55 fprintf( stderr, "%s%.2f sec\n", msg, float(timing_ ## t ## _time) / HZ ); \ 56 56 } \ 57 void timing_reset_ ## t () { \57 static void timing_reset_ ## t () { \ 58 58 timing_ ## t ## _time = 0; \ 59 59 } … … 61 61 #else /* ! WINNT */ 62 62 63 #define TIMING_START(t) { struct tms timing_ ## t ## _start, timing_ ## t ## _end; \ 64 times( &timing_ ## t ## _start ); 63 #define TIMING_START(t) times( &timing_ ## t ## _start ); 65 64 #define TIMING_END(t) times( &timing_ ## t ## _end ); \ 66 timing_ ## t ## _time += timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime; }65 timing_ ## t ## _time += timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime; 67 66 #define TIMING_END_AND_PRINT(t, msg) times( &timing_ ## t ## _end ); \ 68 67 fprintf( stderr, "%s%.2f sec\n", msg, \ 69 68 float( timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime ) / HZ ); \ 70 timing_ ## t ## _time += timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime; } 71 #define TIMING_DEFINE_PRINT(t) long timing_ ## t ## _time; \ 72 void timing_print_ ## t ( char * msg ) { \ 69 timing_ ## t ## _time += timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime; 70 #define TIMING_DEFINE_PRINT(t) static struct tms timing_ ## t ## _start, timing_ ## t ## _end; \ 71 static long timing_ ## t ## _time; \ 72 static void timing_print_ ## t ( char * msg ) { \ 73 73 fprintf( stderr, "%s%.2f sec\n", msg, float(timing_ ## t ## _time) / HZ ); \ 74 74 } \ 75 void timing_reset_ ## t () { \75 static void timing_reset_ ## t () { \ 76 76 timing_ ## t ## _time = 0; \ 77 77 }
Note: See TracChangeset
for help on using the changeset viewer.