Changeset e77676 in git
- Timestamp:
- Jan 6, 2012, 9:43:08 PM (11 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '0604212ebb110535022efecad887940825b97c3f')
- 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
- Location:
- libpolys/coeffs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/coeffs/coeffs.h
r40e88db re77676 102 102 void (*cfCoeffWrite)(const coeffs r, BOOLEAN details); 103 103 104 // the union stuff105 106 // Zp:107 int npPrimeM;108 int npPminus1M;109 #ifdef HAVE_DIV_MOD110 unsigned short *npInvTable;111 #endif112 #if !defined(HAVE_DIV_MOD) || !defined(HAVE_MULT_MOD)113 unsigned short *npExpTable;114 unsigned short *npLogTable;115 #endif116 117 104 // ? 118 105 // initialisation: … … 209 196 int factoryVarOffset; 210 197 n_coeffType type; 211 //------------------------------------------- 198 199 ///////////////////////////////////////////// 200 // the union stuff 201 202 //------------------------------------------- 212 203 213 204 /* for extension fields we need to be able to represent polynomials, … … 276 267 int *m_nfMinPoly; 277 268 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 278 281 }; 279 282 // -
libpolys/coeffs/modulop.cc
r40e88db re77676 57 57 58 58 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) 63 63 //{ 64 64 // unsigned long c = a*b; 65 65 // c = c % npPrimeM; 66 // assume(c == (unsigned long) npMultM((number) a, (number) b ));66 // assume(c == (unsigned long) npMultM((number) a, (number) b, npPrimeM)); 67 67 // return c; 68 68 //} … … 167 167 168 168 #ifdef USE_NTL_XGCD 169 XGCD(d, s, t, a, R-> npPrimeM);169 XGCD(d, s, t, a, R->ch); 170 170 assume (d == 1); 171 171 #else … … 174 174 assume(a>0); 175 175 u1=1; u2=0; 176 u = a; v = R-> npPrimeM;176 u = a; v = R->ch; 177 177 178 178 while (v != 0) … … 191 191 #endif 192 192 if (s < 0) 193 return s + R-> npPrimeM;193 return s + R->ch; 194 194 else 195 195 return s; … … 222 222 223 223 //#ifdef NV_OPS 224 // if ( npPrimeM>NV_MAX_PRIME)224 // if (r->ch>NV_MAX_PRIME) 225 225 // return nvDiv(a,b); 226 226 //#endif … … 339 339 ii *= 10; 340 340 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; 342 342 } 343 343 while (((*s) >= '0') && ((*s) <= '9')); 344 if (ii >= r-> npPrimeM) ii = ii % r->npPrimeM;344 if (ii >= r->ch) ii = ii % r->ch; 345 345 *i=(int)ii; 346 346 } … … 368 368 { 369 369 #ifdef NV_OPS 370 if (r-> npPrimeM>NV_MAX_PRIME)370 if (r->ch>NV_MAX_PRIME) 371 371 *a = nvDiv((number)z,(number)n,r); 372 372 else … … 387 387 #ifdef HAVE_DIV_MOD 388 388 if (r->npInvTable!=NULL) 389 omFreeSize( (void *)r->npInvTable, r-> npPrimeM*sizeof(unsigned short) );389 omFreeSize( (void *)r->npInvTable, r->ch*sizeof(unsigned short) ); 390 390 r->npInvTable=NULL; 391 391 #else 392 392 if (r->npExpTable!=NULL) 393 393 { 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) ); 396 396 r->npExpTable=NULL; r->npLogTable=NULL; 397 397 } … … 407 407 CanonicalForm npConvSingNFactoryN( number n, BOOLEAN setChar, const coeffs r ) 408 408 { 409 if (setChar) setCharacteristic( r-> npPrimeM);409 if (setChar) setCharacteristic( r->ch ); 410 410 CanonicalForm term(npInt( n,r )); 411 411 return term; … … 436 436 int i, w; 437 437 438 r-> npPrimeM= c;439 r->npPminus1M = c /*r-> npPrimeM*/ - 1;438 r->ch = c; 439 r->npPminus1M = c /*r->ch*/ - 1; 440 440 441 441 //r->cfInitChar=npInitChar; … … 514 514 // the tables 515 515 #ifdef NV_OPS 516 if (r-> npPrimeM<=NV_MAX_PRIME)516 if (r->ch <=NV_MAX_PRIME) 517 517 #endif 518 518 { 519 519 #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) ); 522 522 r->npExpTable[0] = 1; 523 523 r->npLogTable[0] = 0; 524 if (r-> npPrimeM> 2)524 if (r->ch > 2) 525 525 { 526 526 w = 1; … … 534 534 i++; 535 535 r->npExpTable[i] =(int)(((long)w * (long)r->npExpTable[i-1]) 536 % r-> npPrimeM);536 % r->ch); 537 537 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)) 539 539 break; 540 540 } 541 if (i == r-> npPrimeM- 1)541 if (i == r->ch - 1) 542 542 break; 543 543 } … … 550 550 #endif 551 551 #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) ); 553 553 #endif 554 554 } … … 559 559 BOOLEAN npDBTest (number a, const char *f, const int l, const coeffs r) 560 560 { 561 if (((long)a<0) || ((long)a>r-> npPrimeM))561 if (((long)a<0) || ((long)a>r->ch)) 562 562 { 563 563 Print("wrong mod p number %ld at %s,%d\n",(long)a,f,l); … … 571 571 { 572 572 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; 579 579 return (number)i; 580 580 } … … 604 604 } 605 605 606 if(dst_r-> npPrimeM>2)606 if(dst_r->ch>2) 607 607 e=(*f)[0]._mp_exp-size; 608 608 else … … 629 629 ndest->_mp_alloc = ndest->_mp_size = bl; 630 630 res->s = 0; 631 in=mpz_fdiv_ui(ndest,dst_r-> npPrimeM);631 in=mpz_fdiv_ui(ndest,dst_r->ch); 632 632 mpz_clear(ndest); 633 633 } … … 644 644 dest->_mp_d = dd; 645 645 dest->_mp_alloc = al; 646 iz=mpz_fdiv_ui(dest,dst_r-> npPrimeM);646 iz=mpz_fdiv_ui(dest,dst_r->ch); 647 647 mpz_clear(dest); 648 648 if(res->s==0) … … 661 661 mpz_init(erg); 662 662 663 mpz_mod_ui(erg, (int_number) from, dst-> npPrimeM);663 mpz_mod_ui(erg, (int_number) from, dst->ch); 664 664 number r = (number) mpz_get_si(erg); 665 665 … … 674 674 number npMapMachineInt(number from, const coeffs /*src*/,const coeffs dst) 675 675 { 676 long i = (long) (((unsigned long) from) % dst-> npPrimeM);676 long i = (long) (((unsigned long) from) % dst->ch); 677 677 return (number) i; 678 678 } … … 682 682 number npMapCanonicalForm (number a, const coeffs /*src*/, const coeffs dst) 683 683 { 684 setCharacteristic (dst -> npPrimeM);684 setCharacteristic (dst ->ch); 685 685 CanonicalForm f= CanonicalForm ((InternalCF*)(a)); 686 686 return (number) (f.intval()); … … 756 756 u1=1; v1=0; 757 757 u2=0; v2=1; 758 u = a; v = R-> npPrimeM;758 u = a; v = R->ch; 759 759 760 760 while (v != 0) … … 775 775 //t = v1; 776 776 if (s < 0) 777 return s + R-> npPrimeM;777 return s + R->ch; 778 778 else 779 779 return s; … … 831 831 void npCoeffWrite (const coeffs r, BOOLEAN /*details*/) 832 832 { 833 Print("// characteristic : %d\n",r-> npPrimeM);834 } 835 833 Print("// characteristic : %d\n",r->ch); 834 } 835 -
libpolys/coeffs/modulop.h
r40e88db re77676 67 67 #endif 68 68 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 // } 85 83 #ifdef HAVE_MULT_MOD 86 84 static inline number npMultM(number a, number b, const coeffs r) 87 85 { 88 86 return (number) 89 ((((unsigned long) a)*((unsigned long) b)) % ((unsigned long) r-> npPrimeM));87 ((((unsigned long) a)*((unsigned long) b)) % ((unsigned long) r->ch)); 90 88 } 91 89 #else … … 121 119 { 122 120 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); 124 122 } 125 123 static inline number npSubM(number a, number b, const coeffs r) 126 124 { 127 125 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); 129 127 } 130 128 #else … … 132 130 { 133 131 long res = ((long)a + (long)b); 134 res -= r-> npPrimeM;132 res -= r->ch; 135 133 #if SIZEOF_LONG == 8 136 res += (res >> 63) & r-> npPrimeM;134 res += (res >> 63) & r->ch; 137 135 #else 138 res += (res >> 31) & r-> npPrimeM;136 res += (res >> 31) & r->ch; 139 137 #endif 140 138 return (number)res; … … 144 142 long res = ((long)a - (long)b); 145 143 #if SIZEOF_LONG == 8 146 res += (res >> 63) & r-> npPrimeM;144 res += (res >> 63) & r->ch; 147 145 #else 148 res += (res >> 31) & r-> npPrimeM;146 res += (res >> 31) & r->ch; 149 147 #endif 150 148 return (number)res; … … 157 155 } 158 156 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 // } 165 161 166 #define npNegM(A,r) (number)(r->npPrimeM-(long)(A)) 162 163 #define npNegM(A,r) (number)(r->ch-(long)(A)) 167 164 #define npEqualM(A,B,r) ((A)==(B)) 168 165 169 166 170 171 167 #endif
Note: See TracChangeset
for help on using the changeset viewer.