Changeset 564dd8 in git for factory/fac_util.cc


Ignore:
Timestamp:
Jul 29, 2020, 10:00:14 AM (4 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '2a584933abf2a2d3082034c7586d38bb6de1a30a')
Children:
f792337caec744ea4c10bf8d9214d7ae5e8acdcc
Parents:
8f5493aaf9a2f74965b580f83ebef852516cb86b
git-author:
Hans Schoenemann <hannes@mathematik.uni-kl.de>2020-07-29 10:00:14+02:00
git-committer:
Hans Schoenemann <hannes@mathematik.uni-kl.de>2020-07-29 10:42:27+02:00
Message:
factorize in Z[x,..] w/o NTL
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/fac_util.cc

    r8f5493 r564dd8  
    1111#include "cf_iter.h"
    1212#include "fac_util.h"
     13#include "cfUnivarGcd.h"
    1314
    1415STATIC_INST_VAR CanonicalForm PK, PKHALF;
     
    111112}
    112113
     114CanonicalForm
     115remainder( const CanonicalForm & f, const CanonicalForm & g, const modpk & pk )
     116{
     117    ASSERT( (f.inCoeffDomain() || f.isUnivariate()) && (g.inCoeffDomain() || g.isUnivariate()) && (f.inCoeffDomain() || g.inCoeffDomain() || f.mvar() == g.mvar()), "can not build remainder" );
     118    if ( f.inCoeffDomain() )
     119        if ( g.inCoeffDomain() )
     120            return pk( f % g );
     121        else
     122            return pk( f );
     123    else {
     124        Variable x = f.mvar();
     125        CanonicalForm result = f;
     126        int degg = g.degree();
     127        CanonicalForm invlcg = pk.inverse( g.lc() );
     128        CanonicalForm gg = pk( g*invlcg );
     129        if((gg.lc().isOne()))
     130        {
     131          while ( result.degree() >= degg )
     132          {
     133            result -= pk(lc( result ) * gg) * power( x, result.degree() - degg );
     134            result=pk(result);
     135          }
     136        }
     137        else
     138        // no inverse found
     139        {
     140          CanonicalForm ic=icontent(g);
     141          if (!ic.isOne())
     142          {
     143            gg=g/ic;
     144            return remainder(f,gg,pk);
     145          }
     146          while ( result.degree() >= degg )
     147          {
     148            if (gg.lc().isZero()) return result;
     149            CanonicalForm lcgf = result.lc() / gg.lc();
     150            if (lcgf.inZ())
     151              gg = pk( g*lcgf );
     152            else
     153            {
     154              //printf("!\n\n");
     155              return result;
     156            }
     157            result -=  gg * power( x, result.degree() - degg );
     158            result=pk(result);
     159          }
     160        }
     161        return result;
     162    }
     163}
     164
     165CanonicalForm
     166prod ( const CFArray & a, int f, int l )
     167{
     168    if ( f < a.min() ) f = a.min();
     169    if ( l > a.max() ) l = a.max();
     170    CanonicalForm p = 1;
     171    for ( int i = f; i <= l; i++ )
     172        p *= a[i];
     173    return p;
     174}
     175
     176CanonicalForm
     177prod ( const CFArray & a )
     178{
     179    return prod( a, a.min(), a.max() );
     180}   
     181
     182void
     183extgcd ( const CanonicalForm & a, const CanonicalForm & b, CanonicalForm & S, CanonicalForm & T, const modpk & pk )
     184{
     185    int p = pk.getp(), k = pk.getk(), j;
     186    CanonicalForm amodp, bmodp, smodp, tmodp, s, t, sigma, tau, e;
     187    CanonicalForm modulus = p, sigmat, taut, q;
     188
     189    setCharacteristic( p );
     190    {
     191        amodp = mapinto( a ); bmodp = mapinto( b );
     192        (void)extgcd( amodp, bmodp, smodp, tmodp );
     193    }
     194    setCharacteristic( 0 );
     195    s = mapinto( smodp ); t = mapinto( tmodp );
     196
     197    for ( j = 1; j < k; j++ ) {
     198        e = ( 1 - s * a - t * b ) / modulus;
     199        setCharacteristic( p );
     200        {
     201            e = mapinto( e );
     202            sigmat = smodp * e;
     203            taut = tmodp * e;
     204            divrem( sigmat, bmodp, q, sigma );
     205            tau = taut + q * amodp;
     206        }
     207        setCharacteristic( 0 );
     208        s += mapinto( sigma ) * modulus;
     209        t += mapinto( tau ) * modulus;
     210        modulus *= p;
     211    }
     212    S = s; T = t;
     213}
Note: See TracChangeset for help on using the changeset viewer.