Changeset 79020f in git
- Timestamp:
- Jan 6, 2012, 9:28:16 PM (11 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '0604212ebb110535022efecad887940825b97c3f')
- Children:
- 40e88db63c509564c2b00b7142b39ef6b846f72e
- Parents:
- 1cbb1f452324cf72b33ef5a1cb6256d97bcbcbd0
- git-author:
- Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-01-06 21:28:16+01:00
- git-committer:
- Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-01-06 21:59:37+01:00
- Location:
- libpolys
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/coeffs/longrat.cc
r1cbb1f4 r79020f 1256 1256 } 1257 1257 1258 int nlModP(number n, int p, const coeffs r) 1259 { 1260 if (SR_HDL(n) & SR_INT) 1261 { 1262 long i=SR_TO_INT(n); 1263 if (i<0L) return (((long)p)-((-i)%((long)p))); 1264 return i%((long)p); 1265 } 1266 int iz=(int)mpz_fdiv_ui(n->z,(unsigned long)p); 1267 if (n->s!=3) 1268 { 1269 int in=mpz_fdiv_ui(n->n,(unsigned long)p); 1270 long s; 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); // BUG: integer overflow!!! 1295 return (int)u; 1296 } 1297 return iz; 1258 // Map q \in QQ \to Zp 1259 // src = Q, dst = Zp (or an extension of Zp?) 1260 number nlModP(number q, const coeffs Q, const coeffs Zp) 1261 { 1262 assume( getCoeffType(Q) == ID ); 1263 1264 const int p = n_GetChar(Zp); 1265 assume( p > 0 ); 1266 1267 const long P = p; 1268 assume( P > 0 ); 1269 1270 // embedded long within q => only long numerator has to be converted 1271 // to int (modulo char.) 1272 if (SR_HDL(q) & SR_INT) 1273 { 1274 long i = SR_TO_INT(q); 1275 if (i<0L) 1276 return n_Init( static_cast<int>( P - ((-i)%P) ), Zp); 1277 else 1278 return n_Init( static_cast<int>( i % P ), Zp ); 1279 } 1280 1281 const unsigned long PP = p; 1282 1283 // numerator modulo char. should fit into int 1284 number z = n_Init( static_cast<int>(mpz_fdiv_ui(q->z, PP)), Zp ); 1285 1286 // denominator != 1? 1287 if (q->s!=3) 1288 { 1289 // denominator modulo char. should fit into int 1290 number n = n_Init( static_cast<int>(mpz_fdiv_ui(q->n, PP)), Zp ); 1291 1292 number res = n_Div( z, n, Zp ); 1293 1294 n_Delete(&z, Zp); 1295 n_Delete(&n, Zp); 1296 1297 return res; 1298 } 1299 1300 return z; 1298 1301 } 1299 1302 -
libpolys/coeffs/longrat.h
r1cbb1f4 r79020f 87 87 const char * nlRead (const char *s, number *a, const coeffs r); 88 88 void nlWrite(number &a, const coeffs r); 89 int nlModP(number n, int p, const coeffs r); 89 90 /// Map q \in QQ \to Zp 91 number nlModP(number q, const coeffs Q, const coeffs Zp); 92 90 93 int nlSize(number n, const coeffs r); 91 94 number nlGetDenom(number &n, const coeffs r); -
libpolys/coeffs/modulop.cc
r1cbb1f4 r79020f 460 460 //r->cfName = ndName; 461 461 r->cfInpMult=ndInpMult; 462 r->cfInit_bigint= n pMap0;462 r->cfInit_bigint= nlModP; // npMap0; 463 463 #ifdef NV_OPS 464 464 if (c>NV_MAX_PRIME) … … 545 545 #endif 546 546 547 number npMap0(number from, const coeffs src, const coeffs dst_r)548 {549 int nlModP(number n, int p, const coeffs r);550 551 return npInit(nlModP(from, dst_r->npPrimeM, src),dst_r);552 }553 554 547 number npMapP(number from, const coeffs src, const coeffs dst_r) 555 548 { … … 686 679 if (nCoeff_is_Q(src)) 687 680 { 688 return n pMap0;681 return nlModP; // npMap0; 689 682 } 690 683 if ( nCoeff_is_Zp(src) ) -
libpolys/coeffs/modulop.h
r1cbb1f4 r79020f 55 55 nMapFunc npSetMap(const coeffs src, const coeffs dst); 56 56 number npMapP(number from, const coeffs src, const coeffs r); 57 number npMap0(number from, const coeffs src, const coeffs r);58 57 /*-------specials for spolys, do NOT use otherwise--------------------------*/ 59 58 /* for npMultM, npSubM, npNegM, npEqualM : */ -
libpolys/polys/ext_fields/algext.cc
r1cbb1f4 r79020f 650 650 if (n_IsZero(a, src)) return NULL; 651 651 int p = rChar(dst->extRing); 652 int n = nlModP(a, p, src); 653 number q = n_Init(n, dst->extRing->cf); 654 poly result = p_One(dst->extRing); 655 p_SetCoeff(result, q, dst->extRing); 652 653 number q = nlModP(a, src, dst->extRing->cf); 654 655 poly result = p_NSet(q, dst->extRing); 656 656 657 return (number)result; 657 658 } -
libpolys/polys/ext_fields/transext.cc
r1cbb1f4 r79020f 1119 1119 if (n_IsZero(a, src)) return NULL; 1120 1120 int p = rChar(dst->extRing); 1121 int n = nlModP(a, p, src); 1122 number q = n_Init(n, dst->extRing->cf); 1123 poly g; 1121 number q = nlModP(a, src, dst->extRing->cf); 1122 1124 1123 if (n_IsZero(q, dst->extRing->cf)) 1125 1124 { … … 1127 1126 return NULL; 1128 1127 } 1129 g = p_One(dst->extRing); 1130 p_SetCoeff(g, q, dst->extRing); 1128 1129 poly g = p_NSet(q, dst->extRing); 1130 1131 1131 fraction f = (fraction)omAlloc0Bin(fractionObjectBin); 1132 1132 NUM(f) = g; // DEN(f) = NULL; COM(f) = 0;
Note: See TracChangeset
for help on using the changeset viewer.