Changeset a62201 in git


Ignore:
Timestamp:
Jul 22, 2014, 9:37:16 AM (9 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'a7324b6e0b44a1a8ed3fa4d9ca3e2ff210ddd52c')
Children:
0c42a847c2651462997b32adb623b79f38d133f5
Parents:
638c230a7830a70d265a617a0f2f2fa0505f2ec0
Message:
add: ndPower by Claus Fieker
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpolys/coeffs/numbers.cc

    r638c230 ra62201  
    6969}
    7070
     71void ndPower(number a, int i, number * res, const coeffs r)
     72{
     73  if (i==0) {
     74    *res = n_Init(1, r);
     75  } else if (i==1) {
     76    *res = n_Copy(a, r);
     77  } else if (i==2) {
     78    *res = n_Mult(a, a, r);
     79  } else if (i<0) {
     80    number b = n_Invers(a, r);
     81    ndPower(b, -i, res, r);
     82    n_Delete(&b, r);
     83  } else {
     84    ndPower(a, i/2, res, r);
     85    n_InpMult(*res, *res, r);
     86    if (i&1) {
     87      n_InpMult(*res, a, r);
     88    }
     89  }
     90}
    7191#ifdef LDEBUG
    7292void   nDBDummy1(number* d,char *, int) { *d=NULL; }
     
    85105{
    86106  Werror("ChineseRemainder not implemented for %s (c=%d)",r->cfCoeffString(r),getCoeffType(r));
    87   return n_Init(0,r); 
     107  return n_Init(0,r);
    88108}
    89109
     
    105125  if( (c != 0) && !ret )
    106126  {
    107     number ch = n_Init( c, r ); 
     127    number ch = n_Init( c, r );
    108128    number g = n_Gcd( ch, a, r );
    109129    ret = !n_IsOne (g, r);
     
    111131    n_Delete(&g, r);
    112132  }
    113   return ret; 
     133  return ret;
    114134}
    115135
     
    143163    c = n_Init(1, r);
    144164    return;
    145   } 
     165  }
    146166
    147167  number &curr = numberCollectionEnumerator.Current();
    148  
     168
    149169#ifdef HAVE_RINGS
    150   /// TODO: move to a separate implementation 
     170  /// TODO: move to a separate implementation
    151171  if (nCoeff_is_Ring(r))
    152172  {
     
    154174    {
    155175      c = n_GetUnit(curr, r);
    156      
     176
    157177      if (!n_IsOne(c, r))
    158178      {
     
    160180
    161181        n_InpMult(curr, inv, r);
    162        
     182
    163183        while( numberCollectionEnumerator.MoveNext() )
    164184        {
     
    168188        }
    169189
    170         n_Delete(&inv, r);       
    171       }     
     190        n_Delete(&inv, r);
     191      }
    172192    } else c = n_Init(1, r);
    173    
     193
    174194    return;
    175195  }
     
    186206
    187207    curr = n_Init(1, r); // ???
    188    
     208
    189209    number inv = n_Invers(t, r);
    190    
     210
    191211    while( numberCollectionEnumerator.MoveNext() )
    192212    {
     
    195215//      n_Normalize(n, r); // ?
    196216    }
    197    
     217
    198218    n_Delete(&inv, r);
    199219
     
    218238  if ( nCoeff_has_simple_Alloc(r) && nCoeff_has_simple_Alloc(aRing) )
    219239    return a;
    220         else
     240  else
    221241    return n_Copy(a, r);
    222242}
     
    255275
    256276number ndInitMPZ(mpz_t m, const coeffs r)
    257 { 
     277{
    258278  return n_Init( mpz_get_si(m), r);
    259279}
     
    281301 NULL,        /* n_algExt */
    282302 NULL,        /* n_transExt */
    283  #endif   
     303 #endif
    284304 ngcInitChar,  /* n_long_C */
    285305 #ifdef HAVE_RINGS
     
    294314 NULL,         /* n_Z2m */
    295315 #endif
    296  NULL   /* n_CF */
     316 NULL         /* n_CF */
    297317};
    298318
     
    335355    n->cfInitMPZ = ndInitMPZ;
    336356    n->cfMPZ = ndMPZ;
     357    n->cfPower = ndPower;
    337358
    338359    // n->cfKillChar = ndKillChar; /* dummy */
     
    343364    n->cfFarey = ndFarey;
    344365    n->cfParDeg = ndParDeg;
    345    
     366
    346367    n->cfParameter = ndParameter;
    347368
     
    357378#endif
    358379
    359 #ifdef fACTORY
    360380    n->convSingNFactoryN=ndConvSingNFactoryN;
    361381    n->convFactoryNSingN=ndConvFactoryNSingN;
    362 #endif
    363    
     382
    364383    BOOLEAN nOK=TRUE;
    365384    // init
     
    378397    if (n->cfExactDiv==NULL) n->cfExactDiv=n->cfDiv;
    379398    if (n->cfSubringGcd==NULL) n->cfSubringGcd=n->cfGcd;
    380    
     399
    381400#ifdef HAVE_RINGS
    382401    if (n->cfGetUnit==NULL) n->cfGetUnit=n->cfCopy;
     
    413432
    414433    assume( (n->iNumberOfParameters == 0 && n->pParameterNames == NULL) ||
    415             (n->iNumberOfParameters >  0 && n->pParameterNames != NULL) );           
     434            (n->iNumberOfParameters >  0 && n->pParameterNames != NULL) );
    416435
    417436    assume(n->cfParameter!=NULL);
    418437    assume(n->cfParDeg!=NULL);
    419      
     438
    420439    assume(n->cfRead!=NULL);
    421440    assume(n->cfNormalize!=NULL);
     
    427446    assume(n->cfIsMOne!=NULL);
    428447    assume(n->cfGreaterZero!=NULL);
    429     assume(n->cfPower!=NULL);
    430448    assume(n->cfGetDenom!=NULL);
    431449    assume(n->cfGetNumerator!=NULL);
     
    441459    assume(n->cfClearContent != NULL);
    442460    assume(n->cfClearDenominators != NULL);
    443    
     461
    444462#ifdef LDEBUG
    445463    if(n->cfDBTest==NULL)
     
    447465#endif
    448466    assume(n->type==t);
    449      
     467
    450468#ifndef SING_NDEBUG
    451469    if(n->cfKillChar==NULL) Warn("cfKillChar is NULL for coeff %d",t);
     
    454472    if(n->cfCoeffString==ndCoeffString) Warn("cfCoeffString is undefined for coeff %d",t);
    455473#endif
    456      
     474
    457475   if( n->nNULL == NULL )
    458476     n->nNULL = n_Init(0, n); // may still remain NULL
     
    526544
    527545void n_Print(number& a,  const coeffs r)
    528 { 
    529    assume(r != NULL); 
    530    n_Test(a,r); 
    531    
    532    StringSetS(""); 
    533    n_Write(a, r); 
     546{
     547   assume(r != NULL);
     548   n_Test(a,r);
     549
     550   StringSetS("");
     551   n_Write(a, r);
    534552   { char* s = StringEndS(); Print("%s", s); omFree(s); }
    535553}
Note: See TracChangeset for help on using the changeset viewer.