Changeset e77676 in git


Ignore:
Timestamp:
Jan 6, 2012, 9:43:08 PM (12 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
4b38e3cc9992129dd4ef044c1d2cc7e55f93b134
Parents:
40e88db63c509564c2b00b7142b39ef6b846f72e
git-author:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-01-06 21:43:08+01:00
git-committer:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-01-06 21:59:37+01:00
Message:
Zp cleanup (no more coeffs::npPrimeM)

CHG: removed coeffs::npPrimeM in favour of coeffs::ch
Location:
libpolys/coeffs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libpolys/coeffs/coeffs.h

    r40e88db re77676  
    102102   void (*cfCoeffWrite)(const coeffs r, BOOLEAN details);
    103103
    104    // the union stuff
    105 
    106    // Zp:
    107    int npPrimeM;
    108    int npPminus1M;
    109    #ifdef HAVE_DIV_MOD
    110    unsigned short *npInvTable;
    111    #endif
    112    #if !defined(HAVE_DIV_MOD) || !defined(HAVE_MULT_MOD)
    113    unsigned short *npExpTable;
    114    unsigned short *npLogTable;
    115    #endif
    116 
    117104   // ?
    118105   // initialisation:
     
    209196   int     factoryVarOffset;
    210197   n_coeffType type;
    211 //-------------------------------------------
     198
     199   /////////////////////////////////////////////
     200   // the union stuff
     201
     202   //-------------------------------------------
    212203
    213204  /* for extension fields we need to be able to represent polynomials,
     
    276267  int *m_nfMinPoly;
    277268  char * m_nfParameter;
     269
     270// ---------------------------------------------------
     271// for Zp:
     272#ifdef HAVE_DIV_MOD
     273  unsigned short *npInvTable;
     274#endif
     275#if !defined(HAVE_DIV_MOD) || !defined(HAVE_MULT_MOD)
     276  unsigned short *npExpTable;
     277  unsigned short *npLogTable;
     278#endif
     279   //   int npPrimeM; // NOTE: npPrimeM is deprecated, please use ch instead!
     280  int npPminus1M; ///< characteristic - 1
    278281};
    279282//
  • libpolys/coeffs/modulop.cc

    r40e88db re77676  
    5757 
    5858  int h = (int)((long) k);
    59   return ((int)h !=0) && (h <= (r->npPrimeM>>1));
    60 }
    61 
    62 //unsigned long npMultMod(unsigned long a, unsigned long b)
     59  return ((int)h !=0) && (h <= (r->ch>>1));
     60}
     61
     62//unsigned long npMultMod(unsigned long a, unsigned long b, int npPrimeM)
    6363//{
    6464//  unsigned long c = a*b;
    6565//  c = c % npPrimeM;
    66 //  assume(c == (unsigned long) npMultM((number) a, (number) b));
     66//  assume(c == (unsigned long) npMultM((number) a, (number) b, npPrimeM));
    6767//  return c;
    6868//}
     
    167167
    168168#ifdef USE_NTL_XGCD
    169    XGCD(d, s, t, a, R->npPrimeM);
     169   XGCD(d, s, t, a, R->ch);
    170170   assume (d == 1);
    171171#else
     
    174174   assume(a>0);
    175175   u1=1; u2=0;
    176    u = a; v = R->npPrimeM;
     176   u = a; v = R->ch;
    177177
    178178   while (v != 0)
     
    191191#endif
    192192   if (s < 0)
    193       return s + R->npPrimeM;
     193      return s + R->ch;
    194194   else
    195195      return s;
     
    222222
    223223//#ifdef NV_OPS
    224 //  if (npPrimeM>NV_MAX_PRIME)
     224//  if (r->ch>NV_MAX_PRIME)
    225225//    return nvDiv(a,b);
    226226//#endif
     
    339339      ii *= 10;
    340340      ii += *s++ - '0';
    341       if (ii >= (MAX_INT_VAL / 10)) ii = ii % r->npPrimeM;
     341      if (ii >= (MAX_INT_VAL / 10)) ii = ii % r->ch;
    342342    }
    343343    while (((*s) >= '0') && ((*s) <= '9'));
    344     if (ii >= r->npPrimeM) ii = ii % r->npPrimeM;
     344    if (ii >= r->ch) ii = ii % r->ch;
    345345    *i=(int)ii;
    346346  }
     
    368368    {
    369369#ifdef NV_OPS
    370       if (r->npPrimeM>NV_MAX_PRIME)
     370      if (r->ch>NV_MAX_PRIME)
    371371        *a = nvDiv((number)z,(number)n,r);
    372372      else
     
    387387  #ifdef HAVE_DIV_MOD
    388388  if (r->npInvTable!=NULL)
    389   omFreeSize( (void *)r->npInvTable, r->npPrimeM*sizeof(unsigned short) );
     389  omFreeSize( (void *)r->npInvTable, r->ch*sizeof(unsigned short) );
    390390  r->npInvTable=NULL;
    391391  #else
    392392  if (r->npExpTable!=NULL)
    393393  {
    394     omFreeSize( (void *)r->npExpTable, r->npPrimeM*sizeof(unsigned short) );
    395     omFreeSize( (void *)r->npLogTable, r->npPrimeM*sizeof(unsigned short) );
     394    omFreeSize( (void *)r->npExpTable, r->ch*sizeof(unsigned short) );
     395    omFreeSize( (void *)r->npLogTable, r->ch*sizeof(unsigned short) );
    396396    r->npExpTable=NULL; r->npLogTable=NULL;
    397397  }
     
    407407CanonicalForm npConvSingNFactoryN( number n, BOOLEAN setChar, const coeffs r )
    408408{
    409   if (setChar) setCharacteristic( r->npPrimeM );
     409  if (setChar) setCharacteristic( r->ch );
    410410  CanonicalForm term(npInt( n,r ));
    411411  return term;
     
    436436  int i, w;
    437437
    438   r->npPrimeM = c;
    439   r->npPminus1M = c /*r->npPrimeM*/ - 1;
     438  r->ch = c;
     439  r->npPminus1M = c /*r->ch*/ - 1;
    440440
    441441  //r->cfInitChar=npInitChar;
     
    514514  // the tables
    515515#ifdef NV_OPS
    516   if (r->npPrimeM <=NV_MAX_PRIME)
     516  if (r->ch <=NV_MAX_PRIME)
    517517#endif
    518518  {
    519519#if !defined(HAVE_DIV_MOD) || !defined(HAVE_MULT_MOD)
    520     r->npExpTable=(unsigned short *)omAlloc( r->npPrimeM*sizeof(unsigned short) );
    521     r->npLogTable=(unsigned short *)omAlloc( r->npPrimeM*sizeof(unsigned short) );
     520    r->npExpTable=(unsigned short *)omAlloc( r->ch*sizeof(unsigned short) );
     521    r->npLogTable=(unsigned short *)omAlloc( r->ch*sizeof(unsigned short) );
    522522    r->npExpTable[0] = 1;
    523523    r->npLogTable[0] = 0;
    524     if (r->npPrimeM > 2)
     524    if (r->ch > 2)
    525525    {
    526526      w = 1;
     
    534534          i++;
    535535          r->npExpTable[i] =(int)(((long)w * (long)r->npExpTable[i-1])
    536                                % r->npPrimeM);
     536                               % r->ch);
    537537          r->npLogTable[r->npExpTable[i]] = i;
    538           if (/*(i == npPrimeM - 1 ) ||*/ (r->npExpTable[i] == 1))
     538          if (/*(i == r->ch - 1 ) ||*/ (r->npExpTable[i] == 1))
    539539            break;
    540540        }
    541         if (i == r->npPrimeM - 1)
     541        if (i == r->ch - 1)
    542542          break;
    543543      }
     
    550550#endif
    551551#ifdef HAVE_DIV_MOD
    552     r->npInvTable=(unsigned short*)omAlloc0( r->npPrimeM*sizeof(unsigned short) );
     552    r->npInvTable=(unsigned short*)omAlloc0( r->ch*sizeof(unsigned short) );
    553553#endif
    554554  }
     
    559559BOOLEAN npDBTest (number a, const char *f, const int l, const coeffs r)
    560560{
    561   if (((long)a<0) || ((long)a>r->npPrimeM))
     561  if (((long)a<0) || ((long)a>r->ch))
    562562  {
    563563    Print("wrong mod p number %ld at %s,%d\n",(long)a,f,l);
     
    571571{
    572572  long i = (long)from;
    573   if (i>src->npPrimeM/2)
    574   {
    575     i-=src->npPrimeM;
    576     while (i < 0) i+=dst_r->npPrimeM;
    577   }
    578   i%=dst_r->npPrimeM;
     573  if (i>src->ch/2)
     574  {
     575    i-=src->ch;
     576    while (i < 0) i+=dst_r->ch;
     577  }
     578  i%=dst_r->ch;
    579579  return (number)i;
    580580}
     
    604604  }
    605605
    606   if(dst_r->npPrimeM>2)
     606  if(dst_r->ch>2)
    607607    e=(*f)[0]._mp_exp-size;
    608608  else
     
    629629    ndest->_mp_alloc = ndest->_mp_size = bl;
    630630    res->s = 0;
    631     in=mpz_fdiv_ui(ndest,dst_r->npPrimeM);
     631    in=mpz_fdiv_ui(ndest,dst_r->ch);
    632632    mpz_clear(ndest);
    633633  }
     
    644644  dest->_mp_d = dd;
    645645  dest->_mp_alloc = al;
    646   iz=mpz_fdiv_ui(dest,dst_r->npPrimeM);
     646  iz=mpz_fdiv_ui(dest,dst_r->ch);
    647647  mpz_clear(dest);
    648648  if(res->s==0)
     
    661661  mpz_init(erg);
    662662
    663   mpz_mod_ui(erg, (int_number) from, dst->npPrimeM);
     663  mpz_mod_ui(erg, (int_number) from, dst->ch);
    664664  number r = (number) mpz_get_si(erg);
    665665
     
    674674number npMapMachineInt(number from, const coeffs /*src*/,const coeffs dst)
    675675{
    676   long i = (long) (((unsigned long) from) % dst->npPrimeM);
     676  long i = (long) (((unsigned long) from) % dst->ch);
    677677  return (number) i;
    678678}
     
    682682number npMapCanonicalForm (number a, const coeffs /*src*/, const coeffs dst)
    683683{
    684   setCharacteristic (dst ->npPrimeM);
     684  setCharacteristic (dst ->ch);
    685685  CanonicalForm f= CanonicalForm ((InternalCF*)(a));
    686686  return (number) (f.intval());
     
    756756   u1=1; v1=0;
    757757   u2=0; v2=1;
    758    u = a; v = R->npPrimeM;
     758   u = a; v = R->ch;
    759759
    760760   while (v != 0)
     
    775775   //t = v1;
    776776   if (s < 0)
    777       return s + R->npPrimeM;
     777      return s + R->ch;
    778778   else
    779779      return s;
     
    831831void    npCoeffWrite  (const coeffs r, BOOLEAN /*details*/)
    832832{
    833   Print("//   characteristic : %d\n",r->npPrimeM);
    834 }
    835 
     833  Print("//   characteristic : %d\n",r->ch);
     834}
     835
  • libpolys/coeffs/modulop.h

    r40e88db re77676  
    6767#endif
    6868
    69 #if 0
    70 inline number npMultM(number a, number b)
    71 // return (a*b)%n
    72 {
    73    double ab;
    74    long q, res;
    75 
    76    ab = ((double) ((int)a)) * ((double) ((int)b));
    77    q  = (long) (ab/((double) npPrimeM));  // q could be off by (+/-) 1
    78    res = (long) (ab - ((double) q)*((double) npPrimeM));
    79    res += (res >> 31) & npPrimeM;
    80    res -= npPrimeM;
    81    res += (res >> 31) & npPrimeM;
    82    return (number)res;
    83 }
    84 #endif
     69// inline number npMultM(number a, number b, int npPrimeM)
     70// // return (a*b)%n
     71// {
     72//    double ab;
     73//    long q, res;
     74//
     75//    ab = ((double) ((int)a)) * ((double) ((int)b));
     76//    q  = (long) (ab/((double) npPrimeM));  // q could be off by (+/-) 1
     77//    res = (long) (ab - ((double) q)*((double) npPrimeM));
     78//    res += (res >> 31) & npPrimeM;
     79//    res -= npPrimeM;
     80//    res += (res >> 31) & npPrimeM;
     81//    return (number)res;
     82// }
    8583#ifdef HAVE_MULT_MOD
    8684static inline number npMultM(number a, number b, const coeffs r)
    8785{
    8886  return (number)
    89     ((((unsigned long) a)*((unsigned long) b)) % ((unsigned long) r->npPrimeM));
     87    ((((unsigned long) a)*((unsigned long) b)) % ((unsigned long) r->ch));
    9088}
    9189#else
     
    121119{
    122120  long R = (long)a + (long)b;
    123   return (number)(R >= r->npPrimeM ? R - r->npPrimeM : R);
     121  return (number)(R >= r->ch ? R - r->ch : R);
    124122}
    125123static inline number npSubM(number a, number b, const coeffs r)
    126124{
    127125  return (number)((long)a<(long)b ?
    128                        r->npPrimeM-(long)b+(long)a : (long)a-(long)b);
     126                       r->ch-(long)b+(long)a : (long)a-(long)b);
    129127}
    130128#else
     
    132130{
    133131   long res = ((long)a + (long)b);
    134    res -= r->npPrimeM;
     132   res -= r->ch;
    135133#if SIZEOF_LONG == 8
    136    res += (res >> 63) & r->npPrimeM;
     134   res += (res >> 63) & r->ch;
    137135#else
    138    res += (res >> 31) & r->npPrimeM;
     136   res += (res >> 31) & r->ch;
    139137#endif
    140138   return (number)res;
     
    144142   long res = ((long)a - (long)b);
    145143#if SIZEOF_LONG == 8
    146    res += (res >> 63) & r->npPrimeM;
     144   res += (res >> 63) & r->ch;
    147145#else
    148    res += (res >> 31) & r->npPrimeM;
     146   res += (res >> 31) & r->ch;
    149147#endif
    150148   return (number)res;
     
    157155}
    158156
    159 /*
    160 *inline number npMultM(number a, number b)
    161 *{
    162 *  return (number)(((long)a*(long)b) % npPrimeM);
    163 *}
    164 */
     157// inline number npMultM(number a, number b, int npPrimeM)
     158// {
     159//   return (number)(((long)a*(long)b) % npPrimeM);
     160// }
    165161
    166 #define npNegM(A,r)      (number)(r->npPrimeM-(long)(A))
     162
     163#define npNegM(A,r)      (number)(r->ch-(long)(A))
    167164#define npEqualM(A,B,r)  ((A)==(B))
    168165
    169166
    170 
    171167#endif
Note: See TracChangeset for help on using the changeset viewer.