[1a80b4] | 1 | /////////////////////////////////////////////////////////////////////////////// |
---|
[36b7a3] | 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."; |
---|
[1a80b4] | 3 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 4 | // FACTORY - Includes |
---|
| 5 | #include <factory.h> |
---|
[14b1e65] | 6 | #ifndef NOSTREAMIO |
---|
[e2ca88] | 7 | #ifdef HAVE_IOSTREAM |
---|
| 8 | #include <iostream> |
---|
| 9 | #define CERR std::cerr |
---|
| 10 | #define CIN std::cin |
---|
| 11 | #elif defined(HAVE_IOSTREAM_H) |
---|
[14b1e65] | 12 | #include <iostream.h> |
---|
[e2ca88] | 13 | #define CERR cerr |
---|
| 14 | #define CIN cin |
---|
| 15 | #endif |
---|
[14b1e65] | 16 | #endif |
---|
[1a80b4] | 17 | // Factor - Includes |
---|
| 18 | #include "tmpl_inst.h" |
---|
| 19 | #include "SqrFree.h" |
---|
| 20 | #include "helpstuff.h" |
---|
| 21 | #include "MVMultiHensel.h" |
---|
| 22 | #include "Truefactor.h" |
---|
| 23 | #include "homogfactor.h" |
---|
[3e55bc] | 24 | #include "interrupt.h" |
---|
[4a81ec] | 25 | // some CC's need this: |
---|
| 26 | #include "Factor.h" |
---|
| 27 | |
---|
[0be2bc] | 28 | #include "alg_factor.h" |
---|
[a38d45] | 29 | void out_cf(char *s1,const CanonicalForm &f,char *s2); |
---|
| 30 | void out_cff(CFFList &L); |
---|
| 31 | |
---|
[0be2bc] | 32 | |
---|
[1a80b4] | 33 | #ifdef FACTORDEBUG |
---|
| 34 | # define DEBUGOUTPUT |
---|
| 35 | #else |
---|
| 36 | # undef DEBUGOUTPUT |
---|
| 37 | #endif |
---|
| 38 | |
---|
[d92d71] | 39 | #include <libfac/factor/debug.h> |
---|
[1a80b4] | 40 | #include "timing.h" |
---|
[be5dff] | 41 | TIMING_DEFINE_PRINT(factorize_time) |
---|
| 42 | TIMING_DEFINE_PRINT(sqrfree_time) |
---|
| 43 | TIMING_DEFINE_PRINT(discr_time) |
---|
| 44 | TIMING_DEFINE_PRINT(evaluate_time) |
---|
| 45 | TIMING_DEFINE_PRINT(hensel_time) |
---|
| 46 | TIMING_DEFINE_PRINT(truefactor_time) |
---|
[1a80b4] | 47 | |
---|
[1048e0c] | 48 | /* |
---|
| 49 | * a wrapper for factorize over algebraic extensions: |
---|
| 50 | * does a sanity check and, if nec., a conversion |
---|
| 51 | * before calling factorize(f,alpha) |
---|
| 52 | * ( in factorize, alpha.level() must be < 0 ) |
---|
| 53 | */ |
---|
[cd8141] | 54 | static |
---|
[5c4b32] | 55 | CFFList factorize2 ( const CanonicalForm & f, |
---|
[1048e0c] | 56 | const Variable & alpha, const CanonicalForm & mipo ) |
---|
| 57 | { |
---|
| 58 | if (alpha.level() <0) |
---|
[fb4f62e] | 59 | { |
---|
[f152c5] | 60 | return factorize(f,alpha); |
---|
[5c4b32] | 61 | } |
---|
[1048e0c] | 62 | else |
---|
| 63 | { |
---|
| 64 | bool repl=(f.mvar() != alpha); |
---|
| 65 | //out_cf("f2 - factor:",f,"\n"); |
---|
| 66 | //out_cf("f2 - ext:",alpha,"\n"); |
---|
| 67 | //out_cf("f2 - mipo:",mipo,"\n"); |
---|
| 68 | Variable X=rootOf(mipo); |
---|
| 69 | CanonicalForm F=f; |
---|
| 70 | if (repl) F=replacevar(f,alpha,X); |
---|
| 71 | //out_cf("call - factor:",F,"\n"); |
---|
| 72 | //out_cf("call - ext:",X,"\n"); |
---|
| 73 | //out_cf("call - mipo:",getMipo(X,'A'),"\n"); |
---|
| 74 | CFFList L=factorize(F,X); |
---|
| 75 | CFFListIterator i=L; |
---|
| 76 | if (repl) |
---|
| 77 | { |
---|
| 78 | CFFList Outputlist; |
---|
| 79 | for(;i.hasItem(); i++ ) |
---|
| 80 | { |
---|
| 81 | Outputlist.append(CFFactor( |
---|
| 82 | replacevar(i.getItem().factor(),X,alpha), |
---|
| 83 | i.getItem().exp())); |
---|
| 84 | } |
---|
| 85 | return Outputlist; |
---|
| 86 | } |
---|
| 87 | else return L; |
---|
| 88 | } |
---|
| 89 | } |
---|
[1a80b4] | 90 | /////////////////////////////////////////////////////////////// |
---|
| 91 | // Choose a main variable if the user didn`t wish a // |
---|
| 92 | // special one. Returns level of main variable. // |
---|
| 93 | /////////////////////////////////////////////////////////////// |
---|
[0be2bc] | 94 | static int |
---|
[1a80b4] | 95 | choose_main_variable( const CanonicalForm & f, int Mainvar=0){ |
---|
| 96 | CanonicalForm remlc, newlc; |
---|
| 97 | int n= level(f), mainvar= Mainvar; |
---|
| 98 | |
---|
| 99 | if (mainvar != 0) return mainvar ; // We force use of the wished mainvar |
---|
| 100 | remlc= LC(f,n); mainvar = n; |
---|
| 101 | if ( totaldegree(remlc)==0 ){ remlc=f.genOne() ; } |
---|
[e2ca88] | 102 | DEBOUTLN(CERR, "remlc= " , remlc); |
---|
[aa7480c] | 103 | for ( int i=n-1; i>=1; i-- ) |
---|
| 104 | { |
---|
[1a80b4] | 105 | newlc= LC(f,i); |
---|
| 106 | if ( totaldegree(newlc)==0 ){ newlc=f.genOne() ; } |
---|
[e2ca88] | 107 | DEBOUTLN(CERR, "newlc= " , newlc); |
---|
[1a80b4] | 108 | if ( (remlc.isOne()) && (newlc.isOne()) ){ // take care of the degrees |
---|
| 109 | if ( degree(f,i) < degree(f,mainvar) ){ |
---|
[0be2bc] | 110 | remlc= newlc; |
---|
| 111 | mainvar= i; |
---|
[1a80b4] | 112 | } |
---|
| 113 | } |
---|
| 114 | else if ( (! remlc.isOne() ) && ( newlc.isOne() ) ){ |
---|
[0be2bc] | 115 | remlc= newlc; |
---|
[1a80b4] | 116 | mainvar= i; |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | return mainvar; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | /////////////////////////////////////////////////////////////// |
---|
| 123 | // Check if the derivative is nonzero for oldmainvar. // |
---|
| 124 | // Returns the level of the choosen main variable. // |
---|
| 125 | /////////////////////////////////////////////////////////////// |
---|
[0be2bc] | 126 | static int |
---|
[1a80b4] | 127 | necessary_condition( const CanonicalForm & F, int oldmainvar){ |
---|
| 128 | CanonicalForm g; |
---|
| 129 | int n=level(F); |
---|
| 130 | |
---|
[0be2bc] | 131 | g= swapvar(F,oldmainvar,n); |
---|
[1a80b4] | 132 | g= g.deriv(); |
---|
[0be2bc] | 133 | if ( g.isZero() ) |
---|
[52e543] | 134 | { |
---|
| 135 | for ( int i=n; i>=1; i-- ) |
---|
| 136 | { |
---|
[0be2bc] | 137 | g= swapvar(F,i,n); |
---|
[1a80b4] | 138 | g= g.deriv(); |
---|
| 139 | if ( ! g.isZero() ) return i; |
---|
| 140 | } |
---|
[52e543] | 141 | } |
---|
[1a80b4] | 142 | return oldmainvar; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | /////////////////////////////////////////////////////////////// |
---|
| 146 | // Make F monic. Return monic polynomial. // |
---|
| 147 | /////////////////////////////////////////////////////////////// |
---|
[0be2bc] | 148 | static CanonicalForm |
---|
[7fa52c2] | 149 | make_monic( const CanonicalForm & F, const CanonicalForm & lt) |
---|
| 150 | { |
---|
[1a80b4] | 151 | CanonicalForm intermediatpoly,f; |
---|
| 152 | Variable x(level(F)); |
---|
| 153 | |
---|
| 154 | if ( degree(lt) == 0 ) f= 1/lt * F ; |
---|
[7fa52c2] | 155 | else |
---|
| 156 | { |
---|
[1a80b4] | 157 | intermediatpoly= power(lt,degree(F)-1); |
---|
| 158 | for ( int i=0; i<=degree(F); i++ ) |
---|
| 159 | if ( ! F[i].isZero()) |
---|
[0be2bc] | 160 | f+= (F[i] * intermediatpoly*power(x,i))/power(lt,i); |
---|
[1a80b4] | 161 | } |
---|
| 162 | return f; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | /////////////////////////////////////////////////////////////// |
---|
[0be2bc] | 166 | // Decide whether num/denum (num,denum both from the // |
---|
[1a80b4] | 167 | // FiniteFielddomain) lies in the RationalDomain. // |
---|
| 168 | // If false, return num/denum else return the zero poly from // |
---|
| 169 | // the FiniteFielddomain. // |
---|
| 170 | /////////////////////////////////////////////////////////////// |
---|
[0be2bc] | 171 | static CanonicalForm |
---|
[1a80b4] | 172 | is_rational( const CanonicalForm & num, const CanonicalForm & denum ){ |
---|
| 173 | CanonicalForm a, b; |
---|
| 174 | int retvalue; |
---|
| 175 | |
---|
| 176 | retvalue= mydivremt(num,denum,a,b); |
---|
[e89e56] | 177 | if ( retvalue && b == num.genZero() ) // num/denum from FFdomain |
---|
[1a80b4] | 178 | return a; |
---|
| 179 | else // num/denum is rational |
---|
| 180 | return num.genZero(); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | /////////////////////////////////////////////////////////////// |
---|
| 184 | // lt_is_product returns 1 iff lt is a product, 0 iff lt is // |
---|
| 185 | // a sum. // |
---|
| 186 | /////////////////////////////////////////////////////////////// |
---|
[0be2bc] | 187 | static int |
---|
[1a80b4] | 188 | lt_is_product( const CanonicalForm & lt ){ |
---|
| 189 | CFList result; |
---|
| 190 | |
---|
| 191 | result= get_Terms(lt); |
---|
| 192 | if ( result.length() > 1 ) return 0; |
---|
| 193 | else return 1; |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | /////////////////////////////////////////////////////////////// |
---|
| 197 | // Reverse the make_monic transformation. // |
---|
| 198 | // Return the list of factors. // |
---|
| 199 | /////////////////////////////////////////////////////////////// |
---|
[0be2bc] | 200 | static CFFList |
---|
[265aa7] | 201 | not_monic( const CFFList & TheList, const CanonicalForm & ltt, const CanonicalForm & F, int levelF) |
---|
| 202 | { |
---|
[1a80b4] | 203 | CFFList Returnlist,IntermediateList; |
---|
| 204 | CFFListIterator i; |
---|
| 205 | CanonicalForm intermediate,lt= ltt,savelc; |
---|
| 206 | CanonicalForm numerator,denumerator,test,a,b; |
---|
| 207 | Variable x(level(F)); |
---|
| 208 | int test1; |
---|
| 209 | |
---|
[aa7480c] | 210 | if ( lt.isOne() ) return TheList; // the poly was already monic |
---|
[265aa7] | 211 | if ( TheList.length() <= 1 ) // only one factor to substitute back |
---|
| 212 | { |
---|
[1a80b4] | 213 | if ( totaldegree(lt) == 0 ) // lt is type numeric |
---|
| 214 | Returnlist.append( CFFactor(lt*TheList.getFirst().factor(), |
---|
[0be2bc] | 215 | TheList.getFirst().exp()) ); |
---|
[265aa7] | 216 | else |
---|
| 217 | { |
---|
[1a80b4] | 218 | intermediate = F(x*lt, levelF)/power(lt,degree(F,levelF)-1); |
---|
| 219 | Returnlist.append(CFFactor(intermediate,TheList.getFirst().exp())); |
---|
| 220 | } |
---|
| 221 | } |
---|
[265aa7] | 222 | else // more then one factor |
---|
| 223 | { |
---|
[1a80b4] | 224 | IntermediateList= TheList; |
---|
| 225 | if ( totaldegree(lt) == 0 ){ // lt is type numeric;(SqrFree-use, see above) |
---|
| 226 | Returnlist.append( CFFactor(lt*IntermediateList.getFirst().factor() |
---|
[0be2bc] | 227 | , IntermediateList.getFirst().exp()) ); |
---|
[1a80b4] | 228 | IntermediateList.removeFirst(); |
---|
| 229 | Returnlist= Union(Returnlist,IntermediateList); |
---|
| 230 | } |
---|
[265aa7] | 231 | else // lt is a) a product or b) a sum of terms |
---|
| 232 | { |
---|
| 233 | if ( lt_is_product(lt) ) // case a) |
---|
| 234 | { |
---|
[e2ca88] | 235 | DEBOUTLN(CERR, "lt_is_product: ", lt); |
---|
[0be2bc] | 236 | savelc= content(lt) ; // can we simplify to savelc= lc(lt); ? |
---|
| 237 | while ( getNumVars(savelc) != 0 ) |
---|
| 238 | savelc= content(savelc); |
---|
[265aa7] | 239 | for ( i=TheList; i.hasItem();i++ ) |
---|
| 240 | { |
---|
[0be2bc] | 241 | numerator= i.getItem().factor(); |
---|
| 242 | numerator= numerator(x*lt,levelF); // x <- x*lt |
---|
| 243 | denumerator= power(lt,degree(F,levelF)-1); // == lt^(1-degree(F,x) |
---|
[e89e56] | 244 | while (numerator.genZero() == is_rational(numerator, denumerator)) |
---|
[0be2bc] | 245 | numerator*= lt; |
---|
| 246 | intermediate= is_rational(numerator,denumerator); |
---|
| 247 | |
---|
| 248 | Returnlist.append( CFFactor(lc(content(intermediate))*intermediate/content(intermediate), i.getItem().exp() ) ); |
---|
| 249 | } |
---|
| 250 | // Now we add a test. If product(factors)/F is a multiple of |
---|
| 251 | // savelc, we have to add 1/multiplicity to the factors |
---|
| 252 | IntermediateList= Returnlist; |
---|
| 253 | intermediate= 1; |
---|
| 254 | for ( CFFListIterator j=IntermediateList; j.hasItem(); j++) |
---|
| 255 | intermediate*= j.getItem().factor(); |
---|
| 256 | test1= mydivremt( intermediate,F,a,b); |
---|
[e89e56] | 257 | if ( test1 && b == intermediate.genZero() ) // Yupp! |
---|
[265aa7] | 258 | { |
---|
[0be2bc] | 259 | IntermediateList.append(CFFactor(1/a,1)); |
---|
| 260 | Returnlist= IntermediateList; |
---|
| 261 | } |
---|
| 262 | else { Returnlist= IntermediateList; } |
---|
[1a80b4] | 263 | } |
---|
[265aa7] | 264 | else // case b) |
---|
| 265 | { |
---|
[e2ca88] | 266 | DEBOUTLN(CERR, "lt_is_sum: ", lt); |
---|
[0be2bc] | 267 | CanonicalForm save_denumerator= 1; |
---|
[265aa7] | 268 | for ( i=TheList; i.hasItem(); i++ ) |
---|
| 269 | { |
---|
[0be2bc] | 270 | numerator= i.getItem().factor(); |
---|
| 271 | numerator= numerator(x*lt,levelF); // x <- x*lt |
---|
| 272 | denumerator= power(lt,degree(numerator,levelF)); // == lt^(-degree(numerator,x) |
---|
| 273 | test= content(numerator,x); |
---|
| 274 | test1= mydivremt(denumerator,test,a,b); |
---|
[e89e56] | 275 | if ( test1 && b == numerator.genZero() ) // Yupp! |
---|
[265aa7] | 276 | { |
---|
[0be2bc] | 277 | save_denumerator*= a; |
---|
| 278 | Returnlist.append(CFFactor(numerator/test ,1)); |
---|
| 279 | } |
---|
[265aa7] | 280 | else |
---|
| 281 | { |
---|
[a13956] | 282 | factoryError("libfac: ERROR: not_monic1: case lt is a sum."); |
---|
[0be2bc] | 283 | } |
---|
| 284 | } |
---|
| 285 | // Now we add a test if we did the right thing: |
---|
| 286 | // save_denumerator should be a multiple of the leading coeff |
---|
| 287 | test1= mydivremt(save_denumerator,lt,a,b); |
---|
[e89e56] | 288 | if ( test1 && b == save_denumerator.genZero() ) // Yupp! |
---|
[0be2bc] | 289 | // We have to multiply one of the factors with |
---|
| 290 | // the multiplicity of the save_denumerator <-> lc |
---|
| 291 | // the following will do what we want |
---|
[e89e56] | 292 | Returnlist= myUnion( CFFList(CFFactor(1/a,1)),Returnlist) ; |
---|
[265aa7] | 293 | else |
---|
| 294 | { |
---|
[a13956] | 295 | factoryError("libfac: ERROR: not_monic2: case lt is a sum."); |
---|
[0be2bc] | 296 | } |
---|
[1a80b4] | 297 | } |
---|
| 298 | } |
---|
| 299 | } |
---|
[e2ca88] | 300 | DEBOUTLN(CERR,"Returnlist: ", Returnlist); |
---|
[1a80b4] | 301 | return Returnlist; |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | /////////////////////////////////////////////////////////////// |
---|
| 305 | // Substitute the (Variable,Value)-Pair(s) from Substitution-// |
---|
| 306 | // list into the polynomial F. Returns the resulting poly. // |
---|
| 307 | /////////////////////////////////////////////////////////////// |
---|
[0be2bc] | 308 | static CanonicalForm |
---|
[1a80b4] | 309 | substitutePoly( const CanonicalForm & F, const SFormList & Substitutionlist){ |
---|
| 310 | CanonicalForm f= F; |
---|
| 311 | |
---|
| 312 | for ( SFormListIterator i=Substitutionlist; i.hasItem(); i++ ) |
---|
| 313 | f= f(i.getItem().exp(),level(i.getItem().factor())); |
---|
| 314 | return f; |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | /////////////////////////////////////////////////////////////// |
---|
| 318 | // Find specialization values for the poly F. Returns 0 if // |
---|
| 319 | // procedure failed, 1 otherwise. On success Substitutionlist// |
---|
| 320 | // holds (Variable,Value)-pairs. On failure we only have a // |
---|
| 321 | // partitial list. // |
---|
| 322 | /////////////////////////////////////////////////////////////// |
---|
| 323 | // *** This is the version with extensions *** // |
---|
| 324 | /////////////////////////////////////////////////////////////// |
---|
| 325 | |
---|
| 326 | /////////////////////////////////////////////////////////////// |
---|
| 327 | // is CF g ok? // |
---|
| 328 | /////////////////////////////////////////////////////////////// |
---|
| 329 | static int |
---|
[aa7480c] | 330 | various_tests( const CanonicalForm & g, int deg, int vars_left) |
---|
| 331 | { |
---|
[1a80b4] | 332 | CFMap m; |
---|
| 333 | |
---|
| 334 | if ( degree(g) == deg ) // degrees match |
---|
| 335 | if ( level(compress(g,m)) == (vars_left) ) // exactly one variable less |
---|
[e89e56] | 336 | if ( SqrFreeTest(g,1) ) // poly is sqrfree |
---|
[aa7480c] | 337 | if ( gcd(g,g.deriv()).isOne() ) // Discriminante != 0 |
---|
[0be2bc] | 338 | return 1; |
---|
[1a80b4] | 339 | return 0; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | /////////////////////////////////////////////////////////////// |
---|
| 343 | // specialize one variable over the given field. // |
---|
| 344 | /////////////////////////////////////////////////////////////// |
---|
[0be2bc] | 345 | // substitutes in poly f of degree deg with former |
---|
[1a80b4] | 346 | // former_nr_of_variables variables the variable nr_of_variable ; |
---|
| 347 | // this is done in the field of Char getCharacteristic() and |
---|
| 348 | // Extension given by Extgenerator. |
---|
| 349 | /////////////////////////////////////////////////////////////// |
---|
| 350 | static int |
---|
[b96e07] | 351 | specialize_variable( CanonicalForm & f, int deg, SFormList & Substitutionlist, int nr_of_variable, |
---|
| 352 | int former_nr_of_variables, CFGenerator & Extgenerator ){ |
---|
| 353 | CanonicalForm g; |
---|
| 354 | Variable x(nr_of_variable); |
---|
| 355 | |
---|
[e2ca88] | 356 | DEBOUTLN(CERR, "specialize_variable: called with: ", f); |
---|
[b96e07] | 357 | for ( Extgenerator.reset(); Extgenerator.hasItems(); Extgenerator.next() ){ |
---|
[e2ca88] | 358 | DEBOUTLN(CERR, " specialize_variable: trying: ", Extgenerator.item()); |
---|
[b96e07] | 359 | g= f( Extgenerator.item(), x ); |
---|
[e2ca88] | 360 | DEBOUTLN(CERR, " specialize_variable: resulting g= ", g); |
---|
[b96e07] | 361 | if ( various_tests(g,deg,former_nr_of_variables - nr_of_variable ) ){ |
---|
| 362 | Substitutionlist.insert(SForm(x,Extgenerator.item())); // append (Var,value) pair |
---|
| 363 | f= g; |
---|
| 364 | return 1; |
---|
| 365 | } |
---|
| 366 | } |
---|
| 367 | return 0; |
---|
| 368 | } |
---|
| 369 | static int |
---|
| 370 | specialize_agvariable( CanonicalForm & f, int deg, SFormList & Substitutionlist, int nr_of_variable, |
---|
| 371 | int former_nr_of_variables, AlgExtGenerator & Extgenerator ){ |
---|
[1a80b4] | 372 | CanonicalForm g; |
---|
| 373 | Variable x(nr_of_variable); |
---|
| 374 | |
---|
[e2ca88] | 375 | DEBOUTLN(CERR, "specialize_variable: called with: ", f); |
---|
[1a80b4] | 376 | for ( Extgenerator.reset(); Extgenerator.hasItems(); Extgenerator.next() ){ |
---|
[e2ca88] | 377 | DEBOUTLN(CERR, " specialize_variable: trying: ", Extgenerator.item()); |
---|
[1a80b4] | 378 | g= f( Extgenerator.item(), x ); |
---|
[e2ca88] | 379 | DEBOUTLN(CERR, " specialize_variable: resulting g= ", g); |
---|
[0be2bc] | 380 | if ( various_tests(g,deg,former_nr_of_variables - nr_of_variable ) ){ |
---|
[1a80b4] | 381 | Substitutionlist.insert(SForm(x,Extgenerator.item())); // append (Var,value) pair |
---|
| 382 | f= g; |
---|
| 383 | return 1; |
---|
| 384 | } |
---|
| 385 | } |
---|
| 386 | return 0; |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | /////////////////////////////////////////////////////////////// |
---|
| 390 | // generate a minpoly of degree degree_of_Extension in the // |
---|
| 391 | // field getCharacteristik()^Extension. // |
---|
| 392 | /////////////////////////////////////////////////////////////// |
---|
[4a81ec] | 393 | CanonicalForm |
---|
[1a80b4] | 394 | generate_mipo( int degree_of_Extension , const Variable & Extension ){ |
---|
[0be2bc] | 395 | FFRandom gen; |
---|
| 396 | if ( degree(Extension) > 0 ) GFRandom gen; |
---|
[1a80b4] | 397 | else { |
---|
| 398 | if ( degree(Extension) == 0 ) FFRandom gen; |
---|
[a13956] | 399 | else |
---|
| 400 | { |
---|
| 401 | factoryError("libfac: evaluate: Extension not inFF() or inGF() !"); |
---|
[1a80b4] | 402 | } |
---|
| 403 | } |
---|
| 404 | return find_irreducible( degree_of_Extension, gen, Variable(1) ); |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | /////////////////////////////////////////////////////////////// |
---|
| 408 | // Try to find a specialization for f over the field of char // |
---|
| 409 | // f.getCharacteristic() and (possible) extension defined by // |
---|
| 410 | // the variable Extension . // |
---|
| 411 | // Returns 1 iff specialisation was found, 0 otherwise. // |
---|
| 412 | // If 0 is returned there are variables left to substitute. // |
---|
| 413 | // We check if Substitutionlist.length() > 0, i.e. we // |
---|
| 414 | // previously tried to find specialization values for some // |
---|
| 415 | // values. We take them and work with the resulting poly. // |
---|
| 416 | /////////////////////////////////////////////////////////////// |
---|
| 417 | static int |
---|
[38e7b3] | 418 | try_specializePoly(const CanonicalForm & f, const Variable & Extension, int deg, SFormList & Substitutionlist, int ii,int j) |
---|
| 419 | { |
---|
[1a80b4] | 420 | int ok,i= ii; |
---|
| 421 | CanonicalForm ff= f; |
---|
| 422 | |
---|
| 423 | if ( Substitutionlist.length() > 0 ){ // we formerly tried to specialize |
---|
| 424 | ff= substitutePoly(f,Substitutionlist); // substitute found values |
---|
| 425 | i= Substitutionlist.length() + 1; |
---|
| 426 | } |
---|
| 427 | |
---|
[38e7b3] | 428 | if ( degree(Extension) > 0 ) |
---|
| 429 | { // working over Extensions |
---|
[e2ca88] | 430 | DEBOUTLN(CERR, "try_specializePoly: working over Extensions: ", Extension); |
---|
[38e7b3] | 431 | if (Extension.level() > 0) |
---|
| 432 | { |
---|
| 433 | // AlgExtGenerator g(Extension,minpoly ); |
---|
| 434 | // for ( int k=i ; k<j ; k++ ) // try to find specialization for all |
---|
| 435 | // { // variables (# = k ) beginning with the |
---|
| 436 | // // starting value i |
---|
| 437 | // ok= specialize_agvariable( ff, deg, Substitutionlist, k, j, g ); |
---|
| 438 | // if ( ! ok ) return 0; // we failed |
---|
| 439 | // } |
---|
[52e543] | 440 | #ifndef NDEBUG |
---|
[7cb56a9] | 441 | //printf("libfac: try_specializePoly: extension level >0\n"); |
---|
[52e543] | 442 | #endif |
---|
[38e7b3] | 443 | return 0; // we failed |
---|
| 444 | } |
---|
| 445 | else |
---|
| 446 | { |
---|
| 447 | AlgExtGenerator g(Extension); |
---|
| 448 | for ( int k=i ; k<j ; k++ ) // try to find specialization for all |
---|
| 449 | { // variables (# = k ) beginning with the |
---|
[1a80b4] | 450 | // starting value i |
---|
[38e7b3] | 451 | ok= specialize_agvariable( ff, deg, Substitutionlist, k, j, g ); |
---|
| 452 | if ( ! ok ) return 0; // we failed |
---|
| 453 | } |
---|
[1a80b4] | 454 | } |
---|
| 455 | } |
---|
| 456 | else{ // working over the ground-field |
---|
| 457 | FFGenerator g; |
---|
[e2ca88] | 458 | DEBOUTMSG(CERR, "try_specializePoly: working over the ground-field."); |
---|
[1a80b4] | 459 | for ( int k=i ; k<j ; k++ ){ |
---|
| 460 | ok= specialize_variable( ff, deg, Substitutionlist, k, j, g ); |
---|
| 461 | if ( ! ok ) return 0; // we failed |
---|
| 462 | } |
---|
| 463 | } |
---|
| 464 | return 1; |
---|
| 465 | } |
---|
| 466 | |
---|
| 467 | static int |
---|
| 468 | specializePoly(const CanonicalForm & f, Variable & Extension, int deg, SFormList & Substitutionlist, int i,int j){ |
---|
| 469 | Variable minpoly= Extension; |
---|
| 470 | int ok,extended= degree(Extension), working_over_extension; |
---|
| 471 | |
---|
| 472 | // Remember if we are working over an extension-field |
---|
| 473 | if ( extended >= 2 ) { working_over_extension = 1; } |
---|
| 474 | else { working_over_extension = 0; extended = 1; } |
---|
| 475 | // First try: |
---|
| 476 | ok = try_specializePoly(f,minpoly,deg,Substitutionlist,i,j); |
---|
| 477 | while ( ! ok ){ // we have to extend! |
---|
| 478 | extended+= 1; |
---|
| 479 | if ( ! working_over_extension ){ |
---|
| 480 | minpoly= rootOf(generate_mipo( extended,Extension )); |
---|
| 481 | Extension= minpoly; |
---|
| 482 | ok= try_specializePoly(f,minpoly,deg,Substitutionlist,i,j); |
---|
| 483 | } |
---|
[a13956] | 484 | else |
---|
| 485 | { |
---|
| 486 | factoryError("libfac: spezializePoly ERROR: Working over given extension-field not yet implemented!"); |
---|
[1a80b4] | 487 | return 0; |
---|
| 488 | } |
---|
| 489 | } |
---|
| 490 | return 1; |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | |
---|
| 494 | // This is a procedure to play with: lot's of parameters! |
---|
| 495 | // returns: 0 iff no success (possibly because Extension isn't great enough |
---|
| 496 | // >0 iff g (univariate) splits into n factors; |
---|
| 497 | // if n>0 BestEvaluationpoint contains the choice of values for the variables |
---|
| 498 | // |
---|
| 499 | // tries to find at least maxtries evaluation points |
---|
| 500 | // if g factored sametries into the same number of poly's the procedure stops |
---|
| 501 | // if we tried failtries evaluations not found valid, we stop. Perhaps |
---|
| 502 | // Extension isn't big enough! |
---|
| 503 | static int |
---|
[1048e0c] | 504 | evaluate( int maxtries, int sametries, int failtries, const CanonicalForm &f , const Variable & Extension, const CanonicalForm &mipo, SFormList & BestEvaluationpoint, CFFList & BestFactorisation ){ |
---|
[1a80b4] | 505 | int minfactors=degree(f),degf=degree(f),n=level(f.mvar())-1; |
---|
| 506 | SFormList minEvaluation; |
---|
| 507 | CFFList minFactorisation; |
---|
| 508 | int samefactors=0, failedfactor=0, tried=0; |
---|
| 509 | FFRandom gen; |
---|
| 510 | CFFList unilist; |
---|
| 511 | |
---|
[0be2bc] | 512 | if ( degree(Extension) >0 ) GFRandom gen; |
---|
[a13956] | 513 | else |
---|
| 514 | { |
---|
| 515 | if ( degree(Extension) == 0 ) FFRandom gen; |
---|
| 516 | else |
---|
| 517 | { |
---|
| 518 | factoryError("libfac: evaluate: Extension not inFF() or inGF() !"); |
---|
| 519 | } |
---|
| 520 | } |
---|
[1a80b4] | 521 | REvaluation k(1,n,gen); |
---|
[4a81ec] | 522 | k.nextpoint(); |
---|
[a13956] | 523 | for ( int i=1; i<=maxtries ; i++) |
---|
| 524 | { |
---|
[4a81ec] | 525 | // k.nextpoint(); |
---|
[1a80b4] | 526 | SFormList Substitutionlist; |
---|
| 527 | for ( int j=1; j<=n; j++ ) |
---|
[0be2bc] | 528 | Substitutionlist.insert(SForm(Variable(j),k[j])); |
---|
[1a80b4] | 529 | k.nextpoint(); |
---|
| 530 | CanonicalForm g=substitutePoly(f,Substitutionlist); |
---|
[a13956] | 531 | if ( various_tests(g, degf,1) ) |
---|
| 532 | { // found a valid point |
---|
[1a80b4] | 533 | failedfactor = 0; tried += 1; |
---|
| 534 | if ( degree(Extension) == 0 ) |
---|
[0be2bc] | 535 | unilist = factorize(g,1); // poly is sqr-free! |
---|
[1a80b4] | 536 | else |
---|
[b4ea1d] | 537 | { |
---|
[1048e0c] | 538 | unilist = factorize2(g,Extension,mipo); |
---|
| 539 | } |
---|
[aa7480c] | 540 | if (unilist.length() <= minfactors ) |
---|
| 541 | { |
---|
[0be2bc] | 542 | minfactors=unilist.length(); |
---|
| 543 | minEvaluation=Substitutionlist; |
---|
| 544 | minFactorisation=unilist; |
---|
[1a80b4] | 545 | } |
---|
| 546 | else samefactors +=1; |
---|
| 547 | |
---|
[aa7480c] | 548 | if (unilist.length() == 1 ) // wow! we found f is irreducible! |
---|
| 549 | { |
---|
[0be2bc] | 550 | BestEvaluationpoint=minEvaluation; |
---|
| 551 | BestFactorisation=minFactorisation; |
---|
| 552 | return 1; |
---|
[1a80b4] | 553 | } |
---|
| 554 | |
---|
[aa7480c] | 555 | if ( samefactors >= sametries ) // now we stop ( maybe polynomial *has* |
---|
| 556 | // minfactors factors? ) |
---|
| 557 | { |
---|
[0be2bc] | 558 | BestEvaluationpoint=minEvaluation; |
---|
| 559 | BestFactorisation=minFactorisation; |
---|
| 560 | return minfactors; |
---|
[1a80b4] | 561 | } |
---|
| 562 | |
---|
| 563 | } |
---|
[aa7480c] | 564 | else |
---|
| 565 | failedfactor += 1; |
---|
[1a80b4] | 566 | |
---|
[aa7480c] | 567 | if ( failedfactor >= failtries ) // now we stop ( perhaps Extension isn't |
---|
| 568 | // big enough ) |
---|
| 569 | { |
---|
[1a80b4] | 570 | if ( tried == 0 ) |
---|
[0be2bc] | 571 | return 0; |
---|
[aa7480c] | 572 | else |
---|
| 573 | { |
---|
[0be2bc] | 574 | BestEvaluationpoint=minEvaluation; |
---|
| 575 | BestFactorisation=minFactorisation; |
---|
| 576 | return minfactors; |
---|
[1a80b4] | 577 | } |
---|
| 578 | } |
---|
| 579 | } |
---|
| 580 | BestEvaluationpoint=minEvaluation; |
---|
| 581 | BestFactorisation=minFactorisation; |
---|
| 582 | return minfactors; |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | /////////////////////////////////////////////////////////////// |
---|
| 586 | // A factorization routine for a sqrfree polynomial. // |
---|
| 587 | // Returns the list of factors. // |
---|
| 588 | /////////////////////////////////////////////////////////////// |
---|
[0be2bc] | 589 | CFFList |
---|
[8de151] | 590 | Factorized( const CanonicalForm & F, const CanonicalForm & alpha, int Mainvar) |
---|
| 591 | { |
---|
[1a80b4] | 592 | CanonicalForm f,lt,ff,ffuni; |
---|
[639047e] | 593 | Variable Extension=alpha.mvar(); |
---|
[1a80b4] | 594 | CFFList Outputlist,UnivariateFactorlist,Outputlist2; |
---|
| 595 | SFormList Substitutionlist, Evaluationpoint; |
---|
| 596 | CFFactor copy; |
---|
| 597 | int mainvar=Mainvar,success,oldmainvar; |
---|
| 598 | CFMap m; |
---|
| 599 | |
---|
[3e55bc] | 600 | // INTERRUPTHANDLER |
---|
| 601 | if ( interrupt_handle() ) return CFFList() ; |
---|
| 602 | // INTERRUPTHANDLER |
---|
| 603 | |
---|
[924d8f] | 604 | if (F.inCoeffDomain()) { return CFFList(CFFactor(F,1)); } |
---|
[8de151] | 605 | if ( F.isUnivariate() ) // could have lost one Variable elsewhere |
---|
| 606 | { |
---|
| 607 | if ( degree(Extension) == 0 ) |
---|
| 608 | { |
---|
[1a80b4] | 609 | TIMING_START(evaluate_time); |
---|
| 610 | Outputlist = factorize(F,1); // poly is sqr-free |
---|
| 611 | TIMING_END(evaluate_time); |
---|
| 612 | return Outputlist; |
---|
| 613 | } |
---|
[8de151] | 614 | else |
---|
| 615 | { |
---|
[1048e0c] | 616 | if (Extension.level()<0) |
---|
[e2ca88] | 617 | DEBOUTLN(CERR, "Univ. Factorization over extension of degree ", |
---|
[0be2bc] | 618 | degree(getMipo(Extension,'x')) ); |
---|
[5c4b32] | 619 | else |
---|
[e2ca88] | 620 | DEBOUTLN(CERR, "Univ. Factorization over extension of level ??", |
---|
[1048e0c] | 621 | Extension.level()); |
---|
[1a80b4] | 622 | TIMING_START(evaluate_time); |
---|
[f152c5] | 623 | Outputlist = factorize2(F,Extension,alpha); |
---|
[1a80b4] | 624 | TIMING_END(evaluate_time); |
---|
| 625 | return Outputlist; |
---|
| 626 | } |
---|
| 627 | } |
---|
| 628 | |
---|
| 629 | if ( Mainvar ) oldmainvar=Mainvar; else oldmainvar=level(F); |
---|
| 630 | // First choose a main variable; this may be revisted in the next step |
---|
| 631 | mainvar = choose_main_variable(F); |
---|
| 632 | // Let`s look if @f/@mainvar is nonzero |
---|
| 633 | mainvar = necessary_condition(F,mainvar); |
---|
| 634 | // Now we have definetly choosen a main variable |
---|
| 635 | // swap poly such that the mainvar has highest level |
---|
| 636 | f=swapvar(F,mainvar,level(F)); |
---|
[0be2bc] | 637 | |
---|
[3e55bc] | 638 | // INTERRUPTHANDLER |
---|
| 639 | if ( interrupt_handle() ) return CFFList() ; |
---|
| 640 | // INTERRUPTHANDLER |
---|
| 641 | |
---|
[1a80b4] | 642 | if ( oldmainvar != mainvar ){ |
---|
[e2ca88] | 643 | DEBOUTSL(CERR); DEBOUT(CERR,"Swapped poly ", F); |
---|
| 644 | DEBOUT(CERR, " in ", f); DEBOUTNL(CERR); |
---|
| 645 | DEBOUTSL(CERR); DEBOUT(CERR,"Swapped ", oldmainvar ); |
---|
| 646 | DEBOUT(CERR, " <-- ", mainvar ); DEBOUT(CERR, " Mainvar= ", f.mvar()); |
---|
| 647 | DEBOUTNL(CERR); |
---|
[1a80b4] | 648 | ff = f.deriv(); |
---|
| 649 | TIMING_START(discr_time); |
---|
[38e7b3] | 650 | ffuni = gcd(f,ff); |
---|
[1a80b4] | 651 | TIMING_END(discr_time); |
---|
[20722e4] | 652 | if ( !(ffuni.isOne()) ){ //discriminante nonzero: split poly |
---|
[e2ca88] | 653 | DEBOUTLN(CERR,"Nontrivial GCD of f= ", f); |
---|
| 654 | DEBOUTLN(CERR," and @f= ", ff); |
---|
| 655 | DEBOUTLN(CERR," GCD(f,@f)= ", ffuni); |
---|
[1a80b4] | 656 | ff=f/ffuni; |
---|
| 657 | CFFList Outputlist_a, Outputlist_b; |
---|
| 658 | Outputlist_a = Factorized(ff,alpha); |
---|
[e2ca88] | 659 | DEBOUTLN(CERR, "Outputlist_a = ", Outputlist_a); |
---|
[1a80b4] | 660 | Outputlist_b = Factorized(ffuni,alpha); |
---|
[e2ca88] | 661 | DEBOUTLN(CERR, "Outputlist_b = ", Outputlist_b); |
---|
[e89e56] | 662 | Outputlist = myUnion(Outputlist_a, Outputlist_b); |
---|
[1a80b4] | 663 | // have to back-swapvar the factors.... |
---|
| 664 | for ( CFFListIterator i=Outputlist; i.hasItem(); i++ ){ |
---|
[0be2bc] | 665 | copy=i.getItem(); |
---|
| 666 | Outputlist2.append(CFFactor(swapvar(copy.factor(),oldmainvar,mainvar),copy.exp())); |
---|
[1a80b4] | 667 | } |
---|
[e2ca88] | 668 | DEBOUTLN(CERR, "Outputlist2 (a+b swapped) (to return) = ", Outputlist2); |
---|
[1a80b4] | 669 | return Outputlist2; |
---|
| 670 | } |
---|
| 671 | } |
---|
| 672 | |
---|
| 673 | // Check special cases |
---|
| 674 | for ( int i=1; i<=level(F); i++) |
---|
[aa7480c] | 675 | { |
---|
[8e0cdf] | 676 | if ( degree(f,Variable(i) ) == 1 ) |
---|
[aa7480c] | 677 | //test trivial case; only true iff F is primitiv w.r.t every variable; else check (if F=ax+b) gcd(a,b)=1 ? |
---|
| 678 | { |
---|
[e2ca88] | 679 | DEBOUTLN(CERR, "Trivial case: ", F); |
---|
[1a80b4] | 680 | Outputlist.append(CFFactor(F,1)); |
---|
| 681 | return Outputlist; |
---|
| 682 | } |
---|
[aa7480c] | 683 | } |
---|
[1a80b4] | 684 | |
---|
| 685 | // Look at the leading term: |
---|
| 686 | lt = LC(f); |
---|
[e2ca88] | 687 | DEBOUTLN(CERR, "Leading term: ", lt); |
---|
[aa7480c] | 688 | //if ( lt != f.genOne() ) |
---|
| 689 | if ( !lt.isOne() ) |
---|
[38e7b3] | 690 | { |
---|
[1a80b4] | 691 | // make the polynomial monic in the main variable |
---|
| 692 | ff = make_monic(f,lt); ffuni = ff; |
---|
[e2ca88] | 693 | DEBOUTLN(CERR, "make_monic returned: ", ff); |
---|
[1a80b4] | 694 | } |
---|
| 695 | else{ ff= f; ffuni= ff; } |
---|
| 696 | |
---|
| 697 | TIMING_START(evaluate_time); |
---|
[1048e0c] | 698 | success=evaluate(min(10,max(degree(ff), 5)), min(degree(ff),3), min(degree(ff),3), ff, Extension, alpha, Substitutionlist,UnivariateFactorlist); |
---|
[e2ca88] | 699 | DEBOUTLN(CERR, "Returned from evaluate: success: ", success); |
---|
[38e7b3] | 700 | for ( SFormListIterator ii=Substitutionlist; ii.hasItem(); ii++ ) |
---|
| 701 | { |
---|
[e2ca88] | 702 | DEBOUTLN(CERR, "Substituting ", ii.getItem().factor()); |
---|
| 703 | DEBOUTLN(CERR, " with value: ", ii.getItem().exp()); |
---|
[1a80b4] | 704 | } |
---|
| 705 | |
---|
[38e7b3] | 706 | if ( success==0 ) // evalute wasn't successfull |
---|
| 707 | { |
---|
[1a80b4] | 708 | success= specializePoly(ffuni,Extension,degree(ff),Substitutionlist,1,getNumVars(compress(ff,m))); |
---|
[e2ca88] | 709 | DEBOUTLN(CERR, "Returned from specializePoly: success: ", success); |
---|
[38e7b3] | 710 | if (success == 0 ) // No spezialisation could be found |
---|
| 711 | { |
---|
[a13956] | 712 | factoryError("libfac: Factorize: ERROR: Not able to find a valid specialization!"); |
---|
[1a80b4] | 713 | Outputlist.append(CFFactor(F,1)); |
---|
| 714 | return Outputlist; |
---|
| 715 | } |
---|
[3e55bc] | 716 | |
---|
| 717 | // INTERRUPTHANDLER |
---|
| 718 | if ( interrupt_handle() ) return CFFList() ; |
---|
| 719 | // INTERRUPTHANDLER |
---|
| 720 | |
---|
[1a80b4] | 721 | ffuni = substitutePoly(ff,Substitutionlist); |
---|
| 722 | // We now have an univariat poly; factorize that |
---|
[38e7b3] | 723 | if ( degree(Extension) == 0 ) |
---|
| 724 | { |
---|
[e2ca88] | 725 | DEBOUTMSG(CERR, "Univ. Factorization over the ground field"); |
---|
[1a80b4] | 726 | UnivariateFactorlist = factorize(ffuni,1); // univ. poly is sqr-free! |
---|
| 727 | } |
---|
[38e7b3] | 728 | else |
---|
| 729 | { |
---|
[e2ca88] | 730 | DEBOUTLN(CERR, "Univ. Factorization over extension of degree ", |
---|
[0be2bc] | 731 | degree(getMipo(Extension,'x')) ); |
---|
[1048e0c] | 732 | UnivariateFactorlist = factorize2(ffuni,Extension,alpha); |
---|
[1a80b4] | 733 | } |
---|
| 734 | } |
---|
[38e7b3] | 735 | else |
---|
| 736 | { |
---|
[0be2bc] | 737 | ffuni = substitutePoly(ff,Substitutionlist); |
---|
[1a80b4] | 738 | } |
---|
| 739 | TIMING_END(evaluate_time); |
---|
[38e7b3] | 740 | if (UnivariateFactorlist.length() == 1) |
---|
| 741 | { // poly is irreduzibel |
---|
[e2ca88] | 742 | DEBOUTLN(CERR, "Univ. poly is irreduzible: ", UnivariateFactorlist); |
---|
[1a80b4] | 743 | Outputlist.append(CFFactor(F,1)); |
---|
| 744 | return Outputlist; |
---|
| 745 | } |
---|
[38e7b3] | 746 | else |
---|
| 747 | { // we have factors |
---|
[e2ca88] | 748 | DEBOUTSL(CERR); |
---|
| 749 | DEBOUT(CERR, "Univariate poly has " , UnivariateFactorlist.length()); |
---|
| 750 | DEBOUT(CERR, " factors: ", ffuni); |
---|
| 751 | DEBOUT(CERR, " = ", UnivariateFactorlist); DEBOUTNL(CERR); |
---|
[1a80b4] | 752 | |
---|
[3e55bc] | 753 | // INTERRUPTHANDLER |
---|
| 754 | if ( interrupt_handle() ) return CFFList() ; |
---|
| 755 | // INTERRUPTHANDLER |
---|
| 756 | |
---|
[1a80b4] | 757 | TIMING_START(hensel_time); |
---|
[8de151] | 758 | Outputlist = MultiHensel(ff,UnivariateFactorlist,Substitutionlist, alpha); |
---|
[e2ca88] | 759 | DEBOUTLN(CERR, "Outputlist after MultiHensel: ", Outputlist); |
---|
[1a80b4] | 760 | TIMING_END(hensel_time); |
---|
| 761 | |
---|
[3e55bc] | 762 | // INTERRUPTHANDLER |
---|
| 763 | if ( interrupt_handle() ) return CFFList() ; |
---|
| 764 | // INTERRUPTHANDLER |
---|
| 765 | |
---|
[1a80b4] | 766 | TIMING_START(truefactor_time); |
---|
| 767 | Outputlist = Truefactors(ff, level(ff), Substitutionlist, Outputlist); |
---|
[e2ca88] | 768 | DEBOUTLN(CERR, "Outputlist after Truefactors: ", Outputlist); |
---|
[1a80b4] | 769 | TIMING_END(truefactor_time); |
---|
| 770 | |
---|
[3e55bc] | 771 | // INTERRUPTHANDLER |
---|
| 772 | if ( interrupt_handle() ) return CFFList() ; |
---|
| 773 | // INTERRUPTHANDLER |
---|
| 774 | |
---|
[aa7480c] | 775 | //if ( lt != f.genOne() ) |
---|
| 776 | if ( !lt.isOne() ) |
---|
[52e543] | 777 | { |
---|
[1a80b4] | 778 | Outputlist = not_monic(Outputlist,lt,ff,level(ff)); |
---|
[e2ca88] | 779 | DEBOUTLN(CERR, "not_monic returned: ", Outputlist); |
---|
[1a80b4] | 780 | } |
---|
| 781 | |
---|
| 782 | // have to back-swapvar the factors.... |
---|
[52e543] | 783 | for ( CFFListIterator i=Outputlist; i.hasItem(); i++ ) |
---|
| 784 | { |
---|
| 785 | copy=i.getItem(); |
---|
| 786 | Outputlist2.append(CFFactor(swapvar(copy.factor(),oldmainvar,mainvar),copy.exp())); |
---|
[1a80b4] | 787 | } |
---|
| 788 | |
---|
| 789 | return Outputlist2; |
---|
| 790 | } |
---|
| 791 | } |
---|
| 792 | |
---|
[5299b6] | 793 | int cmpCF( const CFFactor & f, const CFFactor & g ); |
---|
| 794 | |
---|
[1a80b4] | 795 | /////////////////////////////////////////////////////////////// |
---|
| 796 | // The user front-end for a uni/multivariate factorization // |
---|
| 797 | // routine. F needs not to be SqrFree. // |
---|
| 798 | // Option of * choosing a main variable (n.y.i.) // |
---|
| 799 | // * choosing an algebraic extension (n.y.u.) // |
---|
| 800 | // * ensuring poly is sqrfree (n.y.i.) // |
---|
[b4ea1d] | 801 | // use Factorize(F,alpha,is_SqrFree) if not over Zp[x]/Q[x] // |
---|
[1a80b4] | 802 | /////////////////////////////////////////////////////////////// |
---|
[b6249e] | 803 | int find_mvar(const CanonicalForm &f); |
---|
[38e7b3] | 804 | CFFList Factorize(const CanonicalForm & F, int is_SqrFree ) |
---|
| 805 | { |
---|
[ee586a] | 806 | //out_cf("Factorize ",F,"\n"); |
---|
[1a80b4] | 807 | CFFList Outputlist,SqrFreeList,Intermediatelist,Outputlist2; |
---|
| 808 | ListIterator<CFFactor> i,j; |
---|
[0be2bc] | 809 | CanonicalForm g=1,unit=1,r=1; |
---|
[b4ea1d] | 810 | Variable minpoly; // dummy |
---|
[1a80b4] | 811 | int exp; |
---|
| 812 | CFMap m; |
---|
| 813 | |
---|
[3e55bc] | 814 | // INTERRUPTHANDLER |
---|
| 815 | if ( interrupt_handle() ) return CFFList() ; |
---|
| 816 | // INTERRUPTHANDLER |
---|
| 817 | |
---|
[e2ca88] | 818 | DEBINCLEVEL(CERR, "Factorize"); |
---|
| 819 | DEBOUTLN(CERR, "Called with F= ", F); |
---|
[9e9b7c] | 820 | if (( getCharacteristic() == 0 ) || (F.isUnivariate())) |
---|
[38e7b3] | 821 | { // char == 0 |
---|
[1a80b4] | 822 | TIMING_START(factorize_time); |
---|
[e2ca88] | 823 | //CERR << "Factoring in char=0 of " << F << " = " << Outputlist << "\n"; |
---|
[1a80b4] | 824 | Outputlist= factorize(F); |
---|
[3e55bc] | 825 | // Factorization in char=0 doesn't sometimes return at least two elements!!! |
---|
[0be2bc] | 826 | if ( getNumVars(Outputlist.getFirst().factor()) != 0 ) |
---|
[3e55bc] | 827 | Outputlist.insert(CFFactor(1,1)); |
---|
[e2ca88] | 828 | //CERR << " Factorize in char=0: returning with: " << Outputlist << "\n"; |
---|
[3e55bc] | 829 | TIMING_END(factorize_time); |
---|
[e2ca88] | 830 | DEBDECLEVEL(CERR, "Factorize"); |
---|
[3e55bc] | 831 | TIMING_PRINT(factorize_time, "\ntime used for factorization : "); |
---|
| 832 | return Outputlist; |
---|
[1a80b4] | 833 | } |
---|
| 834 | TIMING_START(factorize_time); |
---|
[b6249e] | 835 | // search an "optimal" main variavble |
---|
| 836 | int mv=F.level(); |
---|
[9e9b7c] | 837 | if ((mv != LEVELBASE) /* && (! F.isUnivariate()) */) |
---|
[b6249e] | 838 | { |
---|
| 839 | mv=find_mvar(F); |
---|
| 840 | if (mv!=F.level()) |
---|
| 841 | { |
---|
| 842 | swapvar(F,Variable(mv),F.mvar()); |
---|
| 843 | } |
---|
| 844 | } |
---|
| 845 | |
---|
[1a80b4] | 846 | /////// |
---|
| 847 | // Maybe it`s better to add a sqrfree-test before? |
---|
| 848 | // (If gcd is fast...) |
---|
| 849 | /////// |
---|
[e89e56] | 850 | // if ( ! SqrFreeTest(F) ){ |
---|
[38e7b3] | 851 | if ( ! is_SqrFree ) |
---|
| 852 | { |
---|
[3e55bc] | 853 | TIMING_START(sqrfree_time); |
---|
[e89e56] | 854 | SqrFreeList = SqrFreeMV(F) ; // first sqrfree the polynomial |
---|
| 855 | // don't use sqrFree(F), factory's internal sqrFree for multiv. |
---|
| 856 | // Polynomials; it's wrong!! Ex.: char=p f= x^p*(y+1); |
---|
| 857 | // SqrFreeMV(f)= ( y+1, (x)^p ), sqrFree(f)= ( y+1 ) . |
---|
[3e55bc] | 858 | TIMING_END(sqrfree_time); |
---|
| 859 | |
---|
| 860 | // INTERRUPTHANDLER |
---|
| 861 | if ( interrupt_handle() ) return CFFList() ; |
---|
| 862 | // INTERRUPTHANDLER |
---|
| 863 | |
---|
[1a80b4] | 864 | } |
---|
[0be2bc] | 865 | else |
---|
[3e55bc] | 866 | SqrFreeList.append(CFFactor(F,1)); |
---|
[9e9b7c] | 867 | |
---|
[e89e56] | 868 | DEBOUTLN(CERR, "SqrFreeMV= ", SqrFreeList); |
---|
[38e7b3] | 869 | for ( i=SqrFreeList; i.hasItem(); i++ ) |
---|
| 870 | { |
---|
[e2ca88] | 871 | DEBOUTLN(CERR, "Factor under consideration: ", i.getItem().factor()); |
---|
[1a80b4] | 872 | // We need a compress on each list item ! Maybe we have less variables! |
---|
[0be2bc] | 873 | g =compress(i.getItem().factor(),m); |
---|
[1a80b4] | 874 | exp = i.getItem().exp(); |
---|
| 875 | if ( getNumVars(g) ==0 ) // a constant; Exp==1 |
---|
| 876 | Outputlist.append( CFFactor(g,1) ) ; |
---|
| 877 | else// a real polynomial |
---|
[38e7b3] | 878 | if ( g.isUnivariate() ) |
---|
| 879 | { |
---|
[ee586a] | 880 | //out_cf("univ. poly: ",g,"\n"); |
---|
[0be2bc] | 881 | Intermediatelist=factorize(g,1); // poly is sqr-free! |
---|
| 882 | for ( j=Intermediatelist; j.hasItem(); j++ ) |
---|
| 883 | //Normally j.getItem().exp() should be 1 |
---|
| 884 | Outputlist.append( CFFactor( m(j.getItem().factor()),exp*j.getItem().exp())); |
---|
[1a80b4] | 885 | } |
---|
[38e7b3] | 886 | else |
---|
| 887 | { // multivariate polynomial |
---|
| 888 | if ( g.isHomogeneous() ) |
---|
| 889 | { |
---|
[e2ca88] | 890 | DEBOUTLN(CERR, "Poly is homogeneous! : ", g); |
---|
[0be2bc] | 891 | // Now we can substitute one variable to 1, factorize and then |
---|
| 892 | // look on the resulting factors and their monomials for |
---|
| 893 | // backsubstitution of the substituted variable. |
---|
| 894 | Intermediatelist = HomogFactor(g, minpoly, 0); |
---|
| 895 | } |
---|
| 896 | else // not homogeneous |
---|
| 897 | Intermediatelist = Factorized(g, minpoly, 0); |
---|
| 898 | |
---|
| 899 | // INTERRUPTHANDLER |
---|
| 900 | if ( interrupt_handle() ) return CFFList() ; |
---|
| 901 | // INTERRUPTHANDLER |
---|
| 902 | |
---|
| 903 | for ( j=Intermediatelist; j.hasItem(); j++ ) |
---|
| 904 | //Normally j.getItem().exp() should be 1 |
---|
[e89e56] | 905 | Outputlist= myappend( Outputlist, CFFactor(m(j.getItem().factor()),exp*j.getItem().exp())); |
---|
[1a80b4] | 906 | } |
---|
| 907 | } |
---|
| 908 | g=1; unit=1; |
---|
[e2ca88] | 909 | DEBOUTLN(CERR, "Outputlist is ", Outputlist); |
---|
[1a80b4] | 910 | for ( i=Outputlist; i.hasItem(); i++ ) |
---|
[38e7b3] | 911 | if ( level(i.getItem().factor()) > 0 ) |
---|
| 912 | { |
---|
[1a80b4] | 913 | unit = lc(i.getItem().factor()); |
---|
[38e7b3] | 914 | if ( getNumVars(unit) == 0 ) |
---|
| 915 | { // a constant; possibly 1 |
---|
[0be2bc] | 916 | Outputlist2.append(CFFactor(i.getItem().factor()/unit , i.getItem().exp())); |
---|
| 917 | g *=power(i.getItem().factor()/unit,i.getItem().exp()); |
---|
[1a80b4] | 918 | } |
---|
[38e7b3] | 919 | else |
---|
| 920 | { |
---|
[0be2bc] | 921 | Outputlist2.append(i.getItem()); |
---|
| 922 | g *=power(i.getItem().factor(),i.getItem().exp()); |
---|
[1a80b4] | 923 | } |
---|
| 924 | } |
---|
[0be2bc] | 925 | |
---|
| 926 | r=F/g; |
---|
[1a80b4] | 927 | Outputlist2.insert(CFFactor(r,1)); |
---|
[0be2bc] | 928 | |
---|
[b6249e] | 929 | if ((mv!=F.level()) && (! F.isUnivariate() )) |
---|
| 930 | { |
---|
| 931 | CFFListIterator J=Outputlist2; |
---|
| 932 | for ( ; J.hasItem(); J++) |
---|
| 933 | { |
---|
| 934 | swapvar(J.getItem().factor(),Variable(mv),F.mvar()); |
---|
| 935 | } |
---|
| 936 | swapvar(F,Variable(mv),F.mvar()); |
---|
| 937 | } |
---|
[e2ca88] | 938 | DEBDECLEVEL(CERR, "Factorize"); |
---|
[1a80b4] | 939 | TIMING_END(factorize_time); |
---|
| 940 | |
---|
| 941 | TIMING_PRINT(sqrfree_time, "\ntime used for sqrfree : "); |
---|
| 942 | TIMING_PRINT(discr_time, "time used for discriminante : "); |
---|
| 943 | TIMING_PRINT(evaluate_time, "time used for evaluation and univ. factorization : "); |
---|
| 944 | TIMING_PRINT(hensel_time, "time used for hensel-lift : "); |
---|
| 945 | TIMING_PRINT(truefactor_time, "time used for truefactors : "); |
---|
| 946 | TIMING_PRINT(factorize_time, "\ntime used for factorization : "); |
---|
[5299b6] | 947 | |
---|
| 948 | if(isOn(SW_USE_NTL_SORT)) Outputlist2.sort(cmpCF); |
---|
| 949 | |
---|
[1a80b4] | 950 | return Outputlist2; |
---|
| 951 | } |
---|
| 952 | |
---|
[b4ea1d] | 953 | /////////////////////////////////////////////////////////////// |
---|
| 954 | // The user front-end for a uni/multivariate factorization // |
---|
| 955 | // routine. F needs not to be SqrFree. // |
---|
| 956 | // Option of * choosing a main variable (n.y.i.) // |
---|
| 957 | // * choosing an algebraic extension (n.y.u.) // |
---|
| 958 | // * ensuring poly is sqrfree (n.y.i.) // |
---|
| 959 | /////////////////////////////////////////////////////////////// |
---|
[52e543] | 960 | static bool fdivides2(const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &minpoly) |
---|
| 961 | { |
---|
[8e0cdf] | 962 | if (!minpoly.isZero()) |
---|
[52e543] | 963 | { |
---|
| 964 | #if 0 |
---|
| 965 | Variable Alpha=minpoly.mvar(); |
---|
| 966 | Variable X=rootOf(minpoly); |
---|
| 967 | CanonicalForm rF=replacevar(F,Alpha,X); |
---|
| 968 | CanonicalForm rG=replacevar(G,Alpha,X); |
---|
| 969 | return fdivides(rF,rG);; |
---|
| 970 | #else |
---|
[304e26] | 971 | if (degree(F,F.mvar()) > degree(G,F.mvar())) return false; |
---|
| 972 | return true; |
---|
| 973 | //CanonicalForm a,b; |
---|
| 974 | //mydivrem(G,F,a,b); |
---|
| 975 | //if (b.isZero()) return true; |
---|
| 976 | //else return false; |
---|
[52e543] | 977 | #endif |
---|
| 978 | } |
---|
| 979 | else |
---|
| 980 | return fdivides(F,G); |
---|
| 981 | } |
---|
[927b7e] | 982 | |
---|
[b4ea1d] | 983 | CFFList |
---|
[38e7b3] | 984 | Factorize(const CanonicalForm & F, const CanonicalForm & minpoly, int is_SqrFree ) |
---|
| 985 | { |
---|
[a38d45] | 986 | //out_cf("Factorize: F=",F,"\n"); |
---|
| 987 | //out_cf(" minpoly:",minpoly,"\n"); |
---|
[b4ea1d] | 988 | CFFList Outputlist,SqrFreeList,Intermediatelist,Outputlist2; |
---|
| 989 | ListIterator<CFFactor> i,j; |
---|
| 990 | CanonicalForm g=1,unit=1,r=1; |
---|
| 991 | //Variable minpoly; // reserved (-> Factorisation over algebraic Extensions) |
---|
| 992 | int exp; |
---|
| 993 | CFMap m; |
---|
| 994 | |
---|
| 995 | // INTERRUPTHANDLER |
---|
| 996 | if ( interrupt_handle() ) return CFFList() ; |
---|
| 997 | // INTERRUPTHANDLER |
---|
| 998 | |
---|
[e2ca88] | 999 | DEBINCLEVEL(CERR, "Factorize"); |
---|
| 1000 | DEBOUTLN(CERR, "Called with F= ", F); |
---|
[639047e] | 1001 | if ( getCharacteristic() == 0 ) |
---|
| 1002 | { // char == 0 |
---|
[b4ea1d] | 1003 | TIMING_START(factorize_time); |
---|
[e2ca88] | 1004 | //CERR << "Factoring in char=0 of " << F << " = " << Outputlist << "\n"; |
---|
[639047e] | 1005 | #if 0 |
---|
[93a6da3] | 1006 | // SHOULD: Outputlist= factorize(F,minpoly); |
---|
| 1007 | Outputlist= factorize(F); |
---|
[639047e] | 1008 | #else |
---|
[8e0cdf] | 1009 | if (!minpoly.isZero()) |
---|
[639047e] | 1010 | { |
---|
[a38d45] | 1011 | if ( F.isHomogeneous() ) |
---|
[6036eb2] | 1012 | { |
---|
[a38d45] | 1013 | DEBOUTLN(CERR, "Poly is homogeneous! : ", F); |
---|
| 1014 | // Now we can substitute one variable to 1, factorize and then |
---|
| 1015 | // look on the resulting factors and their monomials for |
---|
| 1016 | // backsubstitution of the substituted variable. |
---|
| 1017 | Outputlist=HomogFactor(F, minpoly, 0); |
---|
| 1018 | } |
---|
| 1019 | else |
---|
| 1020 | { |
---|
| 1021 | CFList as(minpoly); |
---|
[8e0cdf] | 1022 | //CFFList sqF=sqrFree(F); // sqrFreeZ |
---|
| 1023 | CFFList sqF=SqrFreeMV(F,minpoly); |
---|
[f152c5] | 1024 | if (sqF.isEmpty()) sqF=sqrFree(F); |
---|
[a38d45] | 1025 | CFFList G,H; |
---|
| 1026 | CanonicalForm fac; |
---|
| 1027 | int d; |
---|
| 1028 | ListIterator<CFFactor> i,k; |
---|
| 1029 | for ( i = sqF; i.hasItem(); ++i ) |
---|
[6036eb2] | 1030 | { |
---|
[a38d45] | 1031 | d = i.getItem().exp(); |
---|
| 1032 | fac = i.getItem().factor(); |
---|
[adfb22] | 1033 | int success=1; |
---|
| 1034 | G = newfactoras( fac, as, success); |
---|
[a38d45] | 1035 | for ( k = G; k.hasItem(); ++k ) |
---|
| 1036 | { |
---|
| 1037 | fac = k.getItem().factor(); |
---|
| 1038 | int dd = k.getItem().exp(); |
---|
| 1039 | H.append( CFFactor( fac , d*dd ) ); |
---|
| 1040 | } |
---|
[6036eb2] | 1041 | } |
---|
[a38d45] | 1042 | Outputlist = H; |
---|
[6036eb2] | 1043 | } |
---|
[639047e] | 1044 | } |
---|
[8e0cdf] | 1045 | else // minpoly==0 |
---|
[639047e] | 1046 | Outputlist=factorize(F); |
---|
| 1047 | #endif |
---|
[b4ea1d] | 1048 | // Factorization in char=0 doesn't sometimes return at least two elements!!! |
---|
| 1049 | if ( getNumVars(Outputlist.getFirst().factor()) != 0 ) |
---|
| 1050 | Outputlist.insert(CFFactor(1,1)); |
---|
[e2ca88] | 1051 | //CERR << " Factorize in char=0: returning with: " << Outputlist << "\n"; |
---|
[b4ea1d] | 1052 | TIMING_END(factorize_time); |
---|
[e2ca88] | 1053 | DEBDECLEVEL(CERR, "Factorize"); |
---|
[b4ea1d] | 1054 | TIMING_PRINT(factorize_time, "\ntime used for factorization : "); |
---|
[a38d45] | 1055 | //out_cff(Outputlist); |
---|
[b4ea1d] | 1056 | return Outputlist; |
---|
| 1057 | } |
---|
| 1058 | TIMING_START(factorize_time); |
---|
| 1059 | // search an "optimal" main variavble |
---|
| 1060 | int mv=F.level(); |
---|
| 1061 | if (mv != LEVELBASE && ! F.isUnivariate() ) |
---|
| 1062 | { |
---|
| 1063 | mv=find_mvar(F); |
---|
| 1064 | if (mv!=F.level()) |
---|
| 1065 | { |
---|
| 1066 | swapvar(F,Variable(mv),F.mvar()); |
---|
| 1067 | } |
---|
| 1068 | } |
---|
| 1069 | |
---|
| 1070 | /////// |
---|
| 1071 | // Maybe it`s better to add a sqrfree-test before? |
---|
| 1072 | // (If gcd is fast...) |
---|
| 1073 | /////// |
---|
[e89e56] | 1074 | // if ( ! SqrFreeTest(F) ){ |
---|
[10697c] | 1075 | if ( ! is_SqrFree ) |
---|
| 1076 | { |
---|
[b4ea1d] | 1077 | TIMING_START(sqrfree_time); |
---|
[e89e56] | 1078 | SqrFreeList = SqrFreeMV(F, minpoly) ; // first sqrfree the polynomial |
---|
| 1079 | // don't use sqrFree(F), factory's internal sqrFree for multiv. |
---|
| 1080 | // Polynomials; it's wrong!! Ex.: char=p f= x^p*(y+1); |
---|
| 1081 | // SqrFreeMV(f)= ( y+1, (x)^p ), sqrFree(f)= ( y+1 ) . |
---|
[b4ea1d] | 1082 | TIMING_END(sqrfree_time); |
---|
| 1083 | |
---|
| 1084 | // INTERRUPTHANDLER |
---|
| 1085 | if ( interrupt_handle() ) return CFFList() ; |
---|
| 1086 | // INTERRUPTHANDLER |
---|
| 1087 | |
---|
| 1088 | } |
---|
| 1089 | else |
---|
| 1090 | SqrFreeList.append(CFFactor(F,1)); |
---|
[e89e56] | 1091 | DEBOUTLN(CERR, "SqrFreeMV= ", SqrFreeList); |
---|
[10697c] | 1092 | for ( i=SqrFreeList; i.hasItem(); i++ ) |
---|
| 1093 | { |
---|
[e2ca88] | 1094 | DEBOUTLN(CERR, "Factor under consideration: ", i.getItem().factor()); |
---|
[b4ea1d] | 1095 | // We need a compress on each list item ! Maybe we have less variables! |
---|
| 1096 | g =compress(i.getItem().factor(),m); |
---|
| 1097 | exp = i.getItem().exp(); |
---|
| 1098 | if ( getNumVars(g) ==0 ) // a constant; Exp==1 |
---|
| 1099 | Outputlist.append( CFFactor(g,1) ) ; |
---|
| 1100 | else// a real polynomial |
---|
[8de151] | 1101 | { |
---|
[10697c] | 1102 | if ( g.isUnivariate() ) |
---|
| 1103 | { |
---|
[639047e] | 1104 | Variable alpha=rootOf(minpoly); |
---|
[1048e0c] | 1105 | Intermediatelist=factorize2(g,alpha,minpoly); // poly is sqr-free! |
---|
[b4ea1d] | 1106 | for ( j=Intermediatelist; j.hasItem(); j++ ) |
---|
| 1107 | //Normally j.getItem().exp() should be 1 |
---|
[639047e] | 1108 | Outputlist.append( |
---|
| 1109 | CFFactor( m(replacevar(j.getItem().factor(),alpha,minpoly.mvar())), |
---|
| 1110 | exp*j.getItem().exp())); |
---|
[b4ea1d] | 1111 | } |
---|
[10697c] | 1112 | else // multivariate polynomial |
---|
| 1113 | { |
---|
| 1114 | if ( g.isHomogeneous() ) |
---|
[52e543] | 1115 | { |
---|
[e2ca88] | 1116 | DEBOUTLN(CERR, "Poly is homogeneous! : ", g); |
---|
[b4ea1d] | 1117 | // Now we can substitute one variable to 1, factorize and then |
---|
| 1118 | // look on the resulting factors and their monomials for |
---|
| 1119 | // backsubstitution of the substituted variable. |
---|
| 1120 | Intermediatelist = HomogFactor(g, minpoly, 0); |
---|
| 1121 | } |
---|
| 1122 | else // not homogeneous |
---|
| 1123 | Intermediatelist = Factorized(g, minpoly, 0); |
---|
| 1124 | |
---|
| 1125 | // INTERRUPTHANDLER |
---|
| 1126 | if ( interrupt_handle() ) return CFFList() ; |
---|
| 1127 | // INTERRUPTHANDLER |
---|
| 1128 | |
---|
| 1129 | for ( j=Intermediatelist; j.hasItem(); j++ ) |
---|
| 1130 | //Normally j.getItem().exp() should be 1 |
---|
[e89e56] | 1131 | Outputlist= myappend( Outputlist, CFFactor(m(j.getItem().factor()),exp*j.getItem().exp())); |
---|
[b4ea1d] | 1132 | } |
---|
[8de151] | 1133 | } |
---|
[b4ea1d] | 1134 | } |
---|
| 1135 | g=1; unit=1; |
---|
[e2ca88] | 1136 | DEBOUTLN(CERR, "Outputlist is ", Outputlist); |
---|
[b4ea1d] | 1137 | for ( i=Outputlist; i.hasItem(); i++ ) |
---|
[8e0cdf] | 1138 | if ( level(i.getItem().factor()) > 0 ) |
---|
| 1139 | { |
---|
[b4ea1d] | 1140 | unit = lc(i.getItem().factor()); |
---|
| 1141 | if ( getNumVars(unit) == 0 ){ // a constant; possibly 1 |
---|
| 1142 | Outputlist2.append(CFFactor(i.getItem().factor()/unit , i.getItem().exp())); |
---|
| 1143 | g *=power(i.getItem().factor()/unit,i.getItem().exp()); |
---|
| 1144 | } |
---|
[8e0cdf] | 1145 | else |
---|
| 1146 | { |
---|
[b4ea1d] | 1147 | Outputlist2.append(i.getItem()); |
---|
| 1148 | g *=power(i.getItem().factor(),i.getItem().exp()); |
---|
| 1149 | } |
---|
| 1150 | } |
---|
| 1151 | |
---|
| 1152 | r=F/g; |
---|
| 1153 | Outputlist2.insert(CFFactor(r,1)); |
---|
| 1154 | |
---|
| 1155 | if ((mv!=F.level()) && (! F.isUnivariate() )) |
---|
| 1156 | { |
---|
| 1157 | CFFListIterator J=Outputlist2; |
---|
| 1158 | for ( ; J.hasItem(); J++) |
---|
| 1159 | { |
---|
| 1160 | swapvar(J.getItem().factor(),Variable(mv),F.mvar()); |
---|
| 1161 | } |
---|
| 1162 | swapvar(F,Variable(mv),F.mvar()); |
---|
| 1163 | } |
---|
[1048e0c] | 1164 | |
---|
[e2ca88] | 1165 | DEBDECLEVEL(CERR, "Factorize"); |
---|
[b4ea1d] | 1166 | TIMING_END(factorize_time); |
---|
| 1167 | |
---|
| 1168 | TIMING_PRINT(sqrfree_time, "\ntime used for sqrfree : "); |
---|
| 1169 | TIMING_PRINT(discr_time, "time used for discriminante : "); |
---|
| 1170 | TIMING_PRINT(evaluate_time, "time used for evaluation and univ. factorization : "); |
---|
| 1171 | TIMING_PRINT(hensel_time, "time used for hensel-lift : "); |
---|
| 1172 | TIMING_PRINT(truefactor_time, "time used for truefactors : "); |
---|
| 1173 | TIMING_PRINT(factorize_time, "\ntime used for factorization : "); |
---|
[5299b6] | 1174 | |
---|
| 1175 | if(isOn(SW_USE_NTL_SORT)) Outputlist2.sort(cmpCF); |
---|
| 1176 | |
---|
[a38d45] | 1177 | //out_cff(Outputlist2); |
---|
[b4ea1d] | 1178 | return Outputlist2; |
---|
| 1179 | } |
---|
| 1180 | |
---|