Changeset e7676a in git for factory/cf_gcd.cc


Ignore:
Timestamp:
May 7, 2012, 3:55:50 PM (12 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
517530b37f04ee705b7b271243a265748c447cf5dccd6db99cc44c93669e843ddb6e06d2682769b8
Parents:
a034968a1bff5f6e4e9ad126551a2e9a377d9f6060cc1289a79586c1732ba3885997c3cb49bc01d9
Message:
Merge pull request #100 from mmklee/ezgcd_sw

Ezgcd sw
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/cf_gcd.cc

    ra03496 re7676a  
    757757  else if (!fc_and_gc_Univariate)
    758758  {
    759     if (
    760     isOn(SW_USE_CHINREM_GCD)
    761     && (isPurePoly_m(fc)) && (isPurePoly_m(gc))
    762     )
    763     {
    764     #if 0
    765       if ( p1 == fc.level() )
    766         fc = chinrem_gcd( fc, gc );
    767       else
    768       {
    769         fc = replacevar( fc, Variable(p1), Variable(mp) );
    770         gc = replacevar( gc, Variable(p1), Variable(mp) );
    771         fc = replacevar( chinrem_gcd( fc, gc ), Variable(mp), Variable(p1) );
    772       }
    773     #else
    774       fc = chinrem_gcd( fc, gc);
    775     #endif
    776     }
    777     else if ( isOn( SW_USE_EZGCD ) )
    778     {
    779       if ( pe == 1 )
     759    if ( isOn( SW_USE_EZGCD ) )
     760    {
     761      fc= ezgcd (fc, gc);
     762      /*if ( pe == 1 )
    780763        fc = ezgcd( fc, gc );
    781764      else if ( pe > 0 )// no variable at position 1
     
    791774        gc = swapvar( gc, Variable(pe), Variable(1) );
    792775        fc = swapvar( ezgcd( fc, gc ), Variable(1), Variable(pe) );
     776      }*/
     777    }
     778    else if (
     779    isOn(SW_USE_CHINREM_GCD)
     780    && (isPurePoly_m(fc)) && (isPurePoly_m(gc))
     781    )
     782    {
     783    #if 0
     784      if ( p1 == fc.level() )
     785        fc = chinrem_gcd( fc, gc );
     786      else
     787      {
     788        fc = replacevar( fc, Variable(p1), Variable(mp) );
     789        gc = replacevar( gc, Variable(p1), Variable(mp) );
     790        fc = replacevar( chinrem_gcd( fc, gc ), Variable(mp), Variable(p1) );
    793791      }
     792    #else
     793      fc = chinrem_gcd( fc, gc);
     794    #endif
    794795    }
    795796    else
     
    12361237
    12371238  CanonicalForm Dn, test= 0;
     1239  cl =  gcd (f.lc(),g.lc());
     1240  CanonicalForm gcdcfcg= gcd (cf, cg);
     1241  CanonicalForm b= 1;
     1242  int minCommonDeg= 0;
     1243  for (i= tmax (f.level(), g.level()); i > 0; i--)
     1244  {
     1245    if (degree (f, i) <= 0 || degree (g, i) <= 0)
     1246      continue;
     1247    else
     1248    {
     1249      minCommonDeg= tmin (degree (g, i), degree (f, i));
     1250      break;
     1251    }
     1252  }
     1253  if (i == 0)
     1254    return gcdcfcg;
     1255  for (; i > 0; i--)
     1256  {
     1257    if (degree (f, i) <= 0 || degree (g, i) <= 0)
     1258      continue;
     1259    else
     1260      minCommonDeg= tmin (minCommonDeg, tmin (degree (g, i), degree (f, i)));
     1261  }
     1262  b= 2*tmin (maxNorm (f), maxNorm (g))*abs (cl)*
     1263     power (CanonicalForm (2), minCommonDeg);
    12381264  bool equal= false;
    12391265  i = cf_getNumBigPrimes() - 1;
    1240   cl =  gcd (f.lc(),g.lc());
    1241 
    1242   CanonicalForm gcdcfcg= gcd (cf, cg);
     1266
     1267  CanonicalForm cof, cog, cofp, cogp, newCof, newCog, cofn, cogn;
    12431268  //Off (SW_RATIONAL);
    12441269  while ( true )
     
    12461271    p = cf_getBigPrime( i );
    12471272    i--;
    1248     while ( i >= 0 && mod( cl, p ) == 0 )
     1273    while ( i >= 0 && mod( cl*(lc(f)/cl)*(lc(g)/cl), p ) == 0 )
    12491274    {
    12501275      p = cf_getBigPrime( i );
     
    12531278    //printf("try p=%d\n",p);
    12541279    setCharacteristic( p );
    1255     Dp = gcd_poly( mapinto( f ), mapinto( g ) );
     1280    Dp = GCD_small_p (mapinto (f), mapinto (g), cofp, cogp);
    12561281    Dp /=Dp.lc();
     1282    cofp /= lc (cofp);
     1283    cogp /= lc (cogp);
    12571284    setCharacteristic( 0 );
    12581285    dp_deg=totaldegree(Dp);
     
    12651292    {
    12661293      D = mapinto( Dp );
     1294      cof= mapinto (cofp);
     1295      cog= mapinto (cogp);
    12671296      d_deg=dp_deg;
    12681297      q = p;
     
    12731302      {
    12741303        chineseRemainder( D, q, mapinto( Dp ), p, newD, newq );
     1304        chineseRemainder( cof, q, mapinto (cofp), p, newCof, newq);
     1305        chineseRemainder( cog, q, mapinto (cogp), p, newCog, newq);
     1306        cof= newCof;
     1307        cog= newCog;
    12751308        q = newq;
    12761309        D = newD;
     
    12821315        q = p;
    12831316        D = mapinto( Dp );
     1317        cof= mapinto (cof);
     1318        cog= mapinto (cog);
    12841319        d_deg=dp_deg;
    12851320        test= 0;
     
    12951330    {
    12961331      Dn= Farey(D,q);
     1332      cofn= Farey(cof,q);
     1333      cogn= Farey(cog,q);
    12971334      int is_rat= isOn (SW_RATIONAL);
    12981335      On (SW_RATIONAL);
    12991336      cd = bCommonDen( Dn ); // we need On(SW_RATIONAL)
     1337      cofn *= bCommonDen (cofn);
     1338      cogn *= bCommonDen (cogn);
    13001339      if (!is_rat)
    13011340        Off (SW_RATIONAL);
     
    13061345        equal= true;
    13071346      //Dn /=vcontent(Dn,Variable(1));
    1308       if (equal && fdivides( Dn, f ) && fdivides( Dn, g ) )
     1347      if ((terminationTest (f,g, cofn, cogn, Dn)) ||
     1348          ((equal || q > b) && fdivides (Dn, f) && fdivides (Dn, g)))
    13091349      {
    13101350        //printf(" -> success\n");
     
    13251365}
    13261366
     1367
Note: See TracChangeset for help on using the changeset viewer.