Changeset 8e51ca in git
- Timestamp:
- Nov 20, 2012, 4:49:14 PM (10 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- 5edb7729cce147b1b9aa7e0c72198afd4ac4fa9c
- Parents:
- 780b5285f9d867d03d9da5298c36e8bedf88eaf4bffe62d52befbed8110ddaf99bd0d711e101f9d4
- Location:
- factory
- Files:
-
- 2 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/FLINTconvert.cc
r780b52 r8e51ca 122 122 { 123 123 CanonicalForm c= i.coeff(); 124 if (!c.isImm()) c .mapinto(); //c%= getCharacteristic();124 if (!c.isImm()) c=c.mapinto(); //c%= getCharacteristic(); 125 125 if (!c.isImm()) 126 126 { //This case will never happen if the characteristic is in fact a prime -
factory/Makefile.am
r780b52 r8e51ca 83 83 facIrredTest.cc \ 84 84 facMul.cc \ 85 facNTLzzpEXGCD.cc \ 85 86 facSparseHensel.cc \ 86 87 ffops.cc \ … … 162 163 facIrredTest.h \ 163 164 facMul.h \ 165 facNTLzzpEXGCD.h \ 164 166 facSparseHensel.h \ 165 167 ffops.h \ -
factory/NTLconvert.cc
r780b52 r8e51ca 125 125 126 126 CanonicalForm c=i.coeff(); 127 if (!c.isImm()) c .mapinto(); //c%= getCharacteristic();127 if (!c.isImm()) c=c.mapinto(); //c%= getCharacteristic(); 128 128 if (!c.isImm()) 129 129 { //This case will never happen if the characteristic is in fact a prime -
factory/algext.cc
r780b52 r8e51ca 26 26 #include "cf_map.h" 27 27 #include "cf_generator.h" 28 #include "facMul.h" 29 #include "facNTLzzpEXGCD.h" 28 30 29 31 #ifdef HAVE_NTL … … 365 367 static CanonicalForm tryvcontent ( const CanonicalForm & f, const Variable & x, const CanonicalForm & M, bool & fail ); 366 368 static CanonicalForm trycf_content ( const CanonicalForm & f, const CanonicalForm & g, const CanonicalForm & M, bool & fail ); 367 static void tryDivide( const CanonicalForm & f, const CanonicalForm & g, const CanonicalForm & M, CanonicalForm & result, bool & divides, bool & fail );368 369 369 370 static inline CanonicalForm … … 463 464 mv = g.level(); 464 465 // here: mv is level of the largest variable in f, g 466 Variable v1= Variable (1); 467 #ifdef HAVE_NTL 468 Variable v= M.mvar(); 469 if (fac_NTL_char != getCharacteristic()) 470 { 471 fac_NTL_char= getCharacteristic(); 472 zz_p::init (getCharacteristic()); 473 } 474 zz_pX NTLMipo= convertFacCF2NTLzzpX (M); 475 zz_pE::init (NTLMipo); 476 zz_pEX NTLResult; 477 zz_pEX NTLF; 478 zz_pEX NTLG; 479 #endif 465 480 if(mv == 1) // f,g univariate 466 481 { 467 482 TIMING_START (alg_euclid_p) 483 #ifdef HAVE_NTL 484 NTLF= convertFacCF2NTLzz_pEX (f, NTLMipo); 485 NTLG= convertFacCF2NTLzz_pEX (g, NTLMipo); 486 tryNTLGCD (NTLResult, NTLF, NTLG, fail); 487 if (fail) 488 return; 489 result= convertNTLzz_pEX2CF (NTLResult, f.mvar(), v); 490 #else 468 491 tryEuclid(f,g,M,result,fail); 492 if(fail) 493 return; 494 #endif 469 495 TIMING_END_AND_PRINT (alg_euclid_p, "time for euclidean alg mod p: ") 470 if(fail)471 return;472 496 result= NN (reduce (result, M)); // do not forget to map back 473 497 return; … … 482 506 return; 483 507 CanonicalForm c; 508 #ifdef HAVE_NTL 509 NTLF= convertFacCF2NTLzz_pEX (cf, NTLMipo); 510 NTLG= convertFacCF2NTLzz_pEX (cg, NTLMipo); 511 tryNTLGCD (NTLResult, NTLF, NTLG, fail); 512 if (fail) 513 return; 514 c= convertNTLzz_pEX2CF (NTLResult, v1, v); 515 #else 484 516 tryEuclid(cf,cg,M,c,fail); 485 517 if(fail) 486 518 return; 519 #endif 487 520 // f /= cf 488 521 f.tryDiv (cf, M, fail); … … 518 551 CanonicalForm gamma; 519 552 TIMING_START (alg_euclid_p) 553 #ifdef HAVE_NTL 554 NTLF= convertFacCF2NTLzz_pEX (firstLC (f), NTLMipo); 555 NTLG= convertFacCF2NTLzz_pEX (firstLC (g), NTLMipo); 556 tryNTLGCD (NTLResult, NTLF, NTLG, fail); 557 if (fail) 558 return; 559 gamma= convertNTLzz_pEX2CF (NTLResult, v1, v); 560 #else 520 561 tryEuclid( firstLC(f), firstLC(g), M, gamma, fail ); 562 if(fail) 563 return; 564 #endif 521 565 TIMING_END_AND_PRINT (alg_euclid_p, "time for gcd of lcs in alg mod p: ") 522 if(fail)523 return;524 566 for(int i=2; i<=mv; i++) // entries at i=0,1 not visited 525 567 if(N[i] < L[i]) … … 822 864 equal= true; // modular image did not add any new information 823 865 TIMING_START (alg_termination) 866 #ifdef HAVE_FLINT 867 if (equal && tmp.isUnivariate() && f.isUnivariate() && g.isUnivariate() 868 && f.level() == tmp.level() && tmp.level() == g.level()) 869 { 870 CanonicalForm Q, R, sf, sg, stmp; 871 Variable x= Variable (1); 872 sf= swapvar (f, f.mvar(), x); 873 sg= swapvar (g, f.mvar(), x); 874 stmp= swapvar (tmp, f.mvar(), x); 875 newtonDivrem (sf, stmp, Q, R); 876 if (R.isZero()) 877 { 878 newtonDivrem (sg, stmp, Q, R); 879 if (R.isZero()) 880 { 881 Off (SW_RATIONAL); 882 setReduce (a,true); 883 if (off_rational) Off(SW_RATIONAL); else On(SW_RATIONAL); 884 TIMING_END_AND_PRINT (alg_termination, 885 "time for successful termination test in alg gcd: ") 886 return tmp*gcdcfcg; 887 } 888 } 889 } 890 else 891 #endif 824 892 if(equal && fdivides( tmp, f ) && fdivides( tmp, g )) // trial division 825 893 { … … 1017 1085 } 1018 1086 return abs( f ); 1019 }1020 1021 1022 static void tryDivide( const CanonicalForm & f, const CanonicalForm & g, const CanonicalForm & M, CanonicalForm & result, bool & divides, bool & fail )1023 { // M "univariate" monic polynomial1024 // f, g polynomials with coeffs modulo M.1025 // if f is divisible by g, 'divides' is set to 1 and 'result' == f/g mod M coefficientwise.1026 // 'fail' is set to 1, iff a zero divisor is encountered.1027 // divides==1 implies fail==01028 // required: getReduce(M.mvar())==01029 if(g.inBaseDomain())1030 {1031 result = f/g;1032 divides = true;1033 return;1034 }1035 if(g.inCoeffDomain())1036 {1037 tryInvert(g,M,result,fail);1038 if(fail)1039 return;1040 result = reduce(f*result, M);1041 divides = true;1042 return;1043 }1044 // here: g NOT inCoeffDomain1045 Variable x = g.mvar();1046 if(f.degree(x) < g.degree(x))1047 {1048 divides = false;1049 return;1050 }1051 // here: f.degree(x) > 0 and f.degree(x) >= g.degree(x)1052 CanonicalForm F = f;1053 CanonicalForm q, leadG = LC(g);1054 result = 0;1055 while(!F.isZero())1056 {1057 tryDivide(F.LC(x),leadG,M,q,divides,fail);1058 if(fail || !divides)1059 return;1060 if(F.degree(x)<g.degree(x))1061 {1062 divides = false;1063 return;1064 }1065 q *= power(x,F.degree(x)-g.degree(x));1066 result += q;1067 F = reduce(F-q*g, M);1068 }1069 result = reduce(result, M);1070 divides = true;1071 1087 } 1072 1088 -
factory/cfModResultant.cc
r780b52 r8e51ca 14 14 15 15 #include "cf_assert.h" 16 #include "timing.h" 16 17 17 18 #include "cfModResultant.h" … … 29 30 #include "FLINTconvert.h" 30 31 #endif 32 33 TIMING_DEFINE_PRINT(fac_resultant_p) 31 34 32 35 //TODO arrange by bound= deg (F,xlevel)*deg (G,i)+deg (G,xlevel)*deg (F, i) … … 255 258 return CanonicalForm ((long) FLINTresult); 256 259 #else 257 zz_pBak bak; 258 bak.save(); 259 zz_p::init (getCharacteristic()); 260 if (fac_NTL_char != getCharacteristic()) 261 { 262 fac_NTL_char= getCharacteristic(); 263 zz_p::init (getCharacteristic()); 264 } 260 265 zz_pX NTLF= convertFacCF2NTLzzpX (F); 261 266 zz_pX NTLG= convertFacCF2NTLzzpX (G); … … 263 268 zz_p NTLResult= resultant (NTLF, NTLG); 264 269 265 bak.restore();266 270 return CanonicalForm (to_long (rep (NTLResult))); 267 271 #endif … … 327 331 return power (B, degAx); 328 332 333 if (A.isUnivariate() && B.isUnivariate() && A.level() == B.level()) 334 return uniResultant (A, B); 335 329 336 CanonicalForm F= A; 330 337 CanonicalForm G= B; … … 337 344 338 345 Variable y= Variable (2); 339 340 if (F.isUnivariate() && G.isUnivariate() && F.level() == G.level())341 return N(uniResultant (F, G));342 346 343 347 int i= -1; … … 363 367 if (H == modResult) 364 368 equalCount++; 369 else 370 equalCount= 0; 365 371 366 372 count++; … … 473 479 CanonicalForm resultModP, q (0), newResult, newQ; 474 480 CanonicalForm result; 481 int equalCount= 0; 482 CanonicalForm test, newTest; 483 int count= 0; 475 484 do 476 485 { … … 487 496 setCharacteristic (p); 488 497 498 TIMING_START (fac_resultant_p); 489 499 resultModP= resultantFp (mapinto (F), mapinto (G), X, prob); 500 TIMING_END_AND_PRINT (fac_resultant_p, "time to compute resultant mod p: "); 490 501 491 502 setCharacteristic (0); 492 503 504 count++; 493 505 if ( q.isZero() ) 494 506 { … … 501 513 q= newQ; 502 514 result= newResult; 503 if (newQ > bound) 504 { 505 result= symmetricRemainder (result, q); 515 test= symmetricRemainder (result,q); 516 if (test != newTest) 517 { 518 newTest= test; 519 equalCount= 0; 520 } 521 else 522 equalCount++; 523 if (newQ > bound || (prob && equalCount == 2)) 524 { 525 result= test; 506 526 break; 507 527 } -
factory/cf_gcd.cc
r780b52 r8e51ca 45 45 46 46 bool 47 gcd_test_one ( const CanonicalForm & f, const CanonicalForm & g, bool swap ) 48 { 47 gcd_test_one ( const CanonicalForm & f, const CanonicalForm & g, bool swap, int & d ) 48 { 49 d= 0; 49 50 int count = 0; 50 51 // assume polys have same level; … … 114 115 if (p == 2 && d < 6) 115 116 { 116 zz_p::init (p); 117 if (fac_NTL_char != 2) 118 { 119 fac_NTL_char= 2; 120 zz_p::init (p); 121 } 117 122 bool primFail= false; 118 123 Variable vBuf; … … 138 143 else if ((p == 3 && d < 4) || ((p == 5 || p == 7) && d < 3)) 139 144 { 140 zz_p::init (p); 145 if (fac_NTL_char != p) 146 { 147 fac_NTL_char= p; 148 zz_p::init (p); 149 } 141 150 bool primFail= false; 142 151 Variable vBuf; … … 218 227 } 219 228 220 if ( eval1.taildegree() > 0 && eval2.taildegree() > 0 )221 {222 if (passToGF)223 setCharacteristic (p);224 if (k > 1)225 setCharacteristic (p, k, gf_name);226 return false;227 }228 229 229 CanonicalForm c= gcd (eval1, eval2); 230 bool result= c.degree() < 1; 230 d= c.degree(); 231 bool result= d < 1; 232 if (d < 0) 233 d= 0; 231 234 232 235 if (passToGF) … … 463 466 //}}} 464 467 465 //{{{ static CanonicalForm balance ( const CanonicalForm & f, const CanonicalForm & q )468 //{{{ static CanonicalForm balance_p ( const CanonicalForm & f, const CanonicalForm & q ) 466 469 //{{{ docu 467 470 // 468 // balance () - map f from positive to symmetric representation471 // balance_p() - map f from positive to symmetric representation 469 472 // mod q. 470 473 // … … 476 479 //}}} 477 480 static CanonicalForm 481 balance_p ( const CanonicalForm & f, const CanonicalForm & q ) 482 { 483 Variable x = f.mvar(); 484 CanonicalForm result = 0, qh = q / 2; 485 CanonicalForm c; 486 CFIterator i; 487 for ( i = f; i.hasTerms(); i++ ) 488 { 489 c = i.coeff(); 490 if ( c.inCoeffDomain()) 491 { 492 if ( c > qh ) 493 result += power( x, i.exp() ) * (c - q); 494 else 495 result += power( x, i.exp() ) * c; 496 } 497 else 498 result += power( x, i.exp() ) * balance_p(c,q); 499 } 500 return result; 501 } 502 503 /*static CanonicalForm 478 504 balance ( const CanonicalForm & f, const CanonicalForm & q ) 479 505 { … … 490 516 } 491 517 return result; 492 } 518 }*/ 493 519 //}}} 494 520 … … 566 592 { 567 593 // now balance D mod q 568 D = pp( balance ( D, q ) );594 D = pp( balance_p( D, q ) ); 569 595 if ( fdivides( D, f ) && fdivides( D, g ) ) 570 596 return D * c; … … 597 623 pi1 = pi1 / Ci1; pi = pi / Ci; 598 624 C = gcd( Ci, Ci1 ); 625 int d= 0; 599 626 if ( !( pi.isUnivariate() && pi1.isUnivariate() ) ) 600 627 { 601 if ( gcd_test_one( pi1, pi, true ) )628 if ( gcd_test_one( pi1, pi, true, d ) ) 602 629 { 603 630 C=abs(C); … … 716 743 pi1 = pi1 / Ci1; pi = pi / Ci; 717 744 C = gcd( Ci, Ci1 ); 745 int d= 0; 718 746 if ( pi.isUnivariate() && pi1.isUnivariate() ) 719 747 { … … 729 757 return gcd_poly_univar0( pi, pi1, true ) * C; 730 758 } 731 else if ( gcd_test_one( pi1, pi, true ) )759 else if ( gcd_test_one( pi1, pi, true, d ) ) 732 760 return C; 733 761 Variable v = f.mvar(); … … 1204 1232 delete [] degsg; 1205 1233 }*/ 1206 1207 1208 static CanonicalForm1209 balance_p ( const CanonicalForm & f, const CanonicalForm & q )1210 {1211 Variable x = f.mvar();1212 CanonicalForm result = 0, qh = q / 2;1213 CanonicalForm c;1214 CFIterator i;1215 for ( i = f; i.hasTerms(); i++ )1216 {1217 c = i.coeff();1218 if ( c.inCoeffDomain())1219 {1220 if ( c > qh )1221 result += power( x, i.exp() ) * (c - q);1222 else1223 result += power( x, i.exp() ) * c;1224 }1225 else1226 result += power( x, i.exp() ) * balance_p(c,q);1227 }1228 return result;1229 }1230 1234 1231 1235 TIMING_DEFINE_PRINT(chinrem_termination) -
factory/cf_gcd_smallp.cc
r780b52 r8e51ca 414 414 Variable chooseExtension (const Variable & alpha) 415 415 { 416 zz_p::init (getCharacteristic()); 416 if (fac_NTL_char != getCharacteristic()) 417 { 418 fac_NTL_char= getCharacteristic(); 419 zz_p::init (getCharacteristic()); 420 } 417 421 zz_pX NTLIrredpoly; 418 422 int i, m; … … 440 444 { 441 445 int p= getCharacteristic(); 442 zz_p::init (p); 446 if (p != fac_NTL_char) 447 { 448 fac_NTL_char= p; 449 zz_p::init (p); 450 } 443 451 zz_pX NTLirredpoly; 444 452 //TODO: replace d by max_{i} (deg_x{i}(f)) … … 1333 1341 { 1334 1342 int p= getCharacteristic(); 1335 zz_p::init (p); 1343 if (fac_NTL_char != p) 1344 { 1345 fac_NTL_char= p; 1346 zz_p::init (p); 1347 } 1336 1348 zz_pX NTLirredpoly; 1337 1349 CanonicalForm CFirredpoly; … … 1998 2010 #else 1999 2011 int p= getCharacteristic (); 2000 zz_p::init (p); 2012 if (fac_NTL_char != p) 2013 { 2014 fac_NTL_char= p; 2015 zz_p::init (p); 2016 } 2001 2017 mat_zz_p *NTLN= convertFacCFMatrix2NTLmat_zz_p(*N); 2002 2018 long rk= gauss (*NTLN); … … 2028 2044 (*N) (j, M.columns() + 1)= L[i]; 2029 2045 int p= getCharacteristic (); 2030 zz_p::init (p); 2046 if (fac_NTL_char != p) 2047 { 2048 fac_NTL_char= p; 2049 zz_p::init (p); 2050 } 2031 2051 zz_pX NTLMipo= convertFacCF2NTLzzpX (getMipo (alpha)); 2032 2052 zz_pE::init (NTLMipo); … … 2069 2089 #else 2070 2090 int p= getCharacteristic (); 2071 zz_p::init (p); 2091 if (fac_NTL_char != p) 2092 { 2093 fac_NTL_char= p; 2094 zz_p::init (p); 2095 } 2072 2096 mat_zz_p *NTLN= convertFacCFMatrix2NTLmat_zz_p(*N); 2073 2097 long rk= gauss (*NTLN); … … 2109 2133 (*N) (j, M.columns() + 1)= L[i]; 2110 2134 int p= getCharacteristic (); 2111 zz_p::init (p); 2135 if (fac_NTL_char != p) 2136 { 2137 fac_NTL_char= p; 2138 zz_p::init (p); 2139 } 2112 2140 zz_pX NTLMipo= convertFacCF2NTLzzpX (getMipo (alpha)); 2113 2141 zz_pE::init (NTLMipo); … … 4547 4575 } 4548 4576 4549 if( gcd_test_one( F, G, false ) ) 4577 int dummy= 0; 4578 if( gcd_test_one( F, G, false, dummy ) ) 4550 4579 { 4551 4580 return N (d); … … 4562 4591 { 4563 4592 if (p == 2) 4564 setCharacteristic (2, 6, 'Z');4593 setCharacteristic (2, 12, 'Z'); 4565 4594 else if (p == 3) 4566 4595 setCharacteristic (3, 4, 'Z'); … … 4593 4622 if (p == 2 && d < 6) 4594 4623 { 4595 zz_p::init (p); 4624 if (fac_NTL_char != p) 4625 { 4626 fac_NTL_char= p; 4627 zz_p::init (p); 4628 } 4596 4629 bool primFail= false; 4597 4630 Variable vBuf; … … 4617 4650 else if ((p == 3 && d < 4) || ((p == 5 || p == 7) && d < 3)) 4618 4651 { 4619 zz_p::init (p); 4652 if (fac_NTL_char != p) 4653 { 4654 fac_NTL_char= p; 4655 zz_p::init (p); 4656 } 4620 4657 bool primFail= false; 4621 4658 Variable vBuf; -
factory/cf_map_ext.cc
r780b52 r8e51ca 67 67 { 68 68 int p= getCharacteristic (); 69 zz_p::init (p); 69 if (fac_NTL_char != p) 70 { 71 fac_NTL_char= p; 72 zz_p::init (p); 73 } 70 74 zz_pX NTL_mipo= convertFacCF2NTLzzpX (getMipo (beta)); 71 75 zz_pE::init (NTL_mipo); … … 325 329 int d= degree (mipo); 326 330 int p= getCharacteristic (); 327 zz_p::init (p); 331 if (fac_NTL_char != p) 332 { 333 fac_NTL_char= p; 334 zz_p::init (p); 335 } 328 336 zz_pX NTL_mipo; 329 337 CanonicalForm mipo2; … … 378 386 CanonicalForm primElemMipo= findMinPoly (primElem, alpha); 379 387 int p= getCharacteristic (); 380 zz_p::init (p); 388 if (fac_NTL_char != p) 389 { 390 fac_NTL_char= p; 391 zz_p::init (p); 392 } 381 393 zz_pX NTLMipo= convertFacCF2NTLzzpX (getMipo (beta)); 382 394 zz_pE::init (NTLMipo); … … 399 411 } 400 412 int p= getCharacteristic (); 401 zz_p::init (p); 413 if (fac_NTL_char != p) 414 { 415 fac_NTL_char= p; 416 zz_p::init (p); 417 } 402 418 zz_pX NTL_mipo= convertFacCF2NTLzzpX (getMipo (beta)); 403 419 zz_pE::init (NTL_mipo); … … 422 438 ASSERT (F.isUnivariate() && F.mvar()==alpha,"expected element of F_p(alpha)"); 423 439 424 zz_p::init (getCharacteristic()); 440 if (fac_NTL_char != getCharacteristic()) 441 { 442 fac_NTL_char= getCharacteristic(); 443 zz_p::init (getCharacteristic()); 444 } 425 445 zz_pX NTLF= convertFacCF2NTLzzpX (F); 426 446 int d= degree (getMipo (alpha)); -
factory/facAlgExt.cc
r780b52 r8e51ca 35 35 TIMING_DEFINE_PRINT(fac_alg_sqrf) 36 36 TIMING_DEFINE_PRINT(fac_alg_factor_sqrf) 37 TIMING_DEFINE_PRINT(fac_alg_time_shift) 37 38 38 39 // squarefree part of F … … 126 127 ASSERT (degree (norm, alpha) <= 0, "wrong norm computed"); 127 128 TIMING_START (fac_alg_factor_norm); 129 bool save_sort= !isOn (SW_USE_NTL_SORT); 130 On (SW_USE_NTL_SORT); 128 131 CFFList normFactors= factorize (norm); 132 if (save_sort) 133 Off (SW_USE_NTL_SORT); 129 134 TIMING_END_AND_PRINT (fac_alg_factor_norm, "time to factor norm: "); 130 135 CFList factors; … … 136 141 137 142 normFactors.removeFirst(); 143 CFFListIterator i= normFactors; 138 144 CanonicalForm buf; 139 buf= f; 145 bool shiftBuf= false; 146 if (!(normFactors.length() == 2 && degree (i.getItem().factor()) <= degree (f))) 147 { 148 TIMING_START (fac_alg_time_shift); 149 if (shift != 0) 150 buf= f (f.mvar() - shift*alpha, f.mvar()); 151 else 152 buf= f; 153 shiftBuf= true; 154 TIMING_END_AND_PRINT (fac_alg_time_shift, "time to shift: "); 155 } 156 else 157 buf= f; 140 158 CanonicalForm factor; 141 for (CFFListIterator i= normFactors; i.hasItem(); i++) 159 int count= 0; 160 for (; i.hasItem(); i++) 142 161 { 143 162 ASSERT (i.getItem().exp() == 1, "norm not squarefree"); 144 163 TIMING_START (fac_alg_gcd); 145 if (shift == 0)164 if (shiftBuf) 146 165 factor= gcd (buf, i.getItem().factor()); 147 166 else 148 factor= gcd (buf, i.getItem().factor() (f.mvar() + shift*alpha, f.mvar())); 167 { 168 if (shift == 0) 169 factor= gcd (buf, i.getItem().factor()); 170 else 171 factor= gcd (buf, i.getItem().factor() (f.mvar() + shift*alpha, f.mvar())); 172 } 149 173 buf /= factor; 174 if (shiftBuf) 175 { 176 if (shift != 0) 177 factor= factor (f.mvar() + shift*alpha, f.mvar()); 178 } 150 179 TIMING_END_AND_PRINT (fac_alg_gcd, "time to recover factors: "); 151 180 factors.append (factor); 181 count++; 182 if (normFactors.length() - 1 == count) 183 { 184 if (shiftBuf) 185 factors.append (buf (f.mvar() + shift*alpha, f.mvar())); 186 else 187 factors.append (buf); 188 buf= 1; 189 break; 190 } 152 191 } 153 192 ASSERT (degree (buf) <= 0, "incomplete factorization"); -
factory/facBivar.cc
r780b52 r8e51ca 357 357 (prod (bufUniFactors) == bufAeval)); 358 358 359 if (bufUniFactors.getFirst().inCoeffDomain()) 360 bufUniFactors.removeFirst(); 361 362 if (bufUniFactors.length() == 1) 363 { 364 factors.append (A); 365 366 appendSwapDecompress (factors, conv (contentAxFactors), 367 conv (contentAyFactors), swap, swap2, N); 368 369 if (isOn (SW_RATIONAL)) 370 normalize (factors); 371 return factors; 372 } 373 359 374 TIMING_START (fac_uni_factorizer); 360 375 if (extension) … … 367 382 (prod (bufUniFactors2) == bufAeval2)); 368 383 369 if (bufUniFactors.getFirst().inCoeffDomain())370 bufUniFactors.removeFirst();371 384 if (bufUniFactors2.getFirst().inCoeffDomain()) 372 385 bufUniFactors2.removeFirst(); 373 if (bufUniFactors .length() == 1 || bufUniFactors2.length() == 1)386 if (bufUniFactors2.length() == 1) 374 387 { 375 388 factors.append (A); -
factory/facFactorize.cc
r780b52 r8e51ca 401 401 oldAeval[i]= Aeval2[i]; 402 402 403 getLeadingCoeffs (A, Aeval2 , uniFactors, evaluation);403 getLeadingCoeffs (A, Aeval2); 404 404 405 405 CFList biFactorsLCs; … … 622 622 !isOnlyLeadingCoeff(iter2.getItem())) //content divides LCmultiplier completely and factor consists of more terms than just the leading coeff 623 623 { 624 int index2= 1; 625 for (CFListIterator iter3= leadingCoeffs2[lengthAeval2-1]; 626 iter3.hasItem(); iter3++, index2++) 624 Variable xx= Variable (2); 625 CanonicalForm vars; 626 vars= power (xx, degree (LC (getItem(oldBiFactors, index),1), 627 xx)); 628 for (int i= 0; i < lengthAeval2; i++) 627 629 { 628 if (index2 == index) 630 if (oldAeval[i].isEmpty()) 631 continue; 632 xx= oldAeval[i].getFirst().mvar(); 633 vars *= power (xx, degree (LC (getItem(oldAeval[i], index),1), 634 xx)); 635 } 636 if (vars.level() <= 2) 637 { 638 int index2= 1; 639 for (CFListIterator iter3= leadingCoeffs2[lengthAeval2-1]; 640 iter3.hasItem(); iter3++, index2++) 629 641 { 630 iter3.getItem() /= LCmultiplier; 631 break; 642 if (index2 == index) 643 { 644 iter3.getItem() /= LCmultiplier; 645 break; 646 } 632 647 } 648 A /= LCmultiplier; 649 foundMultiplier= true; 650 iter.getItem()= 1; 633 651 } 634 A /= LCmultiplier;635 foundMultiplier= true;636 iter.getItem()= 1;637 652 } 638 653 } -
factory/facFqBivar.cc
r780b52 r8e51ca 155 155 "univariate polynomial expected or constant expected"); 156 156 CFFList factorsA; 157 zz_p::init (getCharacteristic()); 157 if (fac_NTL_char != getCharacteristic()) 158 { 159 fac_NTL_char= getCharacteristic(); 160 zz_p::init (getCharacteristic()); 161 } 158 162 if (GF) 159 163 { … … 673 677 Variable chooseExtension (const Variable & alpha, const Variable& beta, int k) 674 678 { 675 zz_p::init (getCharacteristic()); 679 if (fac_NTL_char != getCharacteristic()) 680 { 681 fac_NTL_char= getCharacteristic(); 682 zz_p::init (getCharacteristic()); 683 } 676 684 zz_pX NTLIrredpoly; 677 685 int i=1, m= 2; … … 2350 2358 } 2351 2359 delete [] A; 2360 if (!wasInBounds) 2361 { 2362 if (start) 2363 henselLiftResume12 (F, factors, start, degree (F) + 1, Pi, diophant, M); 2364 else 2365 henselLift12 (F, factors, degree (F) + 1, Pi, diophant, M); 2366 factors.insert (LCF); 2367 } 2352 2368 return l; 2353 2369 } … … 2472 2488 } 2473 2489 delete [] A; 2490 if (!wasInBounds) 2491 { 2492 if (start) 2493 henselLiftResume12 (F, factors, start, degree (F) + 1, Pi, diophant, M); 2494 else 2495 henselLift12 (F, factors, degree (F) + 1, Pi, diophant, M); 2496 factors.insert (LCF); 2497 } 2474 2498 return l; 2475 2499 } … … 2652 2676 } 2653 2677 delete [] A; 2678 if (!wasInBounds) 2679 { 2680 if (start) 2681 henselLiftResume12 (F, factors, start, degree (F) + 1, Pi, diophant, M); 2682 else 2683 henselLift12 (F, factors, degree (F) + 1, Pi, diophant, M); 2684 factors.insert (LCF); 2685 } 2654 2686 return l; 2655 2687 } … … 2851 2883 } 2852 2884 delete [] A; 2885 if (!wasInBounds) 2886 { 2887 if (start) 2888 henselLiftResume12 (F, factors, start, degree (F) + 1, Pi, diophant, M); 2889 else 2890 henselLift12 (F, factors, degree (F) + 1, Pi, diophant, M); 2891 factors.insert (LCF); 2892 } 2853 2893 return l; 2854 2894 } … … 2970 3010 } 2971 3011 delete [] A; 3012 if (!wasInBounds) 3013 { 3014 if (start) 3015 henselLiftResume12 (F, factors, start, degree (F) + 1, Pi, diophant, M); 3016 else 3017 henselLift12 (F, factors, degree (F) + 1, Pi, diophant, M); 3018 factors.insert (LCF); 3019 } 2972 3020 return l; 2973 3021 } … … 3137 3185 } 3138 3186 delete [] A; 3187 if (!wasInBounds) 3188 { 3189 if (start) 3190 henselLiftResume12 (F, factors, start, degree (F) + 1, Pi, diophant, M); 3191 else 3192 henselLift12 (F, factors, degree (F) + 1, Pi, diophant, M); 3193 factors.insert (LCF); 3194 } 3139 3195 return l; 3140 3196 } … … 3507 3563 CFArray * A= new CFArray [factors.length()]; 3508 3564 CFArray bufQ= CFArray (factors.length()); 3509 zz_p::init (getCharacteristic()); 3565 if (fac_NTL_char != getCharacteristic()) 3566 { 3567 fac_NTL_char= getCharacteristic(); 3568 zz_p::init (getCharacteristic()); 3569 } 3510 3570 mat_zz_p NTLN; 3511 3571 ident (NTLN, factors.length()); … … 3700 3760 CFArray * A= new CFArray [factors.length()]; 3701 3761 CFArray bufQ= CFArray (factors.length()); 3702 zz_p::init (getCharacteristic()); 3762 if (fac_NTL_char != getCharacteristic()) 3763 { 3764 fac_NTL_char= getCharacteristic(); 3765 zz_p::init (getCharacteristic()); 3766 } 3703 3767 zz_pX NTLMipo= convertFacCF2NTLzzpX (getMipo (alpha)); 3704 3768 zz_pE::init (NTLMipo); … … 6158 6222 nmod_mat_t FLINTN; 6159 6223 #else 6160 zz_p::init (getCharacteristic()); 6224 if (fac_NTL_char != getCharacteristic()) 6225 { 6226 fac_NTL_char= getCharacteristic(); 6227 zz_p::init (getCharacteristic()); 6228 } 6161 6229 mat_zz_p NTLN; 6162 6230 #endif … … 6270 6338 return Union (smallFactors, 6271 6339 factorRecombination (bufUniFactors, F, 6272 power (y, degree (F) + 1 + degree (LCF)),6340 power (y, degree (F) + 1), 6273 6341 degs, 1, bufUniFactors.length()/2 6274 6342 ) … … 7028 7096 int l= 1; 7029 7097 7030 zz_p::init (getCharacteristic()); 7098 if (fac_NTL_char != getCharacteristic()) 7099 { 7100 fac_NTL_char= getCharacteristic(); 7101 zz_p::init (getCharacteristic()); 7102 } 7031 7103 zz_pX NTLMipo; 7032 7104 mat_zz_p NTLN; -
factory/facFqFactorize.cc
r780b52 r8e51ca 1937 1937 1938 1938 1939 void getLeadingCoeffs (const CanonicalForm& A, CFList*& Aeval, 1940 const CFList& uniFactors, const CFList& evaluation 1939 void getLeadingCoeffs (const CanonicalForm& A, CFList*& Aeval 1941 1940 ) 1942 1941 { … … 2562 2561 oldAeval[i]= Aeval2[i]; 2563 2562 2564 getLeadingCoeffs (A, Aeval2 , uniFactors, evaluation);2563 getLeadingCoeffs (A, Aeval2); 2565 2564 2566 2565 CFList biFactorsLCs; … … 2786 2785 !isOnlyLeadingCoeff(iter2.getItem())) //content divides LCmultiplier completely and factor consists of more terms than just the leading coeff 2787 2786 { 2788 int index2= 1; 2789 for (CFListIterator iter3= leadingCoeffs2[lengthAeval2-1]; 2790 iter3.hasItem(); iter3++, index2++) 2787 Variable xx= Variable (2); 2788 CanonicalForm vars; 2789 vars= power (xx, degree (LC (getItem(oldBiFactors, index),1), 2790 xx)); 2791 for (int i= 0; i < lengthAeval2; i++) 2791 2792 { 2792 if (index2 == index) 2793 if (oldAeval[i].isEmpty()) 2794 continue; 2795 xx= oldAeval[i].getFirst().mvar(); 2796 vars *= power (xx, degree (LC (getItem(oldAeval[i], index),1), 2797 xx)); 2798 } 2799 if (vars.level() <= 2) 2800 { 2801 int index2= 1; 2802 for (CFListIterator iter3= leadingCoeffs2[lengthAeval2-1]; 2803 iter3.hasItem(); iter3++, index2++) 2793 2804 { 2794 iter3.getItem() /= LCmultiplier; 2795 break; 2805 if (index2 == index) 2806 { 2807 iter3.getItem() /= LCmultiplier; 2808 break; 2809 } 2796 2810 } 2811 A /= LCmultiplier; 2812 foundMultiplier= true; 2813 iter.getItem()= 1; 2797 2814 } 2798 A /= LCmultiplier;2799 foundMultiplier= true;2800 iter.getItem()= 1;2801 2815 } 2802 2816 } -
factory/facFqFactorize.h
r780b52 r8e51ca 601 601 void 602 602 getLeadingCoeffs (const CanonicalForm& A, ///< [in] some poly 603 CFList*& Aeval ,///< [in,out] array of bivariate603 CFList*& Aeval ///< [in,out] array of bivariate 604 604 ///< factors, returns the leading 605 605 ///< coefficients of these factors 606 const CFList& uniFactors,///< [in] univariate factors of A607 const CFList& evaluation ///< [in] evaluation point608 606 ); 609 607 -
factory/facHensel.cc
r780b52 r8e51ca 30 30 #include "cf_primes.h" 31 31 #include "facBivar.h" 32 #include "facNTLzzpEXGCD.h" 32 33 33 34 #ifdef HAVE_NTL … … 38 39 CFList productsNTL (const CFList& factors, const CanonicalForm& M) 39 40 { 40 zz_p::init (getCharacteristic()); 41 if (fac_NTL_char != getCharacteristic()) 42 { 43 fac_NTL_char= getCharacteristic(); 44 zz_p::init (getCharacteristic()); 45 } 41 46 zz_pX NTLMipo= convertFacCF2NTLzzpX (M); 42 47 zz_pE::init (NTLMipo); … … 100 105 buf1= bufFactors.getFirst(); 101 106 buf2= i.getItem(); 107 #ifdef HAVE_NTL 108 Variable x= Variable (1); 109 if (fac_NTL_char != getCharacteristic()) 110 { 111 fac_NTL_char= getCharacteristic(); 112 zz_p::init (getCharacteristic()); 113 } 114 zz_pX NTLMipo= convertFacCF2NTLzzpX (M); 115 zz_pE::init (NTLMipo); 116 zz_pEX NTLbuf1, NTLbuf2, NTLbuf3, NTLS, NTLT; 117 NTLbuf1= convertFacCF2NTLzz_pEX (buf1, NTLMipo); 118 NTLbuf2= convertFacCF2NTLzz_pEX (buf2, NTLMipo); 119 tryNTLXGCD (NTLbuf3, NTLS, NTLT, NTLbuf1, NTLbuf2, fail); 120 if (fail) 121 return; 122 S= convertNTLzz_pEX2CF (NTLS, x, M.mvar()); 123 T= convertNTLzz_pEX2CF (NTLT, x, M.mvar()); 124 #else 102 125 tryExtgcd (buf1, buf2, M, buf3, S, T, fail); 103 126 if (fail) 104 127 return; 128 #endif 105 129 result.append (S); 106 130 result.append (T); … … 109 133 for (; i.hasItem(); i++) 110 134 { 135 #ifdef HAVE_NTL 136 NTLbuf1= convertFacCF2NTLzz_pEX (i.getItem(), NTLMipo); 137 tryNTLXGCD (NTLbuf3, NTLS, NTLT, NTLbuf3, NTLbuf1, fail); 138 if (fail) 139 return; 140 S= convertNTLzz_pEX2CF (NTLS, x, M.mvar()); 141 T= convertNTLzz_pEX2CF (NTLT, x, M.mvar()); 142 #else 111 143 buf1= i.getItem(); 112 144 tryExtgcd (buf3, buf1, M, buf3, S, T, fail); 113 145 if (fail) 114 146 return; 147 #endif 115 148 CFListIterator k= factors; 116 149 for (CFListIterator j= result; j.hasItem(); j++, k++) … … 535 568 Variable beta; 536 569 Off (SW_RATIONAL); 537 if (mipoHasDen) 538 { 539 setReduce (alpha, false); 540 modMipo= modMipo.mapinto(); 541 modMipo /= lc (modMipo); 542 beta= rootOf (modMipo); 543 setReduce (alpha, true); 544 } 570 setReduce (alpha, false); 571 modMipo= modMipo.mapinto(); 572 modMipo /= lc (modMipo); 573 beta= rootOf (modMipo); 574 setReduce (alpha, true); 545 575 546 576 setReduce (alpha, false); 547 577 for (k= 0; k < factors.length(); k++) 548 578 { 549 if (!mipoHasDen) 550 bufFactors [k]= bufFactors[k].mapinto(); 551 else 552 { 553 bufFactors [k]= bufFactors[k].mapinto(); 554 bufFactors [k]= replacevar (bufFactors[k], alpha, beta); 555 } 579 bufFactors [k]= bufFactors[k].mapinto(); 580 bufFactors [k]= replacevar (bufFactors[k], alpha, beta); 556 581 } 557 582 setReduce (alpha, true); … … 596 621 recResult= mapinto (recResult); 597 622 setReduce (alpha, true); 598 if (mipoHasDen) 599 { 600 for (CFListIterator i= recResult; i.hasItem(); i++) 601 i.getItem()= replacevar (i.getItem(), alpha, beta); 602 } 623 624 for (CFListIterator i= recResult; i.hasItem(); i++) 625 i.getItem()= replacevar (i.getItem(), alpha, beta); 603 626 604 627 setCharacteristic (0); … … 621 644 if (mipoHasDen) 622 645 coeffE= replacevar (coeffE, gamma, beta); 646 else 647 coeffE= replacevar (coeffE, alpha, beta); 623 648 setCharacteristic (0); 624 649 if (!coeffE.isZero()) … … 631 656 { 632 657 setCharacteristic (p); 633 setReduce (alpha, false);634 658 g= mulNTL (coeffE, j.getItem()); 635 659 g= modNTL (g, bufFactors[ii]); 636 setReduce (alpha, true);637 660 setCharacteristic (0); 638 661 if (mipoHasDen) … … 641 664 k.getItem() += replacevar (g.mapinto()*modulus, beta, gamma); 642 665 e -= mulNTL (replacevar (g.mapinto(), beta, gamma)*modulus, 643 666 l.getItem(), b); 644 667 setReduce (beta, true); 645 668 } 646 669 else 647 670 { 648 k.getItem() += g.mapinto()*modulus; 649 e -= mulNTL (g.mapinto()*modulus, l.getItem(), b); 671 k.getItem() += replacevar (g.mapinto()*modulus, beta, alpha); 672 e -= mulNTL (replacevar (g.mapinto()*modulus, beta, alpha), 673 l.getItem(), b); 650 674 } 651 675 e= b(e); -
factory/facMul.cc
r780b52 r8e51ca 503 503 ASSERT (F.isUnivariate() && G.isUnivariate(), "expected univariate polys"); 504 504 ASSERT (F.level() == G.level(), "expected polys of same level"); 505 zz_p::init (getCharacteristic()); 505 if (fac_NTL_char != getCharacteristic()) 506 { 507 fac_NTL_char= getCharacteristic(); 508 zz_p::init (getCharacteristic()); 509 } 506 510 Variable alpha; 507 511 CanonicalForm result; … … 619 623 ASSERT (F.isUnivariate() && G.isUnivariate(), "expected univariate polys"); 620 624 ASSERT (F.level() == G.level(), "expected polys of same level"); 621 zz_p::init (getCharacteristic()); 625 if (fac_NTL_char != getCharacteristic()) 626 { 627 fac_NTL_char= getCharacteristic(); 628 zz_p::init (getCharacteristic()); 629 } 622 630 Variable alpha; 623 631 CanonicalForm result; … … 764 772 ASSERT (F.isUnivariate() && G.isUnivariate(), "expected univariate polys"); 765 773 ASSERT (F.level() == G.level(), "expected polys of same level"); 766 zz_p::init (getCharacteristic()); 774 if (fac_NTL_char != getCharacteristic()) 775 { 776 fac_NTL_char= getCharacteristic(); 777 zz_p::init (getCharacteristic()); 778 } 767 779 Variable alpha; 768 780 CanonicalForm result; … … 2074 2086 int d1= degAx + degBx + 1; 2075 2087 int d2= tmax (degAy, degBy); 2076 zz_p::init (getCharacteristic()); 2088 if (fac_NTL_char != getCharacteristic()) 2089 { 2090 fac_NTL_char= getCharacteristic(); 2091 zz_p::init (getCharacteristic()); 2092 } 2077 2093 zz_pX NTLMipo= convertFacCF2NTLzzpX (getMipo (alpha)); 2078 2094 zz_pE::init (NTLMipo); … … 2834 2850 if (p > 0) 2835 2851 { 2836 zz_p::init (p); 2852 if (fac_NTL_char != p) 2853 { 2854 fac_NTL_char= p; 2855 zz_p::init (p); 2856 } 2837 2857 Variable alpha; 2838 2858 if (hasFirstAlgVar (A, alpha) || hasFirstAlgVar (B, alpha)) -
factory/facMul.h
r780b52 r8e51ca 155 155 const CFList& M ///< [in] contains only powers of Variables 156 156 ); 157 158 #ifdef HAVE_FLINT 159 /// division with remainder of univariate polynomials over Q and Q(a) using 160 /// Newton inversion, satisfying F=G*Q+R, deg(R) < deg(G) 161 void 162 newtonDivrem (const CanonicalForm& F, ///<[in] univariate poly 163 const CanonicalForm& G, ///<[in] univariate poly 164 CanonicalForm& Q, ///<[in, out] quotient 165 CanonicalForm& R ///<[in, out] remainder 166 ); 167 #endif 168 157 169 #endif 158 170 /* FAC_MUL_H */ -
factory/fac_ezgcd.cc
r780b52 r8e51ca 492 492 } 493 493 494 if ( gcd_test_one( F, G, false ) ) 494 int dummy= 0; 495 if ( gcd_test_one( F, G, false, dummy ) ) 495 496 { 496 497 DEBDECLEVEL( cerr, "ezgcd" ); -
factory/fac_util.h
r780b52 r8e51ca 54 54 /*ENDPUBLIC*/ 55 55 56 bool gcd_test_one ( const CanonicalForm & f, const CanonicalForm & g, bool swap );56 bool gcd_test_one ( const CanonicalForm & f, const CanonicalForm & g, bool swap, int & d ); 57 57 58 58 CanonicalForm ezgcd ( const CanonicalForm & f, const CanonicalForm & g ); -
factory/libfac/charset/alg_factor.cc
r780b52 r8e51ca 76 76 { 77 77 current++; 78 }79 80 // replacement for factory's broken psr81 static CanonicalForm82 mypsr ( const CanonicalForm &rr, const CanonicalForm &vv, const Variable & x )83 {84 CanonicalForm r=rr, v=vv, l, test, lu, lv, t, retvalue;85 int dr, dv, d,n=0;86 87 88 dr = degree( r, x );89 dv = degree( v, x );90 if (dv <= dr) {l=LC(v,x); v = v -l*power(x,dv);}91 else { l = 1; }92 d= dr-dv+1;93 while ( ( dv <= dr ) && ( r != r.genZero()) ){94 test = power(x,dr-dv)*v*LC(r,x);95 if ( dr == 0 ) { r= CanonicalForm(0); }96 else { r= r - LC(r,x)*power(x,dr); }97 r= l*r -test;98 dr= degree(r,x);99 n+=1;100 }101 r= power(l, d-n)*r;102 return r;103 78 } 104 79 -
factory/libfac/charset/algfactor.cc
r780b52 r8e51ca 43 43 } 44 44 45 /* unused functions: 45 46 static CFFList 46 47 myDifference(const CFFList & Inputlist1,const CFFList & Inputlist2){ … … 65 66 } 66 67 return 1; 67 } 68 } */ 68 69 69 70 #ifdef CHARSETNADEBUG -
factory/libfac/charset/charset.cc
r780b52 r8e51ca 236 236 if ( ! same( iitem, jitem ) ) 237 237 if ( ! member(jitem, mem)) 238 { 238 239 if ( contractsub(iitem, jitem) ){ 239 240 ts.append(jitem); mem.append(jitem); … … 243 244 ts.append(iitem); 244 245 } 246 } 245 247 } 246 248 } … … 515 517 } 516 518 // CERR << "ind= " << ind << "\n"; 517 if ( (ind == 1)) //&& ( as.length() > 1) )519 if ( ind == 1 ) //&& ( as.length() > 1) ) 518 520 { 519 521 if ( irreducible(AS) ) -
factory/libfac/charset/csutil.cc
r780b52 r8e51ca 657 657 elem = i.getItem(); 658 658 if ( ! elem.isEmpty() ) 659 { 659 660 if ( length <= elem.length() ){ ppi2.append(elem); } 660 661 else { ppi1.append(elem); } 662 } 661 663 } 662 664 } -
factory/libfac/factor/Factor.cc
r780b52 r8e51ca 1 1 /////////////////////////////////////////////////////////////////////////////// 2 static const char * errmsg = "\nYou found a bug!\nPlease inform singular@mathematik.uni-kl.de\nPlease include above information and your input (the ideal/polynomial and characteristic) in your bug-report.\nThank you."; 2 /*static const char * errmsg = "\nYou found a bug!\nPlease inform singular@mathematik.uni-kl.de\nPlease include above information and your input (the ideal/polynomial and characteristic) in your bug-report.\nThank you.";*/ 3 3 /////////////////////////////////////////////////////////////////////////////// 4 4 // FACTORY - Includes -
factory/libfac/factor/SqrFree.cc
r780b52 r8e51ca 1 1 /////////////////////////////////////////////////////////////////////////////// 2 2 // emacs edit mode for this file is -*- C++ -*- 3 static const char * errmsg = "\nYou found a bug!\nPlease inform singular@mathematik.uni-kl.de\n Please include above information and your input (the ideal/polynomial and characteristic) in your bug-report.\nThank you."; 3 /*static const char * errmsg = "\nYou found a bug!\nPlease inform singular@mathematik.uni-kl.de\n Please include above information and your input (the ideal/polynomial and characteristic) in your bug-report.\nThank you.";*/ 4 4 /////////////////////////////////////////////////////////////////////////////// 5 5 // FACTORY - Includes
Note: See TracChangeset
for help on using the changeset viewer.