Changeset ef9d6b in git
- Timestamp:
- Jan 22, 2008, 10:30:32 AM (15 years ago)
- Branches:
- (u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
- Children:
- 35cfa3461f55f0fe3760bcefda25c627641368c7
- Parents:
- c6d3744af7f072c74673ab0aef31dfe80c1c9ae9
- Location:
- factory
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/cf_algorithm.h
rc6d3744 ref9d6b 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: cf_algorithm.h,v 1.1 6 2007-10-25 14:45:41 Singular Exp $ */2 /* $Id: cf_algorithm.h,v 1.17 2008-01-22 09:30:31 Singular Exp $ */ 3 3 4 4 #ifndef INCL_CF_ALGORITHM_H … … 64 64 CFFList factorize ( const CanonicalForm & f, const Variable & alpha ); 65 65 66 CFFList sqrFree ( const CanonicalForm & f, bool sort =false );66 CFFList sqrFree ( const CanonicalForm & f, const CanonicalForm & mipo, bool sort=false ); 67 67 68 68 bool isSqrFree ( const CanonicalForm & f ); -
factory/fac_multivar.h
rc6d3744 ref9d6b 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: fac_multivar.h,v 1. 2 1997-06-19 12:23:22 schmidtExp $ */2 /* $Id: fac_multivar.h,v 1.3 2008-01-22 09:30:31 Singular Exp $ */ 3 3 4 4 #ifndef INCL_FAC_MULTIVAR_H … … 10 10 11 11 CFFList ZFactorizeMultivariate ( const CanonicalForm & f, bool issqrfree ); 12 CFFList FpFactorizeMultivariate ( const CanonicalForm & f, bool issqrfree ); 12 13 13 14 #endif /* ! INCL_FAC_MULTIVAR_H */ -
factory/fac_sqrfree.cc
rc6d3744 ref9d6b 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: fac_sqrfree.cc,v 1. 7 1997-12-08 18:24:32 schmidtExp $ */2 /* $Id: fac_sqrfree.cc,v 1.8 2008-01-22 09:30:31 Singular Exp $ */ 3 3 4 4 #include <config.h> … … 7 7 8 8 #include "cf_defs.h" 9 #include "cf_map.h" 9 10 #include "canonicalform.h" 11 #include "fac_sqrfree.h" 10 12 11 13 static int divexp = 1; … … 16 18 } 17 19 18 static int 19 compareFactors( const CFFactor & f, const CFFactor & g ) 20 static int compareFactors( const CFFactor & f, const CFFactor & g ) 20 21 { 21 22 return f.exp() > g.exp(); 22 23 } 23 24 24 CFFList 25 sortCFFList( CFFList & F ) 25 CFFList sortCFFList( CFFList & F ) 26 26 { 27 27 F.sort( compareFactors ); … … 33 33 34 34 // join elements with the same degree 35 while ( I.hasItem() ) { 36 f = I.getItem().factor(); 37 exp = I.getItem().exp(); 38 I++; 39 while ( I.hasItem() && I.getItem().exp() == exp ) { 40 f *= I.getItem().factor(); 41 I++; 42 } 43 result.append( CFFactor( f, exp ) ); 35 while ( I.hasItem() ) 36 { 37 f = I.getItem().factor(); 38 exp = I.getItem().exp(); 39 I++; 40 while ( I.hasItem() && I.getItem().exp() == exp ) 41 { 42 f *= I.getItem().factor(); 43 I++; 44 } 45 result.append( CFFactor( f, exp ) ); 44 46 } 45 47 … … 47 49 } 48 50 49 CFFList sqrFreeFp ( const CanonicalForm & f ) 50 { 51 CFFList appendCFFL( const CFFList & Inputlist, const CFFactor & TheFactor) 52 { 53 CFFList Outputlist ; 54 CFFactor copy; 55 CFFListIterator i; 56 int exp=0; 57 58 for ( i=Inputlist ; i.hasItem() ; i++ ) 59 { 60 copy = i.getItem(); 61 if ( copy.factor() == TheFactor.factor() ) 62 exp += copy.exp(); 63 else 64 Outputlist.append(copy); 65 } 66 Outputlist.append( CFFactor(TheFactor.factor(), exp + TheFactor.exp())); 67 return Outputlist; 68 } 69 70 CFFList UnionCFFL(const CFFList & Inputlist1,const CFFList & Inputlist2) 71 { 72 CFFList Outputlist; 73 CFFListIterator i; 74 75 for ( i=Inputlist1 ; i.hasItem() ; i++ ) 76 Outputlist = appendCFFL(Outputlist, i.getItem() ); 77 for ( i=Inputlist2 ; i.hasItem() ; i++ ) 78 Outputlist = appendCFFL(Outputlist, i.getItem() ); 79 80 return Outputlist; 81 } 82 83 CFFList sqrFreeFp_univ ( const CanonicalForm & f ) 84 { 85 if (getNumVars(f) == 0) return CFFactor(f,1); 51 86 CanonicalForm t0 = f, t, v, w, h; 52 87 CanonicalForm leadcf = t0.lc(); … … 57 92 58 93 if ( ! leadcf.isOne() ) 59 94 t0 /= leadcf; 60 95 61 96 divexp = p; 62 while ( t0.degree(x) > 0 ) { 63 t = gcd( t0, t0.deriv() ); 64 v = t0 / t; 65 k = 0; 66 while ( v.degree(x) > 0 ) { 67 k = k+1; 68 if ( k % p == 0 ) { 69 t /= v; 70 k = k+1; 71 } 72 w = gcd( t, v ); 73 h = v / w; 74 v = w; 75 t /= v; 76 if ( h.degree(x) > 0 ) 77 F.append( CFFactor( h/h.lc(), e*k ) ); 78 } 79 t0 = apply( t, divexpfunc ); 80 e = p * e; 81 } 82 if ( ! leadcf.isOne() ) { 83 if ( F.getFirst().exp() == 1 ) { 84 leadcf = F.getFirst().factor() * leadcf; 85 F.removeFirst(); 86 } 87 F.insert( CFFactor( leadcf, 1 ) ); 97 while ( t0.degree(x) > 0 ) 98 { 99 t = gcd( t0, t0.deriv() ); 100 v = t0 / t; 101 k = 0; 102 while ( v.degree(x) > 0 ) 103 { 104 k = k+1; 105 if ( k % p == 0 ) 106 { 107 t /= v; 108 k = k+1; 109 } 110 w = gcd( t, v ); 111 h = v / w; 112 v = w; 113 t /= v; 114 if ( h.degree(x) > 0 ) 115 F.append( CFFactor( h/h.lc(), e*k ) ); 116 } 117 t0 = apply( t, divexpfunc ); 118 e = p * e; 119 } 120 if ( ! leadcf.isOne() ) 121 { 122 if ( F.getFirst().exp() == 1 ) 123 { 124 leadcf = F.getFirst().factor() * leadcf; 125 F.removeFirst(); 126 } 127 F.insert( CFFactor( leadcf, 1 ) ); 88 128 } 89 129 return F; 130 } 131 static inline CFFactor Powerup( const CFFactor & F , int exp=1) 132 { 133 return CFFactor(F.factor(), exp*F.exp()) ; 134 } 135 136 static CFFList Powerup( const CFFList & Inputlist , int exp=1 ) 137 { 138 CFFList Outputlist; 139 140 for ( CFFListIterator i=Inputlist; i.hasItem(); i++ ) 141 Outputlist.append(Powerup(i.getItem(), exp)); 142 return Outputlist ; 143 } 144 int Powerup( const int base , const int exp) 145 { 146 int retvalue=1; 147 if ( exp == 0 ) return retvalue ; 148 else for ( int i=1 ; i <= exp; i++ ) retvalue *= base ; 149 150 return retvalue; 151 } 152 153 /////////////////////////////////////////////////////////////// 154 // Compute the Pth root of a polynomial in characteristic p // 155 // f must be a polynomial which we can take the Pth root of. // 156 // Domain is q=p^m , f a uni/multivariate polynomial // 157 /////////////////////////////////////////////////////////////// 158 static CanonicalForm PthRoot( const CanonicalForm & f ) 159 { 160 CanonicalForm RES, R = f; 161 int n= getNumVars(R), p= getCharacteristic(); 162 163 if (level(R)>n) n=level(R); 164 165 if (n==0) 166 { // constant 167 if (R.inExtension()) // not in prime field; f over |F(q=p^k) 168 { 169 R = power(R,Powerup(p,getGFDegree() - 1)) ; 170 } 171 // if f in prime field, do nothing 172 return R; 173 } 174 // we assume R is a Pth power here 175 RES = R.genZero(); 176 Variable x(n); 177 for (int i=0; i<= (int) (degree(R,level(R))/p) ; i++) 178 RES += PthRoot( R[i*p] ) * power(x,i); 179 return RES; 180 } 181 182 /////////////////////////////////////////////////////////////// 183 // Compute the Pth root of a polynomial in characteristic p // 184 // f must be a polynomial which we can take the Pth root of. // 185 // Domain is q=p^m , f a uni/multivariate polynomial // 186 /////////////////////////////////////////////////////////////// 187 static CanonicalForm PthRoot( const CanonicalForm & f ,const CanonicalForm & mipo) 188 { 189 CanonicalForm RES, R = f; 190 int n= getNumVars(R), p= getCharacteristic(); 191 int mipodeg=-1; 192 193 if (level(R)>n) n=level(R); 194 195 if (f.level()==mipo.level()) mipodeg=mipo.degree(); 196 else if ((f.level()==1) &&(mipo.level()!=LEVELBASE)) 197 { 198 Variable t; 199 CanonicalForm tt=getMipo(mipo.mvar(),t); 200 mipodeg=degree(tt,t); 201 } 202 203 if ((n==0) 204 ||(mipodeg!=-1)) 205 { // constant 206 if (R.inExtension()) // not in prime field; f over |F(q=p^k) 207 { 208 R = power(R,Powerup(p,getGFDegree() - 1)) ; 209 } 210 else if ((f.level()==mipo.level()) 211 ||((f.level()==1) &&(mipo.level()!=LEVELBASE))) 212 { 213 R = power(R,Powerup(p,mipodeg - 1)) ; 214 R=mod(R, mipo); 215 } 216 // if f in prime field, do nothing 217 return R; 218 } 219 // we assume R is a Pth power here 220 RES = R.genZero(); 221 Variable x(n); 222 for (int i=0; i<= (int) (degree(R,level(R))/p) ; i++) 223 RES += PthRoot( R[i*p], mipo ) * power(x,i); 224 return RES; 225 } 226 CFFList sqrFreeFp ( const CanonicalForm & r, const CanonicalForm &mipo ) 227 { 228 /////////////////////////////////////////////////////////////// 229 // A uni/multivariate SqrFree routine.Works for polynomials // 230 // which don\'t have a constant as the content. // 231 // Works for charcteristic 0 and q=p^m // 232 // returns a list of polys each of sqrfree, but gcd(f_i,f_j) // 233 // needs not to be 1 !!!!! // 234 /////////////////////////////////////////////////////////////// 235 CanonicalForm h, g, f = r; 236 CFFList Outputlist; 237 int n = level(f); 238 239 if (getNumVars(f)==0 ) 240 { // just a constant; return it 241 Outputlist= CFFactor(f,1); 242 return Outputlist ; 243 } 244 245 // We look if we do have a content; if so, SqrFreed the content 246 // and continue computations with pp(f) 247 for (int k=1; k<=n; k++) 248 { 249 if ((mipo.level()==LEVELBASE)||(k!=1)) 250 { 251 g = swapvar(f,k,n); g = content(g); 252 if ( ! (g.isOne() || (-g).isOne() || degree(g)==0 )) 253 { 254 g = swapvar(g,k,n); 255 Outputlist = UnionCFFL(sqrFreeFp(g,mipo),Outputlist); // should we add a 256 // SqrFreeTest(g) first ? 257 f /=g; 258 } 259 } 260 } 261 262 // Now f is primitive; Let`s look if f is univariate 263 if ( f.isUnivariate() ) 264 { 265 g = content(g); 266 if ( ! (g.isOne() || (-g).isOne() ) ) 267 { 268 Outputlist= appendCFFL(Outputlist,CFFactor(g,1)) ; 269 f /= g; 270 } 271 Outputlist = Union(sqrFreeFp_univ(f),Outputlist) ; 272 return Outputlist ; 273 } 274 275 // Linear? 276 if ( totaldegree(f) <= 1 ) 277 { 278 Outputlist= appendCFFL(Outputlist,CFFactor(f,1)) ; 279 return Outputlist ; 280 } 281 282 // is it Pth root? 283 n=level(f); // maybe less indeterminants 284 g= f.deriv(); 285 if ( /*getCharacteristic() > 0 &&*/ g.isZero() ) 286 { // Pth roots only apply to char > 0 287 for (int k=1; k<=n; k++) 288 { 289 if ((mipo.level()==LEVELBASE)||(k!=1)) 290 { 291 g=swapvar(f,k,n) ; 292 g = g.deriv(); 293 294 if ( ! g.isZero() ) 295 { // can`t be Pth root 296 CFFList Outputlist2= sqrFreeFp(swapvar(f,k,n)); 297 for (CFFListIterator inter=Outputlist2; inter.hasItem(); inter++) 298 { 299 Outputlist=appendCFFL(Outputlist, 300 CFFactor(swapvar(inter.getItem().factor(),k,n), inter.getItem().exp())); 301 } 302 return Outputlist; 303 } 304 } 305 if ( k==n ) 306 { // really is Pth power 307 CFMap m; 308 g = compress(f,m); 309 if (mipo.isZero()) 310 f = m(PthRoot(g)); 311 else 312 f = m(PthRoot(g,mipo)); 313 // now : Outputlist union ( SqrFreed(f) )^getCharacteristic() 314 Outputlist=UnionCFFL(Powerup(sqrFreeFp(f),getCharacteristic()),Outputlist); 315 return Outputlist ; 316 } 317 } 318 } 319 g = f.deriv(); 320 h = gcd(f,pp(g)); h /= lc(h); 321 if ( (h.isOne()) || ( h==f) || ((-h).isOne()) || getNumVars(h)==0 ) 322 { // no common factor 323 Outputlist=appendCFFL(Outputlist,CFFactor(f,1)) ; 324 return Outputlist ; 325 } 326 else // we can split into two nontrivial pieces 327 { 328 f /= h; // Now we have split the poly into f and h 329 g = lc(f); 330 if ( (!g.isOne()) && getNumVars(g) == 0 ) 331 { 332 Outputlist=appendCFFL(Outputlist,CFFactor(g,1)) ; 333 f /= g; 334 } 335 // For char > 0 the polys f and h can have Pth roots; so we need a test 336 // Test is disabled because timing is the same 337 338 Outputlist=UnionCFFL(Outputlist, sqrFreeFp(f,mipo)); 339 Outputlist=UnionCFFL(Outputlist,sqrFreeFp(h,mipo)); 340 return Outputlist ; 341 } 342 return Outputlist; // for safety purpose 90 343 } 91 344 … … 111 364 112 365 while ( ! c.degree() == 0 ) { 113 114 115 116 117 118 119 120 366 y = gcd( w, c ); z = w / y; 367 if ( degree( z ) > 0 ) 368 if ( lc( z ).sign() < 0 ) 369 F.append( CFFactor( -z, i ) ); 370 else 371 F.append( CFFactor( z, i ) ); 372 i++; 373 w = y; c = c / y; 121 374 } 122 375 if ( degree( w ) > 0 ) 123 124 125 126 376 if ( lc( w ).sign() < 0 ) 377 F.append( CFFactor( -w, i ) ); 378 else 379 F.append( CFFactor( w, i ) ); 127 380 return F; 128 381 } 129 382 */ 130 383 131 CFFList sqrFreeZ ( const CanonicalForm & a )384 CFFList sqrFreeZ ( const CanonicalForm & a, const CanonicalForm & mipo ) 132 385 { 133 386 if ( a.inCoeffDomain() ) 134 387 return CFFactor( a, 1 ); 135 388 CanonicalForm cont = content( a ); 136 389 CanonicalForm aa = a / cont; … … 140 393 CFFList F; 141 394 Variable v = aa.mvar(); 142 while ( ! c.degree(v) == 0 ) { 143 y = gcd( w, c ); z = w / y; 144 if ( degree( z, v ) > 0 ) 145 if ( lc( z ).sign() < 0 ) 146 F.append( CFFactor( -z, i ) ); 147 else 148 F.append( CFFactor( z, i ) ); 149 i++; 150 w = y; c = c / y; 395 while ( ! c.degree(v) == 0 ) 396 { 397 y = gcd( w, c ); z = w / y; 398 if ( degree( z, v ) > 0 ) 399 if ( lc( z ).sign() < 0 ) 400 F.append( CFFactor( -z, i ) ); 401 else 402 F.append( CFFactor( z, i ) ); 403 i++; 404 w = y; c = c / y; 151 405 } 152 406 if ( degree( w,v ) > 0 ) 153 154 155 156 407 if ( lc( w ).sign() < 0 ) 408 F.append( CFFactor( -w, i ) ); 409 else 410 F.append( CFFactor( w, i ) ); 157 411 if ( ! cont.isOne() ) 158 412 F = Union( F, sqrFreeZ( cont ) ); 159 413 if ( lc( a ).sign() < 0 ) { 160 if ( F.getFirst().exp() == 1 ) { 161 CanonicalForm f = F.getFirst().factor(); 162 CFFListIterator(F).getItem() = CFFactor( -f, 1 ); 163 } 164 else 165 F.insert( CFFactor( -1, 1 ) ); 414 if ( F.getFirst().exp() == 1 ) 415 { 416 CanonicalForm f = F.getFirst().factor(); 417 CFFListIterator(F).getItem() = CFFactor( -f, 1 ); 418 } 419 else 420 F.insert( CFFactor( -1, 1 ) ); 166 421 } 167 422 return F; -
factory/fac_sqrfree.h
rc6d3744 ref9d6b 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: fac_sqrfree.h,v 1. 3 1997-06-19 12:23:18 schmidtExp $ */2 /* $Id: fac_sqrfree.h,v 1.4 2008-01-22 09:30:31 Singular Exp $ */ 3 3 4 4 #ifndef INCL_FAC_SQRFREE_H … … 9 9 #include "canonicalform.h" 10 10 11 /*BEGINPUBLIC*/ 12 13 int Powerup( const int base , const int exp); 14 CFFList appendCFFL( const CFFList & Inputlist, const CFFactor & TheFactor); 15 CFFList UnionCFFL(const CFFList & Inputlist1,const CFFList & Inputlist2); 16 17 18 /*ENDPUBLIC*/ 19 11 20 CFFList sortCFFList ( CFFList & F ); 12 21 13 CFFList sqrFreeFp ( const CanonicalForm & f ); 22 //CFFList sqrFreeFp ( const CanonicalForm & f ); 23 CFFList sqrFreeFp ( const CanonicalForm & r, const CanonicalForm &mipo=0 ); 14 24 15 25 bool isSqrFreeFp ( const CanonicalForm & f ); 16 26 17 CFFList sqrFreeZ ( const CanonicalForm & f );27 CFFList sqrFreeZ ( const CanonicalForm & f, const CanonicalForm &mipo=0 ); 18 28 19 29 bool isSqrFreeZ ( const CanonicalForm & f ); -
factory/fac_univar.cc
rc6d3744 ref9d6b 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: fac_univar.cc,v 1. 19 1998-04-07 08:10:58 pohlExp $ */2 /* $Id: fac_univar.cc,v 1.20 2008-01-22 09:30:31 Singular Exp $ */ 3 3 4 4 #include <config.h> … … 389 389 H.append( CFFactor( g, 1 ) ); 390 390 else 391 H = sqrFree( g );391 H = sqrFree( g, 0, false ); 392 392 393 393 DEBOUTLN( cerr, "H = " << H ); -
factory/factory.template
rc6d3744 ref9d6b 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: factory.template,v 1.1 8 2006-05-15 09:03:04Singular Exp $ */2 /* $Id: factory.template,v 1.19 2008-01-22 09:30:32 Singular Exp $ */ 3 3 4 4 #ifndef INCL_FACTORY_H … … 99 99 #include "cf_reval.h" 100 100 101 /*MAKEHEADER PUBLIC ONLY*/ 102 #include "fac_sqrfree.h" 103 101 104 #ifdef SINGULAR 102 105
Note: See TracChangeset
for help on using the changeset viewer.