Changeset 146c603 in git


Ignore:
Timestamp:
Nov 9, 2011, 10:13:02 AM (12 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'c5facdfddea2addfd91babd8b9019161dea4b695')
Children:
8f40312428677d88ab37a31824f2ec53f144a18a
Parents:
fc497757365979d0168460de9969b49bc49c53f2
git-author:
Hans Schoenemann <hannes@mathematik.uni-kl.de>2011-11-09 10:13:02+01:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 16:14:12+01:00
Message:
fix: nlModP (should not use nvDiv/npDiv
implement conversion to/from factory for algext
Location:
libpolys
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libpolys/coeffs/longrat.cc

    rfc4977 r146c603  
    12681268  {
    12691269    int in=mpz_fdiv_ui(n->n,(unsigned long)p);
    1270     #ifdef NV_OPS
    1271     if (p>NV_MAX_PRIME)
    1272     return (int)((long)nvDiv((number)iz,(number)in,(const coeffs)r));
    1273     #endif
    1274     return (int)((long)npDiv((number)iz,(number)in,(const coeffs)r));
     1270    long  s, t;
     1271
     1272    long  u, v, u0, v0, u1, v1, u2, v2, q, r;
     1273
     1274     u1=1; v1=0;
     1275     u2=0; v2=1;
     1276     u = in; v = p;
     1277
     1278     while (v != 0)
     1279     {
     1280        q = u / v;
     1281        r = u % v;
     1282        u = v;
     1283        v = r;
     1284        u0 = u2;
     1285        v0 = v2;
     1286        u2 =  u1 - q*u2;
     1287        v2 = v1- q*v2;
     1288        u1 = u0;
     1289        v1 = v0;
     1290     }
     1291
     1292     s = u1;
     1293     if (s < 0) s+=p;
     1294     u=(s*((long)iz)) % ((long)p);
     1295     return (int)u;
    12751296  }
    12761297  return iz;
  • libpolys/polys/clapconv.cc

    rfc4977 r146c603  
    2626
    2727static void conv_RecPP ( const CanonicalForm & f, int * exp, sBucket_pt result, ring r );
    28 
    29 static void convRecTrP ( const CanonicalForm & f, int * exp, poly & result, int offs, const ring r );
    30 
    31 static void convRecGFGF ( const CanonicalForm & f, int * exp, poly & result );
    3228
    3329static number convFactoryNSingAN( const CanonicalForm &f, const ring r);
     
    105101}
    106102
    107 int convFactoryISingI( const CanonicalForm & f)
    108 {
    109   if (!f.isImm()) WerrorS("int overflow in det");
    110   return f.intval();
    111 }
    112 #if 0
    113 CanonicalForm convSingAPFactoryAP ( poly p , const Variable & a, const ring r)
     103CanonicalForm convSingAFactoryA( number pp, Variable a, const coeffs cf )
    114104{
    115105  CanonicalForm result = 0;
    116   int e, n = pVariables;
    117   int off=rPar(currRing);
     106  int e;
     107  poly p=(poly)pp;
     108  BOOLEAN setChar=TRUE;
    118109
    119   On(SW_RATIONAL);
    120   while ( p!=NULL)
     110  while ( p!=NULL )
    121111  {
    122     CanonicalForm term=convSingAFactoryA(((lnumber)pGetCoeff(p))->z,a, r);
    123     for ( int i = 1; i <= n; i++ )
    124     {
    125       if ( (e = pGetExp( p, i )) != 0 )
    126         term *= power( Variable( i + off), e );
    127     }
     112    CanonicalForm term;
     113    term=cf->extRing->cf->convSingNFactoryN(pGetCoeff( p ),setChar, cf->extRing->cf);
     114    if (errorreported) break;
     115    setChar=FALSE;
     116    if ( (e = p_GetExp( p, 1, cf->extRing)) != 0 )
     117        term *= power( a, e );
    128118    result += term;
    129119    pIter( p );
     
    132122}
    133123
    134 static void
    135 convRecAP_R ( const CanonicalForm & f, int * exp, poly & result, int par_start, int var_start, const ring r) ;
    136 
    137 poly convFactoryAPSingAP_R ( const CanonicalForm & f, int par_start, int var_start, const ring r )
    138 {
    139   int n = rVar(r)+rPar(r)+1;
    140   int * exp = (int *)omAlloc0(n*sizeof(int));
    141   poly result = NULL;
    142   convRecAP_R( f, exp, result,par_start, var_start, r );
    143   omFreeSize((ADDRESS)exp,n*sizeof(int));
    144   return result;
    145 }
    146 
    147 poly convFactoryAPSingAP ( const CanonicalForm & f, const ring r )
    148 {
    149   return convFactoryAPSingAP_R(f,0,rPar(r),r);
    150 }
    151 
    152 static void convRecAP_R ( const CanonicalForm & f, int * exp, poly & result, int par_start, int var_start, const ring r )
    153 {
    154   if (f.isZero())
    155     return;
    156   if ( ! f.inCoeffDomain() )
    157   {
    158     int l = f.level();
    159     for ( CFIterator i = f; i.hasTerms(); i++ )
    160     {
    161       exp[l] = i.exp();
    162       convRecAP_R( i.coeff(), exp, result, par_start, var_start, r);
    163     }
    164     exp[l] = 0;
    165   }
    166   else
    167   {
    168     poly z=(poly)convFactoryASingA( f,r );
    169     if (z!=NULL)
    170     {
    171       poly term = p_Init(r);
    172       pNext( term ) = NULL;
    173       int i;
    174       for ( i = rVar(r); i>0 ; i-- )
    175         p_SetExp( term, i , exp[i+var_start],r);
    176       //if (rRing_has_Comp(currRing->extRing)) p_SetComp(term, 0, currRing->extRing); // done by pInit
    177       if (par_start==0)
    178       {
    179         for ( i = 1; i <= var_start; i++ )
    180         //z->e[i-1]+=exp[i];
    181           p_AddExp(z,i,exp[i],r->extRing);
    182       }
    183       else
    184       {
    185         for ( i = par_start+1; i <= var_start+rPar(currRing); i++ )
    186         //z->e[i-1]+=exp[i];
    187           p_AddExp(z,i,exp[i-par_start],r->extRing);
    188       }
    189       pGetCoeff(term)=(number)ALLOC0_LNUMBER();
    190       ((lnumber)pGetCoeff(term))->z=z;
    191       p_Setm( term,r );
    192       result = p_Add_q( result, term, r );
    193     }
    194   }
    195 }
    196 
    197 CanonicalForm convSingAFactoryA ( poly p , const Variable & a, const ring r )
    198 {
    199   CanonicalForm result = 0;
    200   int e;
    201 
    202   while ( p!=NULL )
    203   {
    204     CanonicalForm term;
    205     /* does only work for finite fields:Z/p */
    206     if ( rField_is_Zp_a() )
    207     {
    208       term = npInt( napGetCoeff( p ),r );
    209     }
    210     else
    211     {
    212       if ( SR_HDL(napGetCoeff( p )) & SR_INT )
    213         term = SR_TO_INT(napGetCoeff( p )) ;
    214       else
    215       {
    216         if ( napGetCoeff( p )->s == 3 )
    217         {
    218           lint dummy;
    219           mpz_init_set( &dummy, (napGetCoeff( p )->z) );
    220           term = make_cf( dummy );
    221         }
    222         else
    223         {
    224           // assume s==0 or s==1
    225           lint num, den;
    226           On(SW_RATIONAL);
    227           mpz_init_set( &num, (napGetCoeff( p )->z) );
    228           mpz_init_set( &den, (napGetCoeff( p )->n) );
    229           term = make_cf( num, den, ( napGetCoeff( p )->s != 1 ));
    230         }
    231       }
    232     }
    233     if ( (e = p_GetExp( p, 1, r->extRing )) != 0 )
    234       term *= power( a , e );
    235     result += term;
    236     p = pNext( p );
    237   }
    238   return result;
    239 }
    240 
    241 static number convFactoryNSingAN( const CanonicalForm &f, const ring r)
    242 {
    243   if ( f.isImm() )
    244     return n_Init( f.intval(), r->extRing );
    245   else
    246   {
    247     number z=ALLOC_RNUMBER();
    248 #if defined(LDEBUG)
    249     z->debug=123456;
    250 #endif
    251     gmp_numerator( f, z->z );
    252     if ( f.den().isOne() )
    253     {
    254       z->s = 3;
    255     }
    256     else
    257     {
    258       gmp_denominator( f, z->n );
    259       z->s = 0;
    260       nlNormalize(z);
    261     }
    262     #ifdef LDEBUG
    263     nlDBTest(z,__FILE__,__LINE__);
    264     #endif
    265     return z;
    266   }
    267 }
    268 
    269 poly convFactoryASingA ( const CanonicalForm & f, const ring r )
     124number convFactoryASingA ( const CanonicalForm & f, const coeffs cf )
    270125{
    271126  poly a=NULL;
     
    273128  for( CFIterator i=f; i.hasTerms(); i++)
    274129  {
    275     t=napNew();
     130    t=p_New(cf->extRing);
    276131    // pNext( t ) = NULL; //already done by napNew
    277     pGetCoeff(t)=convFactoryNSingAN( i.coeff(), r );
    278     if (n_IsZero(napGetCoeff(t),r->extRing))
     132    pGetCoeff(t)=cf->extRing->cf->convFactoryNSingN( i.coeff(), cf->extRing->cf );
     133    if (n_IsZero(p_GetCoeff(t,cf->extRing),cf->extRing->cf))
    279134    {
    280       p_Delete(&t,r->extRing);
     135      p_Delete(&t,cf->extRing);
    281136    }
    282137    else
    283138    {
    284       p_SetExp(t,1,i.exp(),r->extRing);
    285       a=p_Add_q(a,t,r->extRing);
     139      p_SetExp(t,1,i.exp(),cf->extRing);
     140      a=p_Add_q(a,t,cf->extRing);
    286141    }
    287142  }
    288   if (a!=NULL)
    289   {
    290     if (r->minpoly!=NULL)
    291     {
    292       lnumber l=(lnumber)r->minpoly;
    293       if (p_GetExp(a,1,r->extRing) >= p_GetExp(l->z,1,r->extRing))
    294         a = napRemainder( a, l->z);
    295     }
    296   }
    297   return a;
     143  number aa=(number)a;
     144  n_Normalize(aa,cf);
     145  return aa;
    298146}
    299147
    300 CanonicalForm convSingTrPFactoryP ( poly p, const ring r )
     148
     149int convFactoryISingI( const CanonicalForm & f)
    301150{
    302   CanonicalForm result = 0;
    303   int e, n = rVar(r);
    304   int offs = rPar(r);
    305 
    306   while ( p!=NULL )
    307   {
    308     n_Normalize(pGetCoeff(p),r);
    309     CanonicalForm term=convSingPFactoryP(((lnumber)pGetCoeff(p))->z,r->extRing);
    310 
    311     if ((((lnumber)pGetCoeff(p))->n!=NULL)
    312     && (!errorreported))
    313     {
    314       WerrorS("conversion error: denominator!= 1");
    315     }
    316 
    317     for ( int i = n; i > 0; i-- )
    318     {
    319       if ( (e = p_GetExp( p, i,r )) != 0 )
    320         term = term * power( Variable( i + offs ), e );
    321     }
    322     result += term;
    323     p = pNext( p );
    324   }
    325   return result;
     151  if (!f.isImm()) WerrorS("int overflow in det");
     152  return f.intval();
    326153}
    327 
    328 poly convFactoryPSingTrP ( const CanonicalForm & f, const ring r )
    329 {
    330   int n = rVar(r)+1;
    331   int * exp = (int*)omAlloc0(n*sizeof(int));
    332   poly result = NULL;
    333   convRecTrP( f, exp, result , rPar(r), r );
    334   omFreeSize((ADDRESS)exp,n*sizeof(int));
    335   return result;
    336 }
    337 
    338 static void
    339 convRecTrP ( const CanonicalForm & f, int * exp, poly & result , int offs, const ring r)
    340 {
    341   if (f.isZero())
    342     return;
    343   if ( f.level() > offs )
    344   {
    345     int l = f.level();
    346     for ( CFIterator i = f; i.hasTerms(); i++ )
    347     {
    348       exp[l-offs] = i.exp();
    349       convRecTrP( i.coeff(), exp, result, offs, r );
    350     }
    351     exp[l-offs] = 0;
    352   }
    353   else
    354   {
    355     poly term = p_Init(r);
    356     pNext( term ) = NULL;
    357     for ( int i = rVar(r); i>0; i-- )
    358       p_SetExp( term, i ,exp[i], r);
    359     //if (rRing_has_Comp(currRing)) p_SetComp(term, 0, currRing); // done by pInit
    360     pGetCoeff(term) = ALLOC0_RNUMBER(); // Q!?
    361     ((lnumber)pGetCoeff(term))->z=convFactoryPSingP( f, r->extRing );
    362     p_Setm( term,r );
    363     result = p_Add_q( result, term,r );
    364   }
    365 }
    366 
    367 number   nlChineseRemainder(number *x, number *q,int rl)
    368 // elemenst in the array are x[0..(rl-1)], q[0..(rl-1)]
    369 {
    370 #ifdef HAVE_FACTORY
    371   setCharacteristic( 0 ); // only in char 0
    372   CFArray X(rl), Q(rl);
    373   int i;
    374   for(i=rl-1;i>=0;i--)
    375   {
    376     X[i]=convSingNFactoryN(x[i],NULL); // may be larger MAX_INT
    377     Q[i]=convSingNFactoryN(q[i],NULL); // may be larger MAX_INT
    378   }
    379   CanonicalForm xnew,qnew;
    380   chineseRemainder(X,Q,xnew,qnew);
    381   number n=convFactoryNSingN(xnew,NULL);
    382   number p=convFactoryNSingN(qnew,NULL);
    383   number p2=nlIntDiv(p,nlInit(2, NULL));
    384   if (nlGreater(n,p2))
    385   {
    386      number n2=nlSub(n,p);
    387      nlDelete(&n,NULL);
    388      n=n2;
    389   }
    390   nlDelete(&p,NULL);
    391   nlDelete(&p2,NULL);
    392   return n;
    393 #else
    394   WerrorS("not implemented");
    395   return nlInit(0);
    396154#endif
    397 }
    398 
    399 CanonicalForm
    400 convSingGFFactoryGF( poly p )
    401 {
    402   CanonicalForm result=CanonicalForm(0);
    403   int e, n = pVariables;
    404 
    405   while ( p != NULL )
    406   {
    407     CanonicalForm term;
    408     term = make_cf_from_gf( (int)(long)pGetCoeff( p ) );
    409     //int * A=(int *)&term;
    410     //Print("term=%x, == 0 ?: %d\n",*A, term.isZero());
    411     for ( int i = 1; i <= n; i++ )
    412     {
    413       if ( (e = pGetExp( p, i )) != 0 )
    414          term *= power( Variable( i ), e );
    415     }
    416     result += term;
    417     p = pNext( p );
    418   }
    419   return result;
    420 }
    421 
    422 poly
    423 convFactoryGFSingGF ( const CanonicalForm & f )
    424 {
    425 //    cerr << " f = " << f << endl;
    426   int n = pVariables+1;
    427   /* ASSERT( level( f ) <= pVariables, "illegal number of variables" ); */
    428   int * exp = (int*)omAlloc0(n*sizeof(int));
    429   poly result = NULL;
    430   convRecGFGF( f, exp, result );
    431   omFreeSize((ADDRESS)exp,n*sizeof(int));
    432   return result;
    433 }
    434 
    435 static void
    436 convRecGFGF ( const CanonicalForm & f, int * exp, poly & result )
    437 {
    438   if (f.isZero())
    439     return;
    440   if ( ! f.inCoeffDomain() )
    441   {
    442     int l = f.level();
    443     for ( CFIterator i = f; i.hasTerms(); i++ )
    444     {
    445       exp[l] = i.exp();
    446       convRecGFGF( i.coeff(), exp, result );
    447     }
    448     exp[l] = 0;
    449   }
    450   else
    451   {
    452     poly term = pInit();
    453     pNext( term ) = NULL;
    454     for ( int i = 1; i <= pVariables; i++ )
    455       pSetExp( term, i, exp[i]);
    456     //if (rRing_has_Comp(currRing)) p_SetComp(term, 0, currRing); // done by pInit
    457     pGetCoeff( term ) = (number) gf_value (f);
    458     pSetm( term );
    459     result = pAdd( result, term );
    460   }
    461 }
    462 
    463 #endif
    464 #endif
  • libpolys/polys/clapconv.h

    rfc4977 r146c603  
    1515
    1616#include <polys/monomials/ring.h>
    17 //#include <polys/ext_fields/longtrans.h>
    1817#include <factory/factory.h>
    1918
     
    2120poly convFactoryPSingP ( const CanonicalForm & f, const ring r );
    2221CanonicalForm convSingPFactoryP( poly p, const ring r );
    23 //CanonicalForm convSingIFactoryI( int i);// by constructor of CanonicalForm
    2422int convFactoryISingI( const CanonicalForm & f);
    2523
    26 //CanonicalForm convSingAPFactoryAP ( poly p , const Variable & a, const ring r );
    27 //poly convFactoryAPSingAP ( const CanonicalForm & f, const ring r );
    28 //poly convFactoryAPSingAP_R ( const CanonicalForm & f, int par_start, int var_start );
    29 
    30 //CanonicalForm convSingGFFactoryGF ( poly p, const ring r );
    31 //poly convFactoryGFSingGF ( const CanonicalForm & f, const ring r );
    32 
    33 //CanonicalForm convSingAFactoryA ( number p , const Variable & a, const ring r );
    34 //number convFactoryASingA ( const CanonicalForm & f, const ring r );
    35 
    36 //CanonicalForm convSingTrPFactoryP ( poly p, const ring r );
    37 //poly convFactoryPSingTrP ( const CanonicalForm & f, const ring r );
     24CanonicalForm convSingAFactoryA( number pp, Variable a, const coeffs cf );
     25number convFactoryASingA ( const CanonicalForm & f, const coeffs cf );
    3826
    3927// HAVE_FACTORY
  • libpolys/polys/ext_fields/algext.cc

    rfc4977 r146c603  
    4444#include <polys/simpleideals.h>
    4545
     46#ifdef HAVE_FACTORY
     47#include <polys/clapconv.h>
     48#include <factory/factory.h>
     49#endif
     50
    4651#include "ext_fields/algext.h"
    4752#define TRANSEXT_PRIVATES 1
     
    522527}
    523528
     529void  naNormalize(number &a, const coeffs cf)
     530{
     531  poly aa=(poly)a;
     532  definiteReduce(aa,naMinpoly,cf);
     533  a=(number)aa;
     534}
     535
     536#ifdef HAVE_FACTORY
     537number naConvFactoryNSingN( const CanonicalForm n, const coeffs cf)
     538{
     539  if (n.isZero()) return NULL;
     540  poly p=convFactoryPSingP(n,naRing);
     541  return (number)p;
     542}
     543CanonicalForm naConvSingNFactoryN( number n, BOOLEAN setChar, const coeffs cf )
     544{
     545  naTest(n);
     546  if (n==NULL) return CanonicalForm(0);
     547
     548  return convSingPFactoryP((poly)n,naRing);
     549}
     550#endif
     551
     552
    524553/* IMPORTANT NOTE: Since an algebraic field extension is again a field,
    525554                   the gcd of two elements is not very interesting. (It
     
    735764  cf->cfImPart       = naImPart;
    736765  cf->cfCoeffWrite   = naCoeffWrite;
     766  cf->cfNormalize    = naNormalize;
    737767#ifdef LDEBUG
    738768  cf->cfDBTest       = naDBTest;
     
    744774  cf->cfInvers       = naInvers;
    745775  cf->cfIntDiv       = naDiv;
     776#ifdef HAVE_FACTORY
     777  cf->convFactoryNSingN=naConvFactoryNSingN;
     778  cf->convSingNFactoryN=naConvSingNFactoryN;
     779#endif
    746780 
    747781  return FALSE;
Note: See TracChangeset for help on using the changeset viewer.