Changeset 7af0e48 in git for factory


Ignore:
Timestamp:
Jul 30, 2002, 5:23:51 PM (22 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
412bedd0d8fb0ee909f2782332e9750b3d45b71a
Parents:
b2231c92ab6b80cbd9f6b556cd9aa757c5afc3f3
Message:
*hannes: NTL


git-svn-id: file:///usr/local/Singular/svn/trunk@6227 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/cf_factor.cc

    rb2231c r7af0e48  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: cf_factor.cc,v 1.12 2002-03-08 10:31:46 Singular Exp $ */
     2/* $Id: cf_factor.cc,v 1.13 2002-07-30 15:23:51 Singular Exp $ */
    33
    44//{{{ docu
     
    2929
    3030#include "int_int.h"
    31 #if 0
     31#ifdef HAVE_NTL
    3232#include "NTLconvert.h"
    3333#endif
     
    5050    int e=f.level();
    5151    CFIterator i = f;
    52     if (i.exp() > exp_f[e]) exp_f[e]=i.exp();
     52    if (e>=0)
     53    {
     54      if (i.exp() > exp_f[e]) exp_f[e]=i.exp();
     55    }
    5356    for (; i.hasTerms(); i++ )
    5457    {
     
    7679}
    7780
     81#if 0
     82void out_cf(char *s1,const CanonicalForm &f,char *s2)
     83{
     84  printf("%s",s1);
     85  if (f==0) printf("+0");
     86  else if (! f.inCoeffDomain() )
     87  {
     88    int l = f.level();
     89    for ( CFIterator i = f; i.hasTerms(); i++ )
     90    {
     91      int e=i.exp();
     92      printf("+(");out_cf("+(",i.coeff(),")*v(");printf("%d)^%d",l,e);
     93    }
     94  }
     95  else
     96  {
     97    if ( f.isImm() )
     98    {
     99      printf("+%d(",f.intval());
     100    }
     101    else printf("+...(");
     102    if (f.inZ()) printf("Z)");
     103    else if (f.inQ()) printf("Q)");
     104    else if (f.inFF()) printf("FF)");
     105    else if (f.inPP()) printf("PP)");
     106    else if (f.inGF()) printf("PP)");
     107    else if (f.inExtension()) printf("E(%d))",f.level());
     108
     109  }
     110  printf("%s",s2);
     111}
     112void out_cff(CFFList &L)
     113{
     114  int n = L.length();
     115  CFFListIterator J=L;
     116  int j=0;
     117  for ( ; J.hasItem(); J++, j++ )
     118  {
     119    printf("F%d",j);out_cf(":",J.getItem().factor()," ^ ");
     120    printf("%d\n", J.getItem().exp());
     121  }
     122}
     123void test_cff(CFFList &L,const CanonicalForm & f)
     124{
     125  int n = L.length();
     126  CFFListIterator J=L;
     127  CanonicalForm t=1;
     128  int j=0;
     129  if (!(L.getFirst().factor().inCoeffDomain()))
     130    printf("first entry is not const\n");
     131  for ( ; J.hasItem(); J++, j++ )
     132  {
     133    CanonicalForm tt=J.getItem().factor();
     134    if (tt.inCoeffDomain() && (j!=0))
     135      printf("other entry is const\n");
     136    j=J.getItem().exp();
     137    while(j>0) { t*=tt; j--; }
     138  }
     139  if ((f-t)!=0) { printf("problem:\n");out_cf("factor:",f," has problems\n");}
     140}
     141#endif
     142
     143static bool isPurePoly(const CanonicalForm & f)
     144{
     145  if (f.level()<=0) return false;
     146  for (CFIterator i=f;i.hasTerms();i++)
     147  {
     148    if (!(i.coeff().inBaseDomain())) return false;
     149  }
     150  return true;
     151}
     152
    78153CFFList factorize ( const CanonicalForm & f, bool issqrfree )
    79154{
    80155  if ( f.inCoeffDomain() )
    81         return CFFList( f );
     156        return CFFList( f );
    82157  int mv=f.level();
    83158  if (! f.isUnivariate() )
     
    88163      swapvar(f,Variable(mv),f.mvar());
    89164    }
     165    if ( getCharacteristic() == 0 ) Off(SW_USE_NTL);
    90166  }
    91167  CFFList F;
    92   if ( getCharacteristic() > 0 ) 
     168  if ( getCharacteristic() > 0 )
    93169  {
    94170    ASSERT( f.isUnivariate(), "multivariate factorization not implemented" );
    95     #if 0
    96     if (isOn(SW_USE_NTL) && (getExp()==1))
    97     {
    98       printf("start ntl...\n");
     171    #ifdef HAVE_NTL
     172    if (isOn(SW_USE_NTL) && (isPurePoly(f)))
     173    {
    99174      // USE NTL
    100175      if (getCharacteristic()!=2)
    101176      {
    102         // set remainder 
     177        // set remainder
    103178        ZZ r;
    104         r=getCharacteristic();   
     179        r=getCharacteristic();
    105180        ZZ_pContext ccc(r);
    106181        ccc.restore();
     182        ZZ_p::init(r);
    107183        // convert to NTL
    108         ZZ_pX f1=convertFacCF2NTLZZpX(f); 
     184        ZZ_pX f1=convertFacCF2NTLZZpX(f);
    109185        ZZ_p leadcoeff = LeadCoeff(f1);
    110186        //make monic
     
    114190        vec_pair_ZZ_pX_long factors;
    115191        CanZass(factors,f1);
    116        
     192
    117193        // convert back to factory
    118194        F=convertNTLvec_pair_ZZpX_long2FacCFFList(factors,leadcoeff,f.mvar());
     195        //test_cff(F,f);
    119196      }
    120197      else
    121198      {
    122199        // Specialcase characteristic==2
    123          
     200        ZZ r;r=2;
     201        ZZ_p::init(r);
     202
    124203        // remainder is 2 --> nothing to set
    125          
     204
    126205        // convert to NTL using the faster conversion routine for characteristic 2
    127206        GF2X f1=convertFacCF2NTLGF2X(f);
    128      
    129207        // no make monic necessary in GF2
    130 
    131208        //factorize
    132209        vec_pair_GF2X_long factors;
    133210        CanZass(factors,f1);
    134          
     211
    135212        // convert back to factory again using the faster conversion routine for vectors over GF2X
    136        F=convertNTLvec_pair_GF2X_long2FacCFFList(factors,LeadCoeff(f1),f.mvar());
    137       }
    138       printf("... end ntl\n");
     213        F=convertNTLvec_pair_GF2X_long2FacCFFList(factors,LeadCoeff(f1),f.mvar());
     214      }
    139215    }
    140216    else
     
    143219      if ( isOn( SW_BERLEKAMP ) )
    144220         F=FpFactorizeUnivariateB( f, issqrfree );
    145       else   
     221      else
    146222        F=FpFactorizeUnivariateCZ( f, issqrfree, 0, Variable(), Variable() );
    147     }     
     223    }
    148224  }
    149225  else
     
    155231    if ( f.isUnivariate() )
    156232    {
    157       #if 0
    158       if (isOn(SW_USE_NTL))
    159       { 
    160         printf("start ntl...\n");
     233      #ifdef HAVE_NTL
     234      if ((isOn(SW_USE_NTL)) && (isPurePoly(f)))
     235      {
    161236        //USE NTL
     237        CanonicalForm ic=icontent(fz);
     238        fz/=ic;
    162239        ZZ c;
    163240        vec_pair_ZZX_long factors;
    164241        //factorize the converted polynomial
    165         factor(c,factors,convertFacCF2NTLZZX(fz));               
    166            
     242        factor(c,factors,convertFacCF2NTLZZX(fz));
     243
    167244        //convert the result back to Factory
    168245        F=convertNTLvec_pair_ZZX_long2FacCFFList(factors,c,fz.mvar());
    169         printf("... end ntl\n");
     246        if ( ! ic.isOne() )
     247        {
     248          if ( F.getFirst().factor().inCoeffDomain() )
     249          {
     250            CFFactor new_first( F.getFirst().factor() * ic );
     251            F.removeFirst();
     252            F.insert( new_first );
     253          }
     254          else
     255            F.insert( CFFactor( ic ) );
     256        }
     257        if ( F.getFirst().factor().isOne() )
     258        {
     259          F.removeFirst();
     260        }
    170261      }
    171262      else
    172263      #endif
    173       {           
     264      {
    174265        //Use Factory without NTL
    175266        F = ZFactorizeUnivariate( fz, issqrfree );
     
    194285      }
    195286    }
    196   } 
     287  }
    197288
    198289  if ((mv!=f.level()) && (! f.isUnivariate() ))
     
    210301CFFList factorize ( const CanonicalForm & f, const Variable & alpha )
    211302{
     303    CFFList F;
    212304    ASSERT( alpha.level() < 0, "not an algebraic extension" );
    213305    ASSERT( f.isUnivariate(), "multivariate factorization not implemented" );
    214306    ASSERT( getCharacteristic() > 0, "char 0 factorization not implemented" );
    215     #if 0
     307    #ifdef HAVE_NTL
    216308    if  (isOn(SW_USE_NTL))
    217309    {
    218310      //USE NTL
    219       if (getCharacteristic()!=2)
    220       {       
     311      if (1 ) //getCharacteristic()!=2)
     312      {
    221313        // First all cases with characteristic !=2
    222         // set remainder 
     314        // set remainder
    223315        ZZ r;
    224         r=getCharacteristic();   
     316        r=getCharacteristic();
    225317        ZZ_pContext ccc(r);
    226318        ccc.restore();
    227      
     319
    228320        // set minimal polynomial in NTL
    229321        ZZ_pX minPo=convertFacCF2NTLZZpX(getMipo(alpha,f.mvar()));
     
    232324
    233325        // convert to NTL
    234         ZZ_pEX f1=to_ZZ_pEX(convertFacCF2NTLZZpX(f));
    235        
     326        ZZ_pEX f1=convertFacCF2NTLZZ_pEX(f,minPo);
     327
    236328        //make monic
    237329        ZZ_pE leadcoeff= LeadCoeff(f1);
     
    243335
    244336        // return converted result
    245         return convertNTLvec_pair_ZZpEX_long2FacCFFList(factors,leadcoeff,f.mvar(),alpha);
     337        F=convertNTLvec_pair_ZZpEX_long2FacCFFList(factors,leadcoeff,f.mvar(),alpha);
    246338      }
    247339      else
    248340      {
    249341        // special case : GF2
    250        
     342
    251343        // remainder is two ==> nothing to do
    252344
     
    255347        GF2EContext c(minPo);
    256348        c.restore();
    257        
     349
    258350        // convert to NTL again using the faster conversion routines
    259         GF2EX f1=to_GF2EX(convertFacCF2NTLGF2X(f));
    260        
     351        GF2X f_tmp=convertFacCF2NTLGF2X(f);
     352        GF2EX f1=to_GF2EX(f_tmp);
     353
    261354        // no make monic necessary in GF2
    262        
     355
    263356        // factorize using NTL
    264357        vec_pair_GF2EX_long factors;
     
    266359
    267360        // return converted result
    268         return convertNTLvec_pair_GF2EX_long2FacCFFList(factors,LeadCoeff(f1),f.mvar(),alpha);
    269       }
    270      
    271     }
    272     else   
     361        F=convertNTLvec_pair_GF2EX_long2FacCFFList(factors,LeadCoeff(f1),f.mvar(),alpha);
     362      }
     363
     364    }
     365    else
    273366    #endif
    274367    {
    275       return FpFactorizeUnivariateCZ( f, false, 1, alpha, Variable() );
    276     }
    277    
     368      F=FpFactorizeUnivariateCZ( f, false, 1, alpha, Variable() );
     369    }
     370    return F;
    278371}
    279372
     
    284377
    285378    if ( getCharacteristic() == 0 )
    286         result = sqrFreeZ( f );
    287     else
    288         result = sqrFreeFp( f );
     379        result = sqrFreeZ( f );
     380    else
     381        result = sqrFreeFp( f );
    289382
    290383    return ( sort ? sortCFFList( result ) : result );
     
    295388//    ASSERT( f.isUnivariate(), "multivariate factorization not implemented" );
    296389    if ( getCharacteristic() == 0 )
    297         return isSqrFreeZ( f );
    298     else
    299         return isSqrFreeFp( f );
    300 }
    301 
     390        return isSqrFreeZ( f );
     391    else
     392        return isSqrFreeFp( f );
     393}
     394
Note: See TracChangeset for help on using the changeset viewer.