Changeset 48e0bcb in git


Ignore:
Timestamp:
Jun 17, 2020, 3:34:43 PM (3 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '8d54773d6c9e2f1d2593a28bc68b7eeab54ed529')
Children:
e4514d3151a5c53437b9fa2f30bda8febfd87539ed6f2bb0876535189130e32d71be46f776012a36
Parents:
95e373294f19817a4516238a9d8dd18b1a626ab9
Message:
seperate NTL and FLINT: nulNTL and factorize
Location:
factory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • factory/cf_factor.cc

    r95e3732 r48e0bcb  
    434434    if (f.isUnivariate())
    435435    {
     436#ifdef HAVE_FLINT
    436437#ifdef HAVE_NTL
    437 #ifdef HAVE_FLINT
    438438      if (degree (f) < 300)
    439       {
     439#endif
     440      {
     441        // use FLINT
    440442        nmod_poly_t f1;
    441443        convertFacCF2nmod_poly_t (f1, f);
     
    446448        nmod_poly_factor_clear (result);
    447449        nmod_poly_clear (f1);
    448       }
    449       else
    450 #endif
    451       {
    452         // USE NTL
    453         if (getCharacteristic()!=2)
    454         {
    455           if (fac_NTL_char != getCharacteristic())
    456           {
    457             fac_NTL_char = getCharacteristic();
    458             zz_p::init(getCharacteristic());
    459           }
    460 
    461           // convert to NTL
    462           zz_pX f1=convertFacCF2NTLzzpX(f);
    463           zz_p leadcoeff = LeadCoeff(f1);
    464 
    465           //make monic
    466           f1=f1 / LeadCoeff(f1);
    467           // factorize
    468           vec_pair_zz_pX_long factors;
    469           CanZass(factors,f1);
    470 
    471           F=convertNTLvec_pair_zzpX_long2FacCFFList(factors,leadcoeff,f.mvar());
    472           //test_cff(F,f);
    473         }
    474         else /*getCharacteristic()==2*/
     450        if(isOn(SW_USE_NTL_SORT)) F.sort(cmpCF);
     451        return F;
     452      }
     453#endif
     454#ifdef HAVE_NTL
     455      {
     456        if (getCharacteristic()==2)
    475457        {
    476458          // Specialcase characteristic==2
     
    489471          // convert back to factory again using the faster conversion routine for vectors over GF2X
    490472          F=convertNTLvec_pair_GF2X_long2FacCFFList(factors,LeadCoeff(f1),f.mvar());
     473          if(isOn(SW_USE_NTL_SORT)) F.sort(cmpCF);
     474          return F;
    491475        }
    492476      }
    493 #else
     477#endif
     478#ifdef HAVE_NTL
     479      {
     480        // USE NTL
     481        if (fac_NTL_char != getCharacteristic())
     482        {
     483          fac_NTL_char = getCharacteristic();
     484          zz_p::init(getCharacteristic());
     485        }
     486
     487        // convert to NTL
     488        zz_pX f1=convertFacCF2NTLzzpX(f);
     489        zz_p leadcoeff = LeadCoeff(f1);
     490
     491        //make monic
     492        f1=f1 / LeadCoeff(f1);
     493        // factorize
     494        vec_pair_zz_pX_long factors;
     495        CanZass(factors,f1);
     496
     497        F=convertNTLvec_pair_zzpX_long2FacCFFList(factors,leadcoeff,f.mvar());
     498        //test_cff(F,f);
     499        if(isOn(SW_USE_NTL_SORT)) F.sort(cmpCF);
     500        return F;
     501      }
     502#endif
     503#if !defined(HAVE_NTL) && !defined(HAVE_FLINT)
    494504      // Use Factory without NTL
    495       factoryError ("univariate factorization depends on NTL(missing)");
     505      factoryError ("univariate factorization depends on FLINT/NTL(missing)");
    496506      return CFFList (CFFactor (f, 1));
    497 #endif //HAVE_NTL
    498     }
    499     else
    500     {
    501       #ifdef HAVE_NTL
     507#endif
     508    }
     509    else
     510    {
     511      #if defined(HAVE_NTL) || defined(HAVE_FLINT)
    502512      if (issqrfree)
    503513      {
     
    520530      }
    521531      #else
    522       ASSERT( f.isUnivariate(), "multivariate factorization depends on NTL(missing)" );
    523       factoryError ("multivariate factorization depends on NTL(missing)");
     532      ASSERT( f.isUnivariate(), "multivariate factorization depends on FLINT/NTL(missing)" );
     533      factoryError ("multivariate factorization depends on FLINT/NTL(missing)");
    524534      return CFFList (CFFactor (f, 1));
    525535      #endif
     
    572582    else
    573583    {
    574       #ifdef HAVE_NTL
    575584      On (SW_RATIONAL);
    576585      if (issqrfree)
     
    584593        F = ratFactorize (fz);
    585594      Off (SW_RATIONAL);
    586       #else
    587       factoryError ("multivariate factorization  depends on NTL(missing)");
    588       return CFFList (CFFactor (f, 1));
    589       #endif
    590595    }
    591596
     
    607612  }
    608613
    609   //out_cff(F);
    610614  if(isOn(SW_USE_NTL_SORT)) F.sort(cmpCF);
    611615  return F;
     
    633637  if (ch>0)
    634638  {
    635     if (f.isUnivariate()&& (ch>0))
     639    if (f.isUnivariate())
    636640    {
    637641#ifdef HAVE_NTL
    638       //USE NTL
    639       if (ch>2)
    640       {
    641 #if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
    642         nmod_poly_t FLINTmipo, leadingCoeff;
    643         fq_nmod_ctx_t fq_con;
    644 
    645         nmod_poly_init (FLINTmipo, getCharacteristic());
    646         nmod_poly_init (leadingCoeff, getCharacteristic());
    647         convertFacCF2nmod_poly_t (FLINTmipo, getMipo (alpha));
    648 
    649         fq_nmod_ctx_init_modulus (fq_con, FLINTmipo, "Z");
    650         fq_nmod_poly_t FLINTF;
    651         convertFacCF2Fq_nmod_poly_t (FLINTF, f, fq_con);
    652         fq_nmod_poly_factor_t res;
    653         fq_nmod_poly_factor_init (res, fq_con);
    654         fq_nmod_poly_factor (res, leadingCoeff, FLINTF, fq_con);
    655         F= convertFLINTFq_nmod_poly_factor2FacCFFList (res, f.mvar(), alpha, fq_con);
    656         F.insert (CFFactor (Lc (f), 1));
    657 
    658         fq_nmod_poly_factor_clear (res, fq_con);
    659         fq_nmod_poly_clear (FLINTF, fq_con);
    660         nmod_poly_clear (FLINTmipo);
    661         nmod_poly_clear (leadingCoeff);
    662         fq_nmod_ctx_clear (fq_con);
    663 #else
    664         // First all cases with characteristic !=2
    665         // set remainder
    666         if (fac_NTL_char != getCharacteristic())
    667         {
    668           fac_NTL_char = getCharacteristic();
    669           zz_p::init(getCharacteristic());
    670         }
    671 
    672         // set minimal polynomial in NTL
    673         zz_pX minPo=convertFacCF2NTLzzpX(getMipo(alpha));
    674         zz_pE::init (minPo);
    675 
    676         // convert to NTL
    677         zz_pEX f1=convertFacCF2NTLzz_pEX(f,minPo);
    678         zz_pE leadcoeff= LeadCoeff(f1);
    679 
    680         //make monic
    681         f1=f1 / leadcoeff;
    682 
    683         // factorize using NTL
    684         vec_pair_zz_pEX_long factors;
    685         CanZass(factors,f1);
    686 
    687         // return converted result
    688         F=convertNTLvec_pair_zzpEX_long2FacCFFList(factors,leadcoeff,f.mvar(),alpha);
    689 #endif
    690       }
    691       else if (/*getCharacteristic()*/ch==2)
     642      if (/*getCharacteristic()*/ch==2)
    692643      {
    693644        // special case : GF2
     
    719670        // return converted result
    720671        F=convertNTLvec_pair_GF2EX_long2FacCFFList(factors,f1_coef,f.mvar(),alpha);
    721       }
    722 #else
     672        if(isOn(SW_USE_NTL_SORT)) F.sort(cmpCF);
     673        return F;
     674      }
     675#endif
     676#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
     677      {
     678        // use FLINT
     679        nmod_poly_t FLINTmipo, leadingCoeff;
     680        fq_nmod_ctx_t fq_con;
     681
     682        nmod_poly_init (FLINTmipo, getCharacteristic());
     683        nmod_poly_init (leadingCoeff, getCharacteristic());
     684        convertFacCF2nmod_poly_t (FLINTmipo, getMipo (alpha));
     685
     686        fq_nmod_ctx_init_modulus (fq_con, FLINTmipo, "Z");
     687        fq_nmod_poly_t FLINTF;
     688        convertFacCF2Fq_nmod_poly_t (FLINTF, f, fq_con);
     689        fq_nmod_poly_factor_t res;
     690        fq_nmod_poly_factor_init (res, fq_con);
     691        fq_nmod_poly_factor (res, leadingCoeff, FLINTF, fq_con);
     692        F= convertFLINTFq_nmod_poly_factor2FacCFFList (res, f.mvar(), alpha, fq_con);
     693        F.insert (CFFactor (Lc (f), 1));
     694
     695        fq_nmod_poly_factor_clear (res, fq_con);
     696        fq_nmod_poly_clear (FLINTF, fq_con);
     697        nmod_poly_clear (FLINTmipo);
     698        nmod_poly_clear (leadingCoeff);
     699        fq_nmod_ctx_clear (fq_con);
     700        if(isOn(SW_USE_NTL_SORT)) F.sort(cmpCF);
     701        return F;
     702      }
     703#endif
     704#ifdef HAVE_NTL
     705      {
     706        // use NTL
     707        if (fac_NTL_char != getCharacteristic())
     708        {
     709          fac_NTL_char = getCharacteristic();
     710          zz_p::init(getCharacteristic());
     711        }
     712
     713        // convert to NTL
     714        zz_pX f1=convertFacCF2NTLzzpX(f);
     715        zz_p leadcoeff = LeadCoeff(f1);
     716
     717        //make monic
     718        f1=f1 / LeadCoeff(f1);
     719        // factorize
     720        vec_pair_zz_pX_long factors;
     721        CanZass(factors,f1);
     722
     723        F=convertNTLvec_pair_zzpX_long2FacCFFList(factors,leadcoeff,f.mvar());
     724        //test_cff(F,f);
     725        if(isOn(SW_USE_NTL_SORT)) F.sort(cmpCF);
     726        return F;
     727      }
     728#endif
     729#if !defined(HAVE_NTL) && !defined(HAVEFLINT)
    723730      factoryError ("univariate factorization  depends on NTL(missing)");
    724731      return CFFList (CFFactor (f, 1));
     
    727734    else
    728735    {
    729 #ifdef HAVE_NTL
    730736      F= FqFactorize (f, alpha);
    731 #else
    732       ASSERT( f.isUnivariate(), "multivariate factorization depends on NTL(missing)" );
    733       factoryError ("multivariate factorization  depends on NTL(missing)");
    734       return CFFList (CFFactor (f, 1));
    735 #endif
    736737    }
    737738  }
     
    744745    else //Q(a)[x1,...,xn]
    745746    {
    746 #ifdef HAVE_NTL
    747747      F= ratFactorize (f, alpha);
    748 #else
    749       ASSERT( f.isUnivariate(), "multivariate factorization  depends on NTL(missing)" );
    750       factoryError ("multivariate factorization  depends on NTL(missing)");
    751       return CFFList (CFFactor (f, 1));
    752 #endif
    753748    }
    754749  }
  • factory/facMul.cc

    r95e3732 r48e0bcb  
    3232#include <NTL/lzz_pEX.h>
    3333#include "NTLconvert.h"
     34#endif
    3435
    3536#ifdef HAVE_FLINT
     
    452453        fq_ctx_clear (fq_con);
    453454        return b (result);
    454 #else
     455#endif
     456#ifdef HAVE_NTL
    455457        ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
    456458        ZZ_pX NTLmipo= to_ZZ_pX (convertFacCF2NTLZZX (mipo));
     
    489491      }
    490492      return mulFLINTQ (F, G);
    491 #else
     493#endif
     494#ifdef HAVE_NTL
    492495      if (b.getp() != 0)
    493496      {
     
    569572
    570573          return b (result);
    571 #else
     574#endif
     575#ifdef HAVE_NTL
    572576          ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
    573577          ZZ_pX NTLmipo= to_ZZ_pX (convertFacCF2NTLZZX (getMipo (alpha)));
     
    607611  ASSERT (F.isUnivariate() && G.isUnivariate(), "expected univariate polys");
    608612  ASSERT (F.level() == G.level(), "expected polys of same level");
     613#ifdef HAVE_NTL
    609614#if (!defined(HAVE_FLINT) ||  __FLINT_RELEASE < 20400)
    610615  if (fac_NTL_char != getCharacteristic())
     
    613618    zz_p::init (getCharacteristic());
    614619  }
     620#endif
    615621#endif
    616622  Variable alpha;
     
    646652    nmod_poly_clear (FLINTmipo);
    647653    fq_nmod_ctx_clear (fq_con);
    648 #else
     654    return result;
     655#elif defined(AHVE_NTL)
    649656    zz_pX NTLMipo= convertFacCF2NTLzzpX (getMipo (alpha));
    650657    zz_pE::init (NTLMipo);
     
    653660    mul (NTLF, NTLF, NTLG);
    654661    result= convertNTLzz_pEX2CF(NTLF, F.mvar(), alpha);
     662    return result;
    655663#endif
    656664  }
     
    665673    nmod_poly_clear (FLINTF);
    666674    nmod_poly_clear (FLINTG);
    667 #else
     675    return result;
     676#endif
     677#ifdef HAVE_NTL
    668678    zz_pX NTLF= convertFacCF2NTLzzpX (F);
    669679    zz_pX NTLG= convertFacCF2NTLzzpX (G);
    670680    mul (NTLF, NTLF, NTLG);
    671     result= convertNTLzzpX2CF(NTLF, F.mvar());
    672 #endif
    673   }
    674   return result;
     681    return convertNTLzzpX2CF(NTLF, F.mvar());
     682#endif
     683  }
     684  return F*G;
    675685}
    676686
     
    37353745// end division
    37363746
    3737 #endif
Note: See TracChangeset for help on using the changeset viewer.