Changeset 9f84ad in git


Ignore:
Timestamp:
Apr 24, 2012, 4:38:56 PM (11 years ago)
Author:
Martin Lee <martinlee84@…>
Branches:
(u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
Children:
47046743f1273df49ef99fda72ed22a1531d10bd
Parents:
c244d04150a9fd45331938d2c9fb6f89985acb05
git-author:
Martin Lee <martinlee84@web.de>2012-04-24 16:38:56+02:00
git-committer:
Martin Lee <martinlee84@web.de>2012-05-07 14:16:12+02:00
Message:
chg: try to use evaluation points that preserve sparseness chg: handling of SW_RATIONAL
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/fac_ezgcd.cc

    rc244d04 r9f84ad  
    342342}
    343343
     344static
     345bool findeval (const CanonicalForm & F, const CanonicalForm & G,
     346               CanonicalForm & Fb, CanonicalForm & Gb, CanonicalForm & Db,
     347               REvaluation & b, int delta, int degF, int degG, int maxeval,
     348               int & count, int& k, int bound, int& l)
     349{
     350  if( count == 0 && delta != 0)
     351  {
     352    if( count++ > maxeval )
     353      return false;
     354  }
     355  if (count > 0)
     356  {
     357    b.nextpoint(k);
     358    if (k == 0)
     359      k++;
     360    l++;
     361    if (l > bound)
     362    {
     363      l= 1;
     364      k++;
     365      if (k > tmax (F.level(), G.level()) - 1)
     366        return false;
     367      b.nextpoint (k);
     368    }
     369    if (count++ > maxeval)
     370      return false;
     371  }
     372  while( true )
     373  {
     374    Fb = b( F );
     375    if( degree( Fb, 1 ) == degF )
     376    {
     377      Gb = b( G );
     378      if( degree( Gb, 1 ) == degG )
     379      {
     380        Db = gcd( Fb, Gb );
     381        if( delta > 0 )
     382        {
     383          if( degree( Db, 1 ) <= delta )
     384            return true;
     385        }
     386        else
     387        {
     388          k++;
     389          return true;
     390        }
     391      }
     392    }
     393    if (k == 0)
     394      k++;
     395    b.nextpoint(k);
     396    l++;
     397    if (l > bound)
     398    {
     399      l= 1;
     400      k++;
     401      if (k > tmax (F.level(), G.level()) - 1)
     402        return false;
     403      b.nextpoint (k);
     404    }
     405    if( count++ > maxeval )
     406      return false;
     407  }
     408}
     409
    344410static CanonicalForm
    345411ezgcd ( const CanonicalForm & FF, const CanonicalForm & GG, REvaluation & b,
     
    347413{
    348414  bool isRat= isOn (SW_RATIONAL);
    349   if (!isRat)
    350     On (SW_RATIONAL);
    351415  CanonicalForm F, G, f, g, d, Fb, Gb, Db, Fbt, Gbt, Dbt, B0, B, D0, lcF, lcG,
    352416                lcD, cand, result;
    353417  CFArray DD( 1, 2 ), lcDD( 1, 2 );
    354   int degF, degG, delta, t;
     418  int degF, degG, delta, t, count, maxeval;
    355419  REvaluation bt;
    356420  bool gcdfound = false;
    357421  Variable x = Variable(1);
    358   modpk bound;
    359 
    360   F= FF;
    361   G= GG;
     422  count= 0;
     423  maxeval= 200;
     424  int o, l;
     425  o= 0;
     426  l= 1;
     427
     428  if (!isRat)
     429    On (SW_RATIONAL);
     430  F= FF*bCommonDen (FF);
     431  G= GG*bCommonDen (GG);
     432  if (!isRat)
     433    Off (SW_RATIONAL);
    362434
    363435  CFMap M,N;
     
    367439  if (best_level == 0)
    368440  {
    369     if (!isRat)
    370       Off (SW_RATIONAL);
     441    DEBDECLEVEL( cerr, "ezgcd" );
    371442    return G.genOne();
    372443  }
     
    374445  F= M (F);
    375446  G= M (G);
    376 
    377447
    378448  DEBINCLEVEL( cerr, "ezgcd" );
     
    380450  DEBOUTLN( cerr, "GG = " << GG );
    381451  f = content( F, x ); g = content( G, x ); d = gcd( f, g );
     452  d /= icontent (d);
    382453  DEBOUTLN( cerr, "f = " << f );
    383454  DEBOUTLN( cerr, "g = " << g );
     
    386457  {
    387458    DEBDECLEVEL( cerr, "ezgcd" );
    388     if (!isRat)
    389       Off (SW_RATIONAL);
    390459    if(F.mvar()==G.mvar())
    391460      d*=gcd(F,G);
    392461    return N (d);
    393462  }
    394   else  if ( gcd_test_one( F, G, false ) )
     463
     464  int maxNumVars= tmax (getNumVars (F), getNumVars (G));
     465  int sizeF= size (F);
     466  int sizeG= size (G);
     467
     468
     469  if (!isRat)
     470    On (SW_RATIONAL);
     471  if (sizeF/maxNumVars > 500 && sizeG/maxNumVars > 500)
     472  {
     473    Off(SW_USE_EZGCD);
     474    result=gcd( F, G );
     475    On(SW_USE_EZGCD);
     476    if (!isRat)
     477      Off (SW_RATIONAL);
     478    result /= icontent (result);
     479    DEBDECLEVEL( cerr, "ezgcd" );
     480    return N (d*result);
     481  }
     482
     483  if ( gcd_test_one( F, G, false ) )
    395484  {
    396485    DEBDECLEVEL( cerr, "ezgcd" );
     
    404493  degF = degree( F, x ); degG = degree( G, x );
    405494  t = tmax( F.level(), G.level() );
    406   //bound = findBound( F, G, lcF, lcG, degF, degG );
    407495  if ( ! internal )
    408496    b = REvaluation( 2, t, IntRandom( 25 ) );
     
    413501    DEBOUTLN( cerr, "F = " << F );
    414502    DEBOUTLN( cerr, "G = " << G );
    415     findeval( F, G, Fb, Gb, Db, b, delta, degF, degG );
     503    if (!findeval( F, G, Fb, Gb, Db, b, delta, degF, degG, maxeval, count,
     504                   o, 25, l))
     505    {
     506      Off(SW_USE_EZGCD);
     507      result=gcd( F, G );
     508      On(SW_USE_EZGCD);
     509      if (!isRat)
     510        Off (SW_RATIONAL);
     511      DEBDECLEVEL( cerr, "ezgcd" );
     512      result /= icontent (result);
     513      return N (d*result);
     514    }
    416515    DEBOUTLN( cerr, "found evaluation b = " << b );
    417516    DEBOUTLN( cerr, "F(b) = " << Fb );
     
    432531    {
    433532      bt = b;
    434       findeval( F, G, Fbt, Gbt, Dbt, bt, delta + 1, degF, degG );
     533      if (!findeval( F, G, Fbt, Gbt, Dbt, bt, delta, degF, degG, maxeval, count,
     534                     o, 25,l ))
     535      {
     536        Off(SW_USE_EZGCD);
     537        result=gcd( F, G );
     538        On(SW_USE_EZGCD);
     539        if (!isRat)
     540          Off (SW_RATIONAL);
     541        DEBDECLEVEL( cerr, "ezgcd" );
     542        result /= icontent (result);
     543        return N (d*result);
     544      }
    435545      int dd=degree( Dbt );
    436546      if ( dd /*degree( Dbt )*/ == 0 )
     
    515625        if (!isRat)
    516626          Off (SW_RATIONAL);
     627        DEBDECLEVEL( cerr, "ezgcd" );
     628        result /= icontent (result);
    517629        return N (d*result);
    518630      }
     
    535647        if (!isRat)
    536648          Off (SW_RATIONAL);
     649        DEBDECLEVEL( cerr, "ezgcd" );
     650        result /= icontent (result);
    537651        return N (d*result);
    538652      }
     
    549663  /// ---> A9
    550664  DEBDECLEVEL( cerr, "ezgcd" );
     665  cand *= bCommonDen (cand);
    551666  if (!isRat)
    552667    Off (SW_RATIONAL);
     668  cand /= icontent (cand);
    553669  return N (d*cand);
    554670}
Note: See TracChangeset for help on using the changeset viewer.