Changeset 034eec in git


Ignore:
Timestamp:
Jan 20, 2004, 4:39:52 PM (20 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
0ae61c6dbdc8ee3e150c56f17b9989cada5fd83c
Parents:
02da1e214204d265d3630b6f20cffc2ee0c7b979
Message:
*hannes:ntl-gcd


git-svn-id: file:///usr/local/Singular/svn/trunk@6997 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
factory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • factory/cf_factor.cc

    r02da1e r034eec  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: cf_factor.cc,v 1.22 2004-01-19 11:27:46 Singular Exp $ */
     2/* $Id: cf_factor.cc,v 1.23 2004-01-20 15:39:52 Singular Exp $ */
    33
    44//{{{ docu
     
    160160#endif
    161161
    162 static bool isPurePoly(const CanonicalForm & f)
     162bool isPurePoly(const CanonicalForm & f)
    163163{
    164164  if (f.level()<=0) return false;
  • factory/cf_gcd.cc

    r02da1e r034eec  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: cf_gcd.cc,v 1.22 2004-01-19 11:26:20 Singular Exp $ */
     2/* $Id: cf_gcd.cc,v 1.23 2004-01-20 15:39:52 Singular Exp $ */
    33
    44#include <config.h>
     
    1919
    2020#ifdef HAVE_NTL
     21#include <NTL/ZZX.h>
    2122#include "NTLconvert.h"
     23bool isPurePoly(const CanonicalForm & f);
    2224#endif
    2325
     
    144146extgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a, CanonicalForm & b )
    145147{
    146     CanonicalForm contf = content( f );
    147     CanonicalForm contg = content( g );
    148 
    149     CanonicalForm p0 = f / contf, p1 = g / contg;
    150     CanonicalForm f0 = 1, f1 = 0, g0 = 0, g1 = 1, q, r;
    151 
    152     while ( ! p1.isZero() ) {
    153         divrem( p0, p1, q, r );
    154         p0 = p1; p1 = r;
    155         r = g0 - g1 * q;
    156         g0 = g1; g1 = r;
    157         r = f0 - f1 * q;
    158         f0 = f1; f1 = r;
    159     }
    160     CanonicalForm contp0 = content( p0 );
    161     a = f0 / ( contf * contp0 );
    162     b = g0 / ( contg * contp0 );
    163     p0 /= contp0;
    164     if ( p0.sign() < 0 ) {
    165         p0 = -p0;
    166         a = -a;
    167         b = -b;
    168     }
    169     return p0;
     148#ifdef HAVE_NTL
     149  if (isOn(SW_USE_NTL_GCD) && ( getCharacteristic() > 0 )
     150  && isPurePoly(f) && isPurePoly(g))
     151  {
     152    zz_pContext ccc(getCharacteristic());
     153    ccc.restore();
     154    zz_p::init(getCharacteristic());
     155    zz_pX F1=convertFacCF2NTLzzpX(f);
     156    zz_pX G1=convertFacCF2NTLzzpX(g);
     157    zz_pX R;
     158    zz_pX A,B;
     159    XGCD(R,A,B,F1,G1);
     160    a=convertNTLzzpX2CF(A,f.mvar());
     161    b=convertNTLzzpX2CF(B,f.mvar());
     162    return convertNTLzzpX2CF(R,f.mvar());
     163  }
     164#endif
     165  CanonicalForm contf = content( f );
     166  CanonicalForm contg = content( g );
     167
     168  CanonicalForm p0 = f / contf, p1 = g / contg;
     169  CanonicalForm f0 = 1, f1 = 0, g0 = 0, g1 = 1, q, r;
     170
     171  while ( ! p1.isZero() ) {
     172      divrem( p0, p1, q, r );
     173      p0 = p1; p1 = r;
     174      r = g0 - g1 * q;
     175      g0 = g1; g1 = r;
     176      r = f0 - f1 * q;
     177      f0 = f1; f1 = r;
     178  }
     179  CanonicalForm contp0 = content( p0 );
     180  a = f0 / ( contf * contp0 );
     181  b = g0 / ( contg * contp0 );
     182  p0 /= contp0;
     183  if ( p0.sign() < 0 ) {
     184      p0 = -p0;
     185      a = -a;
     186      b = -b;
     187  }
     188  return p0;
    170189}
    171190//}}}
     
    175194{
    176195#ifdef HAVE_NTL
    177   if (isOn(SW_USE_NTL_GCD))
     196  if (isOn(SW_USE_NTL_GCD) && isPurePoly(F) && isPurePoly(G))
    178197  {
    179198    if ( getCharacteristic() > 0 )
     
    295314    C = gcd( Ci, Ci1 );
    296315    pi1 = pi1 / Ci1; pi = pi / Ci;
    297     if ( pi.isUnivariate() && pi1.isUnivariate() ) {
    298         if ( modularflag )
    299             return gcd_poly_univar0( pi, pi1, true ) * C;
    300     }
    301     else
    302         if ( gcd_test_one( pi1, pi, true ) )
    303             return C;
     316    if ( pi.isUnivariate() && pi1.isUnivariate() )
     317    {
     318      if ( modularflag
     319#ifdef HAVE_NTL
     320      || (isOn(SW_USE_NTL_GCD) && isPurePoly(pi) && isPurePoly(pi1))
     321#endif
     322      )
     323        return gcd_poly_univar0( pi, pi1, true ) * C;
     324    }
     325    else if ( gcd_test_one( pi1, pi, true ) )
     326      return C;
    304327    delta = degree( pi, v ) - degree( pi1, v );
    305328    Hi = power( LC( pi1, v ), delta );
Note: See TracChangeset for help on using the changeset viewer.