Changeset 4a7a45 in git


Ignore:
Timestamp:
Jul 29, 2020, 5:33:12 PM (3 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'd1ba061a762c62d3a25159d8da8b6e17332291fa')
Children:
700b89d0131c4b3d214f49af1eeb67501875ec89
Parents:
4772b1b4621f2ab68acc9d2b5a568604d4d5e790
Message:
fix: factorize in Z[x,..] w/o NTL
Location:
factory
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • factory/canonicalform.cc

    r4772b1 r4a7a45  
    1515#include "cf_algorithm.h"
    1616#include "imm.h"
     17#include "int_pp.h"
    1718#include "gfops.h"
    1819#include "facMul.h"
    1920#include "facAlgFuncUtil.h"
    2021#include "FLINTconvert.h"
     22#include "cf_binom.h"
    2123
    2224#ifndef NOSTREAMIO
     
    204206}
    205207
     208
    206209CanonicalForm
    207210CanonicalForm::mapinto () const
     
    216219            else
    217220                return *this;
     221        else  if ( CFFactory::gettype() == PrimePowerDomain )
     222            return CanonicalForm( CFFactory::basic( imm2int( value ) ) );
    218223        else  if ( getGFDegree() == 1 )
    219224            return CanonicalForm( int2imm_p( ff_norm( imm2int( value ) ) ) );
     
    222227    else  if ( value->inBaseDomain() )
    223228        if ( getCharacteristic() == 0 )
    224              return *this;
     229            if ( value->levelcoeff() == PrimePowerDomain )
     230            {
     231              mpz_t d;
     232              getmpi( value,d);
     233              if ( mpz_cmp( InternalPrimePower::primepowhalf, d ) < 0 )
     234                mpz_sub( d, d, InternalPrimePower::primepow );
     235              return CFFactory::basic( d );
     236            }
     237            else
     238                return *this;
     239        else  if ( CFFactory::gettype() == PrimePowerDomain )
     240        {
     241            ASSERT( value->levelcoeff() == PrimePowerDomain || value->levelcoeff() == IntegerDomain, "no proper map defined" );
     242            if ( value->levelcoeff() == PrimePowerDomain )
     243                return *this;
     244            else
     245            {
     246              mpz_t d;
     247              getmpi(value,d);
     248              if ( mpz_cmp( InternalPrimePower::primepowhalf, d ) < 0 )
     249                mpz_sub( d, d, InternalPrimePower::primepow );
     250              return CFFactory::basic( d );
     251            }
     252        }
    225253        else
    226254        {
     
    248276    }
    249277}
    250 
    251278/** CanonicalForm CanonicalForm::lc (), Lc (), LC (), LC ( v ) const
    252279 *
     
    19351962    return cf_glob_switches.isOn( sw );
    19361963}
     1964
     1965#ifndef HAVE_NTL
     1966static int initialized=0;
     1967int
     1968initCanonicalForm( void )
     1969{
     1970  if ( ! initialized )
     1971  {
     1972    initPT();
     1973    initialized = true;
     1974  }
     1975}
     1976#endif
     1977
  • factory/canonicalform.h

    r4772b1 r4a7a45  
    404404/*ENDPUBLIC*/
    405405
     406int initCanonicalForm( void );
     407static int cf_is_initialized_now = initCanonicalForm();
    406408#endif /* ! INCL_CANONICALFORM_H */
  • factory/cf_binom.h

    r4772b1 r4a7a45  
    11/* emacs edit mode for this file is -*- C++ -*- */
     2/* $Id: cf_binom.h 12231 2009-11-02 10:12:22Z hannes $ */
    23
    34#ifndef INCL_CF_BINOM_H
    45#define INCL_CF_BINOM_H
    56
    6 // #include "config.h"
     7#include <config.h>
    78
    89#include "canonicalform.h"
  • factory/cf_factory.cc

    r4772b1 r4a7a45  
    1414#include "int_rat.h"
    1515#include "int_poly.h"
     16#include "int_pp.h"
    1617#include "imm.h"
    1718
     
    4647    case GaloisFieldDomain:
    4748        return int2imm_gf( gf_int2gf( value ) );
     49    case PrimePowerDomain:
     50        return new InternalPrimePower( value );
    4851    default: {
    4952        ASSERT( 0, "illegal basic domain!" );
     
    260263void getmpi ( InternalCF * value, mpz_t mpi)
    261264{
    262     ASSERT( ! is_imm( value ) && (value->levelcoeff() == IntegerDomain ), "illegal operation" );
     265    ASSERT( ! is_imm( value ) && (value->levelcoeff() == IntegerDomain || value->levelcoeff() == PrimePowerDomain), "illegal operation" );
    263266    mpz_init_set (mpi, ((InternalInteger*)value)->thempi);
    264267}
    265 
  • factory/cf_factory.h

    r4772b1 r4a7a45  
    2929    static void settype ( int type )
    3030    {
    31       ASSERT( type==FiniteFieldDomain || type==GaloisFieldDomain || type==IntegerDomain || type==RationalDomain, "illegal basic domain!" );
     31      ASSERT( type==FiniteFieldDomain || type==GaloisFieldDomain || type==IntegerDomain || type==RationalDomain || type==PrimePowerDomain, "illegal basic domain!" );
    3232      currenttype = type;
    3333    };
     
    4646
    4747void getmpi ( InternalCF * value, mpz_t mpi);
    48 
    4948#endif /* ! INCL_CF_FACTORY_H */
  • factory/fac_distrib.cc

    r4772b1 r4a7a45  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 
    3 
    4 #include "config.h"
    5 
    6 
    7 #include "cf_assert.h"
     2/* $Id: fac_distrib.cc 14344 2011-07-25 14:08:17Z mlee $ */
     3
     4#include <config.h>
     5
     6#include "assert.h"
    87#include "debug.h"
    98
     
    1615
    1716#ifndef HAVE_NTL
     17
    1818bool
    1919nonDivisors ( CanonicalForm omega, CanonicalForm delta, const CFArray & F, CFArray & d )
  • factory/fac_distrib.h

    r4772b1 r4a7a45  
    11/* emacs edit mode for this file is -*- C++ -*- */
     2/* $Id: fac_distrib.h 12231 2009-11-02 10:12:22Z hannes $ */
    23
    34#ifndef INCL_FAC_DISTRIB_H
    45#define INCL_FAC_DISTRIB_H
    56
    6 // #include "config.h"
     7#include <config.h>
    78
    89#include "canonicalform.h"
  • factory/fac_multihensel.cc

    r4772b1 r4a7a45  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 
    3 
    4 #include "config.h"
    5 
    6 
    7 #include "cf_assert.h"
     2/* $Id: fac_multihensel.cc 12231 2009-11-02 10:12:22Z hannes $ */
     3
     4#include <config.h>
     5
     6#include "assert.h"
    87#include "debug.h"
    98#include "timing.h"
     
    1413#include "fac_util.h"
    1514#include "fac_iterfor.h"
    16 #include "fac_multihensel.h"
    1715#include "cf_iter.h"
    1816
    1917#ifndef HAVE_NTL
    2018
    21 TIMING_DEFINE_PRINT(fac_solve)
    22 TIMING_DEFINE_PRINT(fac_modpk)
    23 TIMING_DEFINE_PRINT(fac_corrcoeff)
    24 TIMING_DEFINE_PRINT(fac_extgcd)
     19TIMING_DEFINE_PRINT(fac_solve);
     20TIMING_DEFINE_PRINT(fac_modpk);
     21TIMING_DEFINE_PRINT(fac_corrcoeff);
     22TIMING_DEFINE_PRINT(fac_extgcd);
    2523
    2624static void
    27 extgcdrest ( const CanonicalForm & a, const CanonicalForm & b, const CanonicalForm & s, const CanonicalForm & t, const CanonicalForm & c, CanonicalForm & S, CanonicalForm & T, const modpk & /*pk*/ )
     25extgcdrest ( const CanonicalForm & a, const CanonicalForm & b, const CanonicalForm & s, const CanonicalForm & t, const CanonicalForm & c, CanonicalForm & S, CanonicalForm & T, const modpk & pk )
    2826{
    2927    CanonicalForm sigma = s * c, tau = t * c;
     
    169167        A[i] = remainder( pk( a[i] * C0 ), P0[i], pk );
    170168    DEBOUTLN( cerr, "the first approximation of the correction coefficients is " << A );
    171 /*#ifdef DEBUGOUTPUT
     169#ifdef DEBUGOUTPUT
    172170    if ( check_dummy( A, P, Q ) - C != 0 )
    173171    {
     
    177175        DEBOUTLN( cerr, "              Q " << Q );
    178176    }
    179 #endif*/
     177#endif
    180178    for ( m = 0; m <= h && ( m == 0 || Dm != 0 ); m++ )
    181179    {
     
    219217        DEBOUTLN( cerr, "the correction coefficients at step " << m );
    220218        DEBOUTLN( cerr, "are now " << A );
    221 /*#ifdef DEBUGOUTPUT
     219#ifdef DEBUGOUTPUT
    222220    if ( check_dummy( A, P, Q ) - C != 0 ) {
    223221        DEBOUTLN( cerr, "there is an error detected, the correction coefficients do not" );
     
    226224        DEBOUTLN( cerr, "              Q " << Q );
    227225    }
    228 #endif*/
     226#endif
    229227    }
    230228    DEBDECLEVEL( cerr, "findCorrCoeffs" );
     
    326324
    327325bool
    328 Hensel ( const CanonicalForm & U, CFArray & G, const CFArray & lcG, const Evaluation & A, const modpk & bound, const Variable & /*x*/ )
     326Hensel ( const CanonicalForm & U, CFArray & G, const CFArray & lcG, const Evaluation & A, const modpk & bound, const Variable & x )
    329327{
    330328    DEBINCLEVEL( cerr, "Hensel" );
  • factory/fac_multivar.cc

    r4772b1 r4a7a45  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 
    3 
    4 #include "config.h"
    5 
    6 
    7 #include "cf_assert.h"
     2/* $Id: fac_multivar.cc 14377 2011-09-01 13:40:30Z mlee $ */
     3
     4#include <config.h>
     5
     6#include "assert.h"
    87#include "debug.h"
    98#include "timing.h"
     
    2120#include "fac_distrib.h"
    2221#include "fac_multihensel.h"
     22#include "facBivar.h"
    2323
    2424#ifndef HAVE_NTL
     25
    2526void out_cf(const char *s1,const CanonicalForm &f,const char *s2);
    2627void out_cff(CFFList &L);
    2728
    28 TIMING_DEFINE_PRINT(fac_content)
    29 TIMING_DEFINE_PRINT(fac_findeval)
    30 TIMING_DEFINE_PRINT(fac_distrib)
    31 TIMING_DEFINE_PRINT(fac_hensel)
     29TIMING_DEFINE_PRINT(fac_content);
     30TIMING_DEFINE_PRINT(fac_findeval);
     31TIMING_DEFINE_PRINT(fac_distrib);
     32TIMING_DEFINE_PRINT(fac_hensel);
    3233
    3334static CFArray
     
    6970
    7071static modpk
    71 coeffBound ( const CanonicalForm & f, int p )
     72coeffBound_old ( const CanonicalForm & f, int p )
    7273{
    7374    int * degs = degrees( f );
     
    148149}
    149150
    150 #ifdef HAVE_NTL
    151 VAR int prime_number=0;
     151
     152static int prime_number=0;
    152153void find_good_prime(const CanonicalForm &f, int &start)
    153154{
     
    199200  }
    200201}
    201 #endif
    202 
    203202static CFArray ZFactorizeMulti ( const CanonicalForm & arg )
    204203{
     204    prime_number=0;
     205    bool is_rat=isOn(SW_RATIONAL);
     206    Off(SW_RATIONAL);
    205207    DEBINCLEVEL( cerr, "ZFactorizeMulti" );
    206208    CFMap M;
     
    264266        G = conv_to_factor_array( factorize( U0, false ) );
    265267        DEBOUTLN( cerr, "which factorizes into " << G );
    266         #ifdef HAVE_NTL
    267268        {
    268269          int i=prime_number;
     
    279280          else if (((i==0)||(i!=prime_number)))
    280281          {
    281             b = coeffBound( U, p );
     282            b = coeffBound_old( U, p );
    282283            prime_number=i;
    283284          }
    284285          // p!=0:
    285           modpk bb=coeffBound(U0,p);
     286          modpk bb=coeffBound_old(U0,p);
    286287          if (bb.getk() > b.getk() ) b=bb;
    287           bb=coeffBound(arg,p);
     288          bb=coeffBound_old(arg,p);
    288289          if (bb.getk() > b.getk() ) b=bb;
    289290        }
    290         #else
    291         b = coeffBound( U, getZFacModulus().getp() );
    292291        if ( getZFacModulus().getpk() > b.getpk() )
    293292            b = getZFacModulus();
    294         #endif
    295293        //printf("p=%d, k=%d\n",b.getp(),b.getk());
    296294        DEBOUTLN( cerr, "the coefficient bound of the factors of U is " << b.getpk() );
     
    342340        G[1] = -G[1];
    343341    DEBDECLEVEL( cerr, "ZFactorMulti" );
     342    if(is_rat) On(SW_RATIONAL);
    344343    return G;
    345344}
     
    364363    {
    365364        if ( i.getItem().factor().inCoeffDomain() )
    366             R.append( CFFactor( i.getItem().factor(), i.getItem().exp() ) );
     365        {
     366            if ( ! i.getItem().factor().isOne() )
     367                R.append( CFFactor( i.getItem().factor(), i.getItem().exp() ) );
     368        }
    367369        else
    368370        {
  • factory/fac_multivar.h

    r4772b1 r4a7a45  
    11/* emacs edit mode for this file is -*- C++ -*- */
     2/* $Id: fac_multivar.h 12231 2009-11-02 10:12:22Z hannes $ */
    23
    34#ifndef INCL_FAC_MULTIVAR_H
    45#define INCL_FAC_MULTIVAR_H
    56
    6 // #include "config.h"
     7#include <config.h>
    78
    89#include "canonicalform.h"
  • factory/int_pp.h

    r4772b1 r4a7a45  
    3030    STATIC_VAR int prime;
    3131    STATIC_VAR int exp;
     32    static void initialize();
     33public:
     34    mpz_ptr MPI( const InternalCF * const c );
    3235    STATIC_VAR mpz_t primepow;
    3336    STATIC_VAR mpz_t primepowhalf;
    34     static void initialize();
    35     static mpz_ptr MPI( const InternalCF * const c );
    36 public:
    3737    InternalPrimePower();
    3838    InternalPrimePower( const InternalCF& )
     
    9191
    9292    int sign() const;
    93     friend mpz_ptr getmpi ( InternalCF * value, bool symmetric );
     93    friend void getmpi ( InternalCF * value, mpz_t );
    9494};
    9595
Note: See TracChangeset for help on using the changeset viewer.