Changeset 9fd8d2 in git for factory/algext.cc


Ignore:
Timestamp:
Jan 8, 2014, 11:40:54 AM (10 years ago)
Author:
Martin Lee <martinlee84@…>
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
Message:
chg: deleted unused tryCRA and tryExtgcd
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/algext.cc

    r7c4341 r9fd8d2  
    239239}
    240240
     241#ifndef HAVE_NTL
    241242void tryDivrem (const CanonicalForm& F, const CanonicalForm& G, CanonicalForm& Q,
    242243                CanonicalForm& R, CanonicalForm& inv, const CanonicalForm& mipo,
     
    345346  }
    346347}
     348#endif
    347349
    348350bool hasFirstAlgVar( const CanonicalForm & f, Variable & a )
     
    972974}
    973975
     976#ifndef HAVE_NTL
    974977void tryExtgcd( const CanonicalForm & F, const CanonicalForm & G, const CanonicalForm & M, CanonicalForm & result, CanonicalForm & s, CanonicalForm & t, bool & fail )
    975978{ // F, G are univariate polynomials (i.e. they have exactly one polynomial variable)
     
    10411044  }
    10421045}
    1043 
     1046#endif
    10441047
    10451048static CanonicalForm trycontent ( const CanonicalForm & f, const Variable & x, const CanonicalForm & M, bool & fail )
     
    10911094}
    10921095
    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 > 0
    1097   // we try to calculate gcd(f,g) = s*F + t*G
    1098   // if a zero divisor is encontered, 'fail' is set to one
    1099   Variable a, b;
    1100   if( !hasFirstAlgVar(F,a) && !hasFirstAlgVar(G,b) ) // note lazy evaluation
    1101   {
    1102     result = extgcd( F, G, s, t ); // no zero divisors possible
    1103     return;
    1104   }
    1105   if( b.level() > a.level() )
    1106     a = b;
    1107   // here: a is the biggest alg. var in F and G
    1108   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   else
    1115   {
    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 M
    1126     q = Lc(P)*inv * power( P.mvar(), degree(P)-degree(result) );
    1127     rem = P - q*result;
    1128     // here: s*F + t*G = result
    1129     if( rem.isZero() )
    1130     {
    1131       s*=inv;
    1132       t*=inv;
    1133       result *= inv; // monify result
    1134       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 coprime
    1149   // xnew = x1 mod q1 (coefficientwise in the above sense)
    1150   // xnew = x2 mod q2
    1151   // qnew = q1*q2
    1152   CanonicalForm tmp;
    1153   if(x1.level() <= 1 && x2.level() <= 1) // base case
    1154   {
    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() > 1
    1167   if(x1.level() > x2.level())
    1168   {
    1169     for(CFIterator i=x1; i.hasTerms(); i++)
    1170     {
    1171       if(i.exp() == 0) // const. term
    1172       {
    1173         tryCRA(i.coeff(),q1,x2,q2,tmp,tmp2,fail);
    1174         if(fail)
    1175           return;
    1176         xnew += tmp;
    1177       }
    1178       else
    1179       {
    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. term
    1194       {
    1195         tryCRA(x1,q1,j.coeff(),q2,tmp,tmp2,fail);
    1196         if(fail)
    1197           return;
    1198         xnew += tmp;
    1199       }
    1200       else
    1201       {
    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() > 1
    1211   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         else
    1228         {
    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 terms
    1248       {
    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 terms
    1257     {
    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.