Changeset 5df7d0 in git for factory/algext.cc
- Timestamp:
- Jul 1, 2011, 12:02:02 PM (12 years ago)
- Branches:
- (u'spielwiese', '91fdef05f09f54b8d58d92a472e9c4a43aa4656f')
- Children:
- 33e850a665f1c7a320edcde4faacdd7602f49b76
- Parents:
- 6f08f33cc3e3c2a69b00521f71d91ff88066e3c0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/algext.cc
r6f08f3 r5df7d0 314 314 return; 315 315 result = inv*P; // monify result (not reduced, yet) 316 result= reduce (result, M); 316 317 return; 317 318 } … … 327 328 { 328 329 result *= inv; 330 result= reduce (result, M); 329 331 return; 330 332 } … … 359 361 bool isEqual(int *a, int *b, int lower, int upper); 360 362 CanonicalForm firstLC(const CanonicalForm & f); 361 void tryCRA( const CanonicalForm & x1, const CanonicalForm & q1, const CanonicalForm & x2, const CanonicalForm & q2, const CanonicalForm & M, CanonicalForm & xnew, CanonicalForm & qnew, bool & fail );362 void tryExtgcd( const CanonicalForm & F, const CanonicalForm & G, const CanonicalForm & M, CanonicalForm & result, CanonicalForm & s, CanonicalForm & t, bool & fail );363 363 static CanonicalForm trycontent ( const CanonicalForm & f, const Variable & x, const CanonicalForm & M, bool & fail ); 364 364 static CanonicalForm tryvcontent ( const CanonicalForm & f, const Variable & x, const CanonicalForm & M, bool & fail ); … … 366 366 static void tryDivide( const CanonicalForm & f, const CanonicalForm & g, const CanonicalForm & M, CanonicalForm & result, bool & divides, bool & fail ); 367 367 368 static inline CanonicalForm 369 tryNewtonInterp (const CanonicalForm alpha, const CanonicalForm u, 370 const CanonicalForm newtonPoly, const CanonicalForm oldInterPoly, 371 const Variable & x, const CanonicalForm& M, bool& fail) 372 { 373 CanonicalForm interPoly; 374 375 CanonicalForm inv; 376 tryInvert (newtonPoly (alpha, x), M, inv, fail); 377 if (fail) 378 return 0; 379 380 interPoly= oldInterPoly+reduce ((u - oldInterPoly (alpha, x))*inv*newtonPoly, M); 381 return interPoly; 382 } 368 383 369 384 void tryBrownGCD( const CanonicalForm & F, const CanonicalForm & G, const CanonicalForm & M, CanonicalForm & result, bool & fail, bool topLevel ) … … 391 406 return; 392 407 result = inv*G; 408 result= reduce (result, M); 393 409 return; 394 410 } … … 409 425 return; 410 426 result = inv*F; 427 result= reduce (result, M); 411 428 return; 412 429 } … … 448 465 if(fail) 449 466 return; 450 result = NN(result); // do not forget to map back467 result= NN (reduce (result, M)); // do not forget to map back 451 468 return; 452 469 } … … 509 526 CanonicalForm gamma_image, m=1; 510 527 CanonicalForm gm=0; 511 CanonicalForm g_image, alpha, gnew , mnew;528 CanonicalForm g_image, alpha, gnew; 512 529 FFGenerator gen = FFGenerator(); 513 530 Variable x= Variable (1); … … 535 552 if(isEqual(dg_im, L, 2, mv)) 536 553 { 537 g_image /= lc(g_image); // make g_image monic over Z/p 554 CanonicalForm inv; 555 tryInvert (firstLC (g_image), M, inv, fail); 556 if (fail) 557 return; 558 g_image *= inv; 538 559 g_image *= gamma_image; // multiply by multiple of image lc(gcd) 539 tryCRA( g_image, x-alpha, gm, m, M, gnew, mnew, fail ); 560 g_image= reduce (g_image, M); 561 gnew= tryNewtonInterp (alpha, g_image, m, gm, x, M, fail); 540 562 // gnew = gm mod m 541 563 // gnew = g_image mod var(1)-alpha … … 543 565 if(fail) 544 566 return; 545 m = mnew;567 m *= (x - alpha); 546 568 if(gnew == gm) // gnew did not change 547 569 { … … 563 585 if(divides) 564 586 { 565 result = NN( c*g_image);587 result = NN(reduce (c*g_image, M)); 566 588 return; 567 589 } … … 672 694 // here: mipo is monic 673 695 tryBrownGCD( mapinto(f), mapinto(g), mipo, Dp, fail ); 674 Dp = reduce( Dp, mipo );675 696 setCharacteristic(0); 676 697 if( fail ) // mipo splits in char p … … 781 802 } 782 803 783 784 void tryCRA( const CanonicalForm & x1, const CanonicalForm & q1, const CanonicalForm & x2, const CanonicalForm & q2, const CanonicalForm & M, CanonicalForm & xnew, CanonicalForm & qnew, bool & fail )785 { // as CRA, but takes care of zero divisors786 CanonicalForm tmp;787 if(x1.level() <= 1 && x2.level() <= 1) // base case788 {789 tryExtgcd(q1,q2,M,tmp,xnew,qnew,fail);790 if(fail)791 return;792 xnew = x1 + (x2-x1) * xnew * q1;793 qnew = q1*q2;794 xnew = mod(xnew,qnew);795 return;796 }797 CanonicalForm tmp2;798 xnew = 0;799 qnew = q1 * q2;800 // here: x1.level() > 1 || x2.level() > 1801 if(x1.level() > x2.level())802 {803 for(CFIterator i=x1; i.hasTerms(); i++)804 {805 if(i.exp() == 0) // const. term806 {807 tryCRA(i.coeff(),q1,x2,q2,M,tmp,tmp2,fail);808 if(fail)809 return;810 xnew += tmp;811 }812 else813 {814 tryCRA(i.coeff(),q1,0,q2,M,tmp,tmp2,fail);815 if(fail)816 return;817 xnew += tmp * power(x1.mvar(),i.exp());818 }819 }820 return;821 }822 // here: x1.level() <= x2.level() && ( x1.level() > 1 || x2.level() > 1 )823 if(x2.level() > x1.level())824 {825 for(CFIterator j=x2; j.hasTerms(); j++)826 {827 if(j.exp() == 0) // const. term828 {829 tryCRA(x1,q1,j.coeff(),q2,M,tmp,tmp2,fail);830 if(fail)831 return;832 xnew += tmp;833 }834 else835 {836 tryCRA(0,q1,j.coeff(),q2,M,tmp,tmp2,fail);837 if(fail)838 return;839 xnew += tmp * power(x2.mvar(),j.exp());840 }841 }842 return;843 }844 // here: x1.level() == x2.level() && x1.level() > 1 && x2.level() > 1845 CFIterator i = x1;846 CFIterator j = x2;847 while(i.hasTerms() || j.hasTerms())848 {849 if(i.hasTerms())850 {851 if(j.hasTerms())852 {853 if(i.exp() == j.exp())854 {855 tryCRA(i.coeff(),q1,j.coeff(),q2,M,tmp,tmp2,fail);856 if(fail)857 return;858 xnew += tmp * power(x1.mvar(),i.exp());859 i++; j++;860 }861 else862 {863 if(i.exp() < j.exp())864 {865 tryCRA(i.coeff(),q1,0,q2,M,tmp,tmp2,fail);866 if(fail)867 return;868 xnew += tmp * power(x1.mvar(),i.exp());869 i++;870 }871 else // i.exp() > j.exp()872 {873 tryCRA(0,q1,j.coeff(),q2,M,tmp,tmp2,fail);874 if(fail)875 return;876 xnew += tmp * power(x1.mvar(),j.exp());877 j++;878 }879 }880 }881 else // j is out of terms882 {883 tryCRA(i.coeff(),q1,0,q2,M,tmp,tmp2,fail);884 if(fail)885 return;886 xnew += tmp * power(x1.mvar(),i.exp());887 i++;888 }889 }890 else // i is out of terms891 {892 tryCRA(0,q1,j.coeff(),q2,M,tmp,tmp2,fail);893 if(fail)894 return;895 xnew += tmp * power(x1.mvar(),j.exp());896 j++;897 }898 }899 }900 901 902 804 void tryExtgcd( const CanonicalForm & F, const CanonicalForm & G, const CanonicalForm & M, CanonicalForm & result, CanonicalForm & s, CanonicalForm & t, bool & fail ) 903 805 { // F, G are univariate polynomials (i.e. they have exactly one polynomial variable) … … 1067 969 divides = true; 1068 970 } 1069 1070 1071 971 1072 972 void tryCRA( const CanonicalForm & x1, const CanonicalForm & q1, const CanonicalForm & x2, const CanonicalForm & q2, CanonicalForm & xnew, CanonicalForm & qnew, bool & fail )
Note: See TracChangeset
for help on using the changeset viewer.