Changeset 9fd8d2 in git for factory/algext.cc
- Timestamp:
- Jan 8, 2014, 11:40:54 AM (10 years ago)
- Branches:
- (u'spielwiese', 'a719bcf0b8dbc648b128303a49777a094b57592c')
- Children:
- 8dbc1a66444170190fc1474cb827d21039988914
- Parents:
- 7c43417b3c0a11646757be1dbd5877c7b19d0459
- git-author:
- Martin Lee <martinlee84@web.de>2014-01-08 11:40:54+01:00
- git-committer:
- Martin Lee <martinlee84@web.de>2014-01-20 16:45:04+01:00
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/algext.cc
r7c4341 r9fd8d2 239 239 } 240 240 241 #ifndef HAVE_NTL 241 242 void tryDivrem (const CanonicalForm& F, const CanonicalForm& G, CanonicalForm& Q, 242 243 CanonicalForm& R, CanonicalForm& inv, const CanonicalForm& mipo, … … 345 346 } 346 347 } 348 #endif 347 349 348 350 bool hasFirstAlgVar( const CanonicalForm & f, Variable & a ) … … 972 974 } 973 975 976 #ifndef HAVE_NTL 974 977 void tryExtgcd( const CanonicalForm & F, const CanonicalForm & G, const CanonicalForm & M, CanonicalForm & result, CanonicalForm & s, CanonicalForm & t, bool & fail ) 975 978 { // F, G are univariate polynomials (i.e. they have exactly one polynomial variable) … … 1041 1044 } 1042 1045 } 1043 1046 #endif 1044 1047 1045 1048 static CanonicalForm trycontent ( const CanonicalForm & f, const Variable & x, const CanonicalForm & M, bool & fail ) … … 1091 1094 } 1092 1095 1093 void tryExtgcd( const CanonicalForm & F, const CanonicalForm & G, CanonicalForm & result, CanonicalForm & s, CanonicalForm & t, bool & fail )1094 {1095 // F, G are univariate polynomials (i.e. they have exactly one polynomial variable)1096 // F and G must have the same level AND level > 01097 // we try to calculate gcd(f,g) = s*F + t*G1098 // if a zero divisor is encontered, 'fail' is set to one1099 Variable a, b;1100 if( !hasFirstAlgVar(F,a) && !hasFirstAlgVar(G,b) ) // note lazy evaluation1101 {1102 result = extgcd( F, G, s, t ); // no zero divisors possible1103 return;1104 }1105 if( b.level() > a.level() )1106 a = b;1107 // here: a is the biggest alg. var in F and G1108 CanonicalForm M = getMipo(a);1109 CanonicalForm P;1110 if( degree(F) > degree(G) )1111 {1112 P=F; result=G; s=0; t=1;1113 }1114 else1115 {1116 P=G; result=F; s=1; t=0;1117 }1118 CanonicalForm inv, rem, q, u, v;1119 // here: degree(P) >= degree(result)1120 while(true)1121 {1122 tryInvert( Lc(result), M, inv, fail );1123 if(fail)1124 return;1125 // here: Lc(result) is invertible modulo M1126 q = Lc(P)*inv * power( P.mvar(), degree(P)-degree(result) );1127 rem = P - q*result;1128 // here: s*F + t*G = result1129 if( rem.isZero() )1130 {1131 s*=inv;1132 t*=inv;1133 result *= inv; // monify result1134 return;1135 }1136 P=result;1137 result=rem;1138 rem=u-q*s;1139 u=s;1140 s=rem;1141 rem=v-q*t;1142 v=t;1143 t=rem;1144 }1145 }1146 1147 void tryCRA( const CanonicalForm & x1, const CanonicalForm & q1, const CanonicalForm & x2, const CanonicalForm & q2, CanonicalForm & xnew, CanonicalForm & qnew, bool & fail )1148 { // polys of level <= 1 are considered coefficients. q1,q2 are assumed to be coprime1149 // xnew = x1 mod q1 (coefficientwise in the above sense)1150 // xnew = x2 mod q21151 // qnew = q1*q21152 CanonicalForm tmp;1153 if(x1.level() <= 1 && x2.level() <= 1) // base case1154 {1155 tryExtgcd(q1,q2,tmp,xnew,qnew,fail);1156 if(fail)1157 return;1158 xnew = x1 + (x2-x1) * xnew * q1;1159 qnew = q1*q2;1160 xnew = mod(xnew,qnew);1161 return;1162 }1163 CanonicalForm tmp2;1164 xnew = 0;1165 qnew = q1 * q2;1166 // here: x1.level() > 1 || x2.level() > 11167 if(x1.level() > x2.level())1168 {1169 for(CFIterator i=x1; i.hasTerms(); i++)1170 {1171 if(i.exp() == 0) // const. term1172 {1173 tryCRA(i.coeff(),q1,x2,q2,tmp,tmp2,fail);1174 if(fail)1175 return;1176 xnew += tmp;1177 }1178 else1179 {1180 tryCRA(i.coeff(),q1,0,q2,tmp,tmp2,fail);1181 if(fail)1182 return;1183 xnew += tmp * power(x1.mvar(),i.exp());1184 }1185 }1186 return;1187 }1188 // here: x1.level() <= x2.level() && ( x1.level() > 1 || x2.level() > 1 )1189 if(x2.level() > x1.level())1190 {1191 for(CFIterator j=x2; j.hasTerms(); j++)1192 {1193 if(j.exp() == 0) // const. term1194 {1195 tryCRA(x1,q1,j.coeff(),q2,tmp,tmp2,fail);1196 if(fail)1197 return;1198 xnew += tmp;1199 }1200 else1201 {1202 tryCRA(0,q1,j.coeff(),q2,tmp,tmp2,fail);1203 if(fail)1204 return;1205 xnew += tmp * power(x2.mvar(),j.exp());1206 }1207 }1208 return;1209 }1210 // here: x1.level() == x2.level() && x1.level() > 1 && x2.level() > 11211 CFIterator i = x1;1212 CFIterator j = x2;1213 while(i.hasTerms() || j.hasTerms())1214 {1215 if(i.hasTerms())1216 {1217 if(j.hasTerms())1218 {1219 if(i.exp() == j.exp())1220 {1221 tryCRA(i.coeff(),q1,j.coeff(),q2,tmp,tmp2,fail);1222 if(fail)1223 return;1224 xnew += tmp * power(x1.mvar(),i.exp());1225 i++; j++;1226 }1227 else1228 {1229 if(i.exp() < j.exp())1230 {1231 tryCRA(i.coeff(),q1,0,q2,tmp,tmp2,fail);1232 if(fail)1233 return;1234 xnew += tmp * power(x1.mvar(),i.exp());1235 i++;1236 }1237 else // i.exp() > j.exp()1238 {1239 tryCRA(0,q1,j.coeff(),q2,tmp,tmp2,fail);1240 if(fail)1241 return;1242 xnew += tmp * power(x1.mvar(),j.exp());1243 j++;1244 }1245 }1246 }1247 else // j is out of terms1248 {1249 tryCRA(i.coeff(),q1,0,q2,tmp,tmp2,fail);1250 if(fail)1251 return;1252 xnew += tmp * power(x1.mvar(),i.exp());1253 i++;1254 }1255 }1256 else // i is out of terms1257 {1258 tryCRA(0,q1,j.coeff(),q2,tmp,tmp2,fail);1259 if(fail)1260 return;1261 xnew += tmp * power(x1.mvar(),j.exp());1262 j++;1263 }1264 }1265 }1266
Note: See TracChangeset
for help on using the changeset viewer.