Changeset a99e31 in git for factory/cf_factor.cc


Ignore:
Timestamp:
Mar 8, 2002, 11:31:46 AM (22 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
82e3b397cda580b0eb004f22f8298631937fcccb
Parents:
7248478bf4e1532750f6423799de6cebde8d2657
Message:
*hannes: NTL -inactive


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

Legend:

Unmodified
Added
Removed
  • factory/cf_factor.cc

    r7248478 ra99e31  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: cf_factor.cc,v 1.11 2001-08-22 14:20:47 Singular Exp $ */
     2/* $Id: cf_factor.cc,v 1.12 2002-03-08 10:31:46 Singular Exp $ */
    33
    44//{{{ docu
     
    2828#include "cf_algorithm.h"
    2929
     30#include "int_int.h"
     31#if 0
     32#include "NTLconvert.h"
     33#endif
     34
     35int getExp(); /* cf_char.cc */
     36
    3037static bool isUnivariateBaseDomain( const CanonicalForm & f )
    3138{
     
    7178CFFList factorize ( const CanonicalForm & f, bool issqrfree )
    7279{
    73     if ( f.inCoeffDomain() )
    74         return CFFList( f );
    75     if ( getCharacteristic() > 0 ) {
    76         ASSERT( f.isUnivariate(), "multivariate factorization not implemented" );
    77         if ( isOn( SW_BERLEKAMP ) )
    78             return FpFactorizeUnivariateB( f, issqrfree );
    79         else
    80             return FpFactorizeUnivariateCZ( f, issqrfree, 0, Variable(), Variable() );
    81     }
    82     else {
    83         int mv=f.level();
    84         if (! f.isUnivariate() )
    85         {
    86           mv=find_mvar(f);
    87           if (mv!=f.level())
    88           {
    89             swapvar(f,Variable(mv),f.mvar());
    90           }
    91         }
    92         CanonicalForm cd = bCommonDen( f );
    93         CanonicalForm fz = f * cd;
    94         CFFList F;
    95         bool on_rational = isOn(SW_RATIONAL);
    96         Off(SW_RATIONAL);
    97         if ( f.isUnivariate() )
    98             F = ZFactorizeUnivariate( fz, issqrfree );
    99         else
    100             F = ZFactorizeMultivariate( fz, issqrfree );
    101         if ( on_rational )
    102             On(SW_RATIONAL);
    103         if ( ! cd.isOne() ) {
    104             if ( F.getFirst().factor().inCoeffDomain() ) {
    105                 CFFactor new_first( F.getFirst().factor() / cd );
    106                 F.removeFirst();
    107                 F.insert( new_first );
    108             }
    109             else {
    110                 F.insert( CFFactor( 1/cd ) );
    111             }
    112         }
    113         if ((mv!=f.level()) && (! f.isUnivariate() ))
    114         {
    115           CFFListIterator J=F;
    116           for ( ; J.hasItem(); J++)
    117           {
    118             swapvar(J.getItem().factor(),Variable(mv),f.mvar());
    119           }
    120           swapvar(f,Variable(mv),f.mvar());
    121         }
    122         return F;
    123     }
     80  if ( f.inCoeffDomain() )
     81        return CFFList( f );
     82  int mv=f.level();
     83  if (! f.isUnivariate() )
     84  {
     85    mv=find_mvar(f);
     86    if (mv!=f.level())
     87    {
     88      swapvar(f,Variable(mv),f.mvar());
     89    }
     90  }
     91  CFFList F;
     92  if ( getCharacteristic() > 0 )
     93  {
     94    ASSERT( f.isUnivariate(), "multivariate factorization not implemented" );
     95    #if 0
     96    if (isOn(SW_USE_NTL) && (getExp()==1))
     97    {
     98      printf("start ntl...\n");
     99      // USE NTL
     100      if (getCharacteristic()!=2)
     101      {
     102        // set remainder
     103        ZZ r;
     104        r=getCharacteristic();   
     105        ZZ_pContext ccc(r);
     106        ccc.restore();
     107        // convert to NTL
     108        ZZ_pX f1=convertFacCF2NTLZZpX(f);
     109        ZZ_p leadcoeff = LeadCoeff(f1);
     110        //make monic
     111        f1=f1 / LeadCoeff(f1);
     112
     113        // factorize
     114        vec_pair_ZZ_pX_long factors;
     115        CanZass(factors,f1);
     116       
     117        // convert back to factory
     118        F=convertNTLvec_pair_ZZpX_long2FacCFFList(factors,leadcoeff,f.mvar());
     119      }
     120      else
     121      {
     122        // Specialcase characteristic==2
     123         
     124        // remainder is 2 --> nothing to set
     125         
     126        // convert to NTL using the faster conversion routine for characteristic 2
     127        GF2X f1=convertFacCF2NTLGF2X(f);
     128     
     129        // no make monic necessary in GF2
     130
     131        //factorize
     132        vec_pair_GF2X_long factors;
     133        CanZass(factors,f1);
     134         
     135        // 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");
     139    }
     140    else
     141    #endif
     142    {  // Use Factory without NTL
     143      if ( isOn( SW_BERLEKAMP ) )
     144         F=FpFactorizeUnivariateB( f, issqrfree );
     145      else   
     146        F=FpFactorizeUnivariateCZ( f, issqrfree, 0, Variable(), Variable() );
     147    }     
     148  }
     149  else
     150  {
     151    CanonicalForm cd = bCommonDen( f );
     152    CanonicalForm fz = f * cd;
     153    bool on_rational = isOn(SW_RATIONAL);
     154    Off(SW_RATIONAL);
     155    if ( f.isUnivariate() )
     156    {
     157      #if 0
     158      if (isOn(SW_USE_NTL))
     159      { 
     160        printf("start ntl...\n");
     161        //USE NTL
     162        ZZ c;
     163        vec_pair_ZZX_long factors;
     164        //factorize the converted polynomial
     165        factor(c,factors,convertFacCF2NTLZZX(fz));               
     166           
     167        //convert the result back to Factory
     168        F=convertNTLvec_pair_ZZX_long2FacCFFList(factors,c,fz.mvar());
     169        printf("... end ntl\n");
     170      }
     171      else
     172      #endif
     173      {           
     174        //Use Factory without NTL
     175        F = ZFactorizeUnivariate( fz, issqrfree );
     176      }
     177    }
     178    else
     179      F = ZFactorizeMultivariate( fz, issqrfree );
     180
     181    if ( on_rational )
     182      On(SW_RATIONAL);
     183    if ( ! cd.isOne() )
     184    {
     185      if ( F.getFirst().factor().inCoeffDomain() )
     186      {
     187        CFFactor new_first( F.getFirst().factor() / cd );
     188        F.removeFirst();
     189        F.insert( new_first );
     190      }
     191      else
     192      {
     193        F.insert( CFFactor( 1/cd ) );
     194      }
     195    }
     196  } 
     197
     198  if ((mv!=f.level()) && (! f.isUnivariate() ))
     199  {
     200    CFFListIterator J=F;
     201    for ( ; J.hasItem(); J++)
     202    {
     203      swapvar(J.getItem().factor(),Variable(mv),f.mvar());
     204    }
     205    swapvar(f,Variable(mv),f.mvar());
     206  }
     207  return F;
    124208}
    125209
     
    129213    ASSERT( f.isUnivariate(), "multivariate factorization not implemented" );
    130214    ASSERT( getCharacteristic() > 0, "char 0 factorization not implemented" );
    131     return FpFactorizeUnivariateCZ( f, false, 1, alpha, Variable() );
     215    #if 0
     216    if  (isOn(SW_USE_NTL))
     217    {
     218      //USE NTL
     219      if (getCharacteristic()!=2)
     220      {       
     221        // First all cases with characteristic !=2
     222        // set remainder
     223        ZZ r;
     224        r=getCharacteristic();   
     225        ZZ_pContext ccc(r);
     226        ccc.restore();
     227     
     228        // set minimal polynomial in NTL
     229        ZZ_pX minPo=convertFacCF2NTLZZpX(getMipo(alpha,f.mvar()));
     230        ZZ_pEContext c(minPo);
     231        c.restore();
     232
     233        // convert to NTL
     234        ZZ_pEX f1=to_ZZ_pEX(convertFacCF2NTLZZpX(f));
     235       
     236        //make monic
     237        ZZ_pE leadcoeff= LeadCoeff(f1);
     238        f1=f1 / leadcoeff;
     239
     240        // factorize using NTL
     241        vec_pair_ZZ_pEX_long factors;
     242        CanZass(factors,f1);
     243
     244        // return converted result
     245        return convertNTLvec_pair_ZZpEX_long2FacCFFList(factors,leadcoeff,f.mvar(),alpha);
     246      }
     247      else
     248      {
     249        // special case : GF2
     250       
     251        // remainder is two ==> nothing to do
     252
     253        // set minimal polynomial in NTL using the optimized conversion routines for characteristic 2
     254        GF2X minPo=convertFacCF2NTLGF2X(getMipo(alpha,f.mvar()));
     255        GF2EContext c(minPo);
     256        c.restore();
     257       
     258        // convert to NTL again using the faster conversion routines
     259        GF2EX f1=to_GF2EX(convertFacCF2NTLGF2X(f));
     260       
     261        // no make monic necessary in GF2
     262       
     263        // factorize using NTL
     264        vec_pair_GF2EX_long factors;
     265        CanZass(factors,f1);
     266
     267        // return converted result
     268        return convertNTLvec_pair_GF2EX_long2FacCFFList(factors,LeadCoeff(f1),f.mvar(),alpha);
     269      }
     270     
     271    }
     272    else   
     273    #endif
     274    {
     275      return FpFactorizeUnivariateCZ( f, false, 1, alpha, Variable() );
     276    }
     277   
    132278}
    133279
     
    138284
    139285    if ( getCharacteristic() == 0 )
    140         result = sqrFreeZ( f );
     286        result = sqrFreeZ( f );
    141287    else
    142         result = sqrFreeFp( f );
     288        result = sqrFreeFp( f );
    143289
    144290    return ( sort ? sortCFFList( result ) : result );
     
    149295//    ASSERT( f.isUnivariate(), "multivariate factorization not implemented" );
    150296    if ( getCharacteristic() == 0 )
    151         return isSqrFreeZ( f );
     297        return isSqrFreeZ( f );
    152298    else
    153         return isSqrFreeFp( f );
    154 }
     299        return isSqrFreeFp( f );
     300}
     301
Note: See TracChangeset for help on using the changeset viewer.