Changeset 7d1c995 in git
- Timestamp:
- May 31, 2011, 3:48:35 PM (12 years ago)
- Branches:
- (u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
- Children:
- a8e8b95ce901a8a52041639c48329ebc09efae2b
- Parents:
- 5b274570b3977c8b95131bdda194e0b179f17b8b
- Location:
- factory
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/GNUmakefile.in
r5b2745 r7d1c995 128 128 # factory source files 129 129 basefactorysrc := \ 130 algext.cc \ 130 131 canonicalform.cc \ 131 132 cf_algorithm.cc \ -
factory/algext.cc
r5b2745 r7d1c995 145 145 return false; 146 146 } 147 148 CanonicalForm univarQGCD( const CanonicalForm & F, const CanonicalForm & G )149 { // F,G in Q(a)[x]150 CanonicalForm f, g, tmp, M, q, D, Dp, cl, newD, newq;151 int p, dp_deg, bound, i;152 bool fail;153 On(SW_RATIONAL);154 f = F * bCommonDen(F);155 g = G * bCommonDen(G);156 Variable a,b;157 if( !hasFirstAlgVar( f, a ) && !hasFirstAlgVar( g, b ))158 {159 // F and G are in Q[x], call...160 #ifdef HAVE_NTL161 if ( isOn( SW_USE_NTL_GCD_0 ))162 return gcd_univar_ntl0( f, g );163 #endif164 return gcd_poly_univar0( f, g, false );165 }166 if( b.level() > a.level() )167 a = b;168 // here: a is the biggest alg. var in f and g169 tmp = getMipo(a);170 M = tmp * bCommonDen(tmp);171 Off(SW_RATIONAL);172 // calculate upper bound for degree of gcd173 bound = degree(f);174 i = degree(g);175 if( i < bound )176 bound = i;177 178 cl = lc(M) * lc(f) * lc(g);179 q = 1;180 D = 0;181 for(i=cf_getNumBigPrimes()-1; i>-1; i--)182 {183 p = cf_getBigPrime(i);184 if( mod( cl, p ).isZero() ) // skip lc-bad primes185 continue;186 187 fail = false;188 setCharacteristic(p);189 tryEuclid( mapinto(f), mapinto(g), mapinto(M), Dp, fail );190 setCharacteristic(0);191 if( fail ) // M splits in char p192 continue;193 194 dp_deg = degree(Dp);195 196 if( dp_deg == 0 ) // early termination197 {198 CanonicalForm inv;199 tryInvert(Dp, M, inv, fail);200 if(fail)201 continue;202 return CanonicalForm(1);203 }204 205 if( dp_deg > bound ) // current prime unlucky206 continue;207 208 if( dp_deg < bound ) // all previous primes unlucky209 {210 q = p;211 D = mapinto(Dp); // shortcut CRA212 bound = dp_deg; // tighten bound213 continue;214 }215 chineseRemainder( D, q, mapinto(Dp), p, newD, newq );216 // newD = Dp mod p217 // newD = D mod q218 // newq = p*q219 q = newq;220 if( D != newD )221 {222 D = newD;223 continue;224 }225 On( SW_RATIONAL );226 tmp = Farey( D, q );227 if( fdivides( tmp, f ) && fdivides( tmp, g )) // trial division228 {229 Off( SW_RATIONAL );230 return tmp;231 }232 Off( SW_RATIONAL );233 }234 // hopefully, we never reach this point235 Off( SW_USE_QGCD );236 D = gcd( f, g );237 On( SW_USE_QGCD );238 return D;239 }240 241 242 147 243 148 CanonicalForm QGCD( const CanonicalForm & F, const CanonicalForm & G ); -
factory/algext.h
r5b2745 r7d1c995 1 #ifndef ALGEXT_H 2 #define ALGEXT_H 3 1 4 #include <config.h> 2 5 … … 5 8 6 9 CanonicalForm QGCD( const CanonicalForm &, const CanonicalForm & ); 7 CanonicalForm univarQGCD( const CanonicalForm & F, const CanonicalForm & G ); 8 //void tryEuclid( const CanonicalForm &, const CanonicalForm &, const CanonicalForm, CanonicalForm &, bool & ); 10 void tryEuclid( const CanonicalForm &, const CanonicalForm &, const CanonicalForm &, CanonicalForm &, bool & ); 9 11 void tryInvert( const CanonicalForm &, const CanonicalForm &, CanonicalForm &, bool & ); 10 12 bool hasFirstAlgVar( const CanonicalForm &, Variable & ); … … 12 14 void tryCRA( const CanonicalForm & x1, const CanonicalForm & q1, const CanonicalForm & x2, const CanonicalForm & q2, CanonicalForm & xnew, CanonicalForm & qnew, bool & fail ); 13 15 void tryExtgcd( const CanonicalForm & F, const CanonicalForm & G, CanonicalForm & result, CanonicalForm & s, CanonicalForm & t, bool & fail ); 16 int * leadDeg(const CanonicalForm & f, int *degs); 17 bool isLess(int *a, int *b, int lower, int upper); 18 bool isEqual(int *a, int *b, int lower, int upper); 19 CanonicalForm firstLC(const CanonicalForm & f); 14 20 21 #endif 15 22 16 -
factory/cf_gcd.cc
r5b2745 r7d1c995 834 834 (getCharacteristic() == 0) && 835 835 (hasFirstAlgVar(f,m) || hasFirstAlgVar(g,m)) 836 //&& f.isUnivariate()837 //&& g.isUnivariate()838 836 ) 839 837 { 840 //if ((f.level()==g.level()) && f.isUnivariate() && g.isUnivariate())841 // return univarQGCD(f,g);842 //else843 //return QGCD(f,g);844 838 bool on_rational = isOn(SW_RATIONAL); 845 839 CanonicalForm r=QGCD(f,g); … … 1238 1232 } 1239 1233 1240 #include "algext.cc"1241 -
factory/facAlgExt.h
r5b2745 r7d1c995 17 17 **/ 18 18 //***************************************************************************** 19 20 #ifndef FAC_ALG_EXT_H 21 #define FAC_ALG_EXT_H 19 22 20 23 #include "assert.h" … … 38 41 const Variable& alpha ///<[in] an algebraic variable 39 42 ); 43 44 #endif 45 -
factory/fieldGCD.h
r5b2745 r7d1c995 1 #ifndef FIELD_GCD_H 2 #define FIELD_GCD_H 3 1 4 CanonicalForm fieldGCD( const CanonicalForm & F, const CanonicalForm & G ); 2 5 void CRA(const CanonicalForm & x1, const CanonicalForm & q1, const CanonicalForm & x2, const CanonicalForm & q2, CanonicalForm & xnew, CanonicalForm & qnew); 3 int * leadDeg(const CanonicalForm & f, int *degs);4 bool isLess(int *a, int *b, int lower, int upper);5 bool isEqual(int *a, int *b, int lower, int upper);6 CanonicalForm firstLC(const CanonicalForm & f);7 6 7 #endif 8
Note: See TracChangeset
for help on using the changeset viewer.