Changeset fe2d4c in git
- Timestamp:
- Jun 20, 2011, 2:10:50 PM (12 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- 4e35a894dd1ecea25a42d6b12a182338771e5732
- Parents:
- 35eb6cf319007843f3388d3f071f3bee96188fbd
- Location:
- factory
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/algext.cc
r35eb6c rfe2d4c 14 14 #endif 15 15 16 #include "templates/ftmpl_functions.h" 16 17 #include "cf_defs.h" 17 18 #include "canonicalform.h" … … 23 24 #include "cf_map.h" 24 25 #include "cf_generator.h" 26 27 /// compressing two polynomials F and G, M is used for compressing, 28 /// N to reverse the compression 29 static 30 int myCompress (const CanonicalForm& F, const CanonicalForm& G, CFMap & M, 31 CFMap & N, bool topLevel) 32 { 33 int n= tmax (F.level(), G.level()); 34 int * degsf= new int [n + 1]; 35 int * degsg= new int [n + 1]; 36 37 for (int i = 0; i <= n; i++) 38 degsf[i]= degsg[i]= 0; 39 40 degsf= degrees (F, degsf); 41 degsg= degrees (G, degsg); 42 43 int both_non_zero= 0; 44 int f_zero= 0; 45 int g_zero= 0; 46 int both_zero= 0; 47 48 if (topLevel) 49 { 50 for (int i= 1; i <= n; i++) 51 { 52 if (degsf[i] != 0 && degsg[i] != 0) 53 { 54 both_non_zero++; 55 continue; 56 } 57 if (degsf[i] == 0 && degsg[i] != 0 && i <= G.level()) 58 { 59 f_zero++; 60 continue; 61 } 62 if (degsg[i] == 0 && degsf[i] && i <= F.level()) 63 { 64 g_zero++; 65 continue; 66 } 67 } 68 69 if (both_non_zero == 0) 70 { 71 delete [] degsf; 72 delete [] degsg; 73 return 0; 74 } 75 76 // map Variables which do not occur in both polynomials to higher levels 77 int k= 1; 78 int l= 1; 79 for (int i= 1; i <= n; i++) 80 { 81 if (degsf[i] != 0 && degsg[i] == 0 && i <= F.level()) 82 { 83 if (k + both_non_zero != i) 84 { 85 M.newpair (Variable (i), Variable (k + both_non_zero)); 86 N.newpair (Variable (k + both_non_zero), Variable (i)); 87 } 88 k++; 89 } 90 if (degsf[i] == 0 && degsg[i] != 0 && i <= G.level()) 91 { 92 if (l + g_zero + both_non_zero != i) 93 { 94 M.newpair (Variable (i), Variable (l + g_zero + both_non_zero)); 95 N.newpair (Variable (l + g_zero + both_non_zero), Variable (i)); 96 } 97 l++; 98 } 99 } 100 101 // sort Variables x_{i} in increasing order of 102 // min(deg_{x_{i}}(f),deg_{x_{i}}(g)) 103 int m= tmax (F.level(), G.level()); 104 int min_max_deg; 105 k= both_non_zero; 106 l= 0; 107 int i= 1; 108 while (k > 0) 109 { 110 if (degsf [i] != 0 && degsg [i] != 0) 111 min_max_deg= tmax (degsf[i], degsg[i]); 112 else 113 min_max_deg= 0; 114 while (min_max_deg == 0) 115 { 116 i++; 117 min_max_deg= tmax (degsf[i], degsg[i]); 118 if (degsf [i] != 0 && degsg [i] != 0) 119 min_max_deg= tmax (degsf[i], degsg[i]); 120 else 121 min_max_deg= 0; 122 } 123 for (int j= i + 1; j <= m; j++) 124 { 125 if (tmax (degsf[j],degsg[j]) <= min_max_deg && degsf[j] != 0 && degsg [j] != 0) 126 { 127 min_max_deg= tmax (degsf[j], degsg[j]); 128 l= j; 129 } 130 } 131 if (l != 0) 132 { 133 if (l != k) 134 { 135 M.newpair (Variable (l), Variable(k)); 136 N.newpair (Variable (k), Variable(l)); 137 degsf[l]= 0; 138 degsg[l]= 0; 139 l= 0; 140 } 141 else 142 { 143 degsf[l]= 0; 144 degsg[l]= 0; 145 l= 0; 146 } 147 } 148 else if (l == 0) 149 { 150 if (i != k) 151 { 152 M.newpair (Variable (i), Variable (k)); 153 N.newpair (Variable (k), Variable (i)); 154 degsf[i]= 0; 155 degsg[i]= 0; 156 } 157 else 158 { 159 degsf[i]= 0; 160 degsg[i]= 0; 161 } 162 i++; 163 } 164 k--; 165 } 166 } 167 else 168 { 169 //arrange Variables such that no gaps occur 170 for (int i= 1; i <= n; i++) 171 { 172 if (degsf[i] == 0 && degsg[i] == 0) 173 { 174 both_zero++; 175 continue; 176 } 177 else 178 { 179 if (both_zero != 0) 180 { 181 M.newpair (Variable (i), Variable (i - both_zero)); 182 N.newpair (Variable (i - both_zero), Variable (i)); 183 } 184 } 185 } 186 } 187 188 delete [] degsf; 189 delete [] degsg; 190 191 return 1; 192 } 25 193 26 194 CanonicalForm reduce(const CanonicalForm & f, const CanonicalForm & M) … … 199 367 200 368 201 void tryBrownGCD( const CanonicalForm & F, const CanonicalForm & G, const CanonicalForm & M, CanonicalForm & result, bool & fail )369 void tryBrownGCD( const CanonicalForm & F, const CanonicalForm & G, const CanonicalForm & M, CanonicalForm & result, bool & fail, bool topLevel ) 202 370 { // assume F,G are multivariate polys over Z/p(a) for big prime p, M "univariate" polynomial in an algebraic variable 203 371 // M is assumed to be monic … … 261 429 } 262 430 CFMap MM,NN; 263 CFArray ps(1,2); 264 ps[1] = F; 265 ps[2] = G; 266 compress(ps,MM,NN); // maps MM, NN are created 431 int lev= myCompress (F, G, MM, NN, topLevel); 432 if (lev == 0) 433 { 434 result= 1; 435 return; 436 } 267 437 CanonicalForm f=MM(F); 268 438 CanonicalForm g=MM(G); … … 347 517 if(gamma_image.isZero()) // skip lc-bad points var(1)-alpha 348 518 continue; 349 tryBrownGCD( f(alpha, Variable(1)), g(alpha, Variable(1)), M, g_image, fail ); // recursive call with one var less519 tryBrownGCD( f(alpha, Variable(1)), g(alpha, Variable(1)), M, g_image, fail, false ); // recursive call with one var less 350 520 if(fail) 351 521 return; … … 488 658 q = 1; 489 659 D = 0; 660 CanonicalForm test= 0; 661 bool equal= false; 490 662 for( i=cf_getNumBigPrimes()-1; i>-1; i-- ) 491 663 { … … 530 702 setReduce(a,true); // reduce expressions modulo mipo 531 703 On( SW_RATIONAL ); // needed by fdivides 532 if( fdivides( tmp, f ) && fdivides( tmp, g )) // trial division 704 if (test != tmp) 705 test= tmp; 706 else 707 equal= true; // modular image did not add any new information 708 if(equal && fdivides( tmp, f ) && fdivides( tmp, g )) // trial division 533 709 { 534 710 Off( SW_RATIONAL ); … … 762 938 while(true) 763 939 { 764 tryInvert( Lc(result), M, inv, fail ); 765 if(fail) 766 return; 767 // here: Lc(result) is invertible modulo M 768 q = Lc(P)*inv*power( x, P.degree(x)-result.degree(x) ); 769 rem = reduce( P - q*result, M ); 940 tryDivrem (P, result, q, rem, inv, M, fail); 941 if(fail) 942 return; 770 943 if( rem.isZero() ) 771 944 { -
factory/algext.h
r35eb6c rfe2d4c 14 14 void tryInvert( const CanonicalForm &, const CanonicalForm &, CanonicalForm &, bool & ); 15 15 bool hasFirstAlgVar( const CanonicalForm &, Variable & ); 16 void tryBrownGCD( const CanonicalForm & F, const CanonicalForm & G, const CanonicalForm & M, CanonicalForm & result, bool & fail );16 void tryBrownGCD( const CanonicalForm & F, const CanonicalForm & G, const CanonicalForm & M, CanonicalForm & result, bool & fail, bool topLevel= true ); 17 17 void tryCRA( const CanonicalForm & x1, const CanonicalForm & q1, const CanonicalForm & x2, const CanonicalForm & q2, CanonicalForm & xnew, CanonicalForm & qnew, bool & fail ); 18 18 void tryExtgcd( const CanonicalForm & F, const CanonicalForm & G, CanonicalForm & result, CanonicalForm & s, CanonicalForm & t, bool & fail );
Note: See TracChangeset
for help on using the changeset viewer.