Changeset 925a43c in git
 Timestamp:
 Jun 21, 2010, 7:12:01 PM (13 years ago)
 Branches:
 (u'jengelhdatetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'f875bbaccd0831e36aaed09ff6adeb3eb45aeb94')
 Children:
 4d1ae5af2805ed797a6a992f88a4bb83fbc625f8
 Parents:
 37d3186ad34a5dcbcd56103bd58674b22a5b236b
 gitauthor:
 Hans Schoenemann <hannes@mathematik.unikl.de>20100621 19:12:01+02:00
 gitcommitter:
 Mohamed Barakat <mohamed.barakat@rwthaachen.de>20111109 11:55:15+01:00
 Location:
 coeffs
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

coeffs/rmodulo2m.cc
r37d318 r925a43c 24 24 int nr2mExp; 25 25 26 extern omBin gmp_nrz_bin; /* init in rintegers*/ 27 26 28 /* for initializing function pointers */ 27 29 void nr2mInitChar (coeffs r, void*) 28 30 { 29 nr2mInitExp( c, r);30 n>cfInit = nr2mInit;31 n>cfCopy = nr2mCopy;32 n>n_Int = nr2mInt;33 n>nAdd = nr2mAdd;34 n>nSub = nr2mSub;35 n>nMult = nr2mMult;36 n>nDiv = nr2mDiv;37 n>nIntDiv = nr2mIntDiv;38 n>nIntMod = nr2mMod;39 n>nExactDiv = nr2mDiv;40 n>nNeg = nr2mNeg;41 n>nInvers = nr2mInvers;42 n>nDivBy = nr2mDivBy;43 n>nDivComp = nr2mDivComp;44 n>nGreater = nr2mGreater;45 n>nEqual = nr2mEqual;46 n>nIsZero = nr2mIsZero;47 n>nIsOne = nr2mIsOne;48 n>nIsMOne = nr2mIsMOne;49 n>nGreaterZero = nr2mGreaterZero;50 n>cfWrite = nr2mWrite;51 n>nRead = nr2mRead;52 n>nPower = nr2mPower;53 n>cfSetMap = nr2mSetMap;54 n>nNormalize = ndNormalize;55 n>nLcm = nr2mLcm;56 n>nGcd = nr2mGcd;57 n>nIsUnit = nr2mIsUnit;58 n>nGetUnit = nr2mGetUnit;59 n>nExtGcd = nr2mExtGcd;60 n>nName = ndName;31 nr2mInitExp(r>ch, r); 32 r>cfInit = nr2mInit; 33 r>cfCopy = ndCopy; 34 r>cfInt = nr2mInt; 35 r>cfAdd = nr2mAdd; 36 r>cfSub = nr2mSub; 37 r>cfMult = nr2mMult; 38 r>cfDiv = nr2mDiv; 39 r>cfIntDiv = nr2mIntDiv; 40 r>cfIntMod = nr2mMod; 41 r>cfExactDiv = nr2mDiv; 42 r>cfNeg = nr2mNeg; 43 r>cfInvers = nr2mInvers; 44 r>cfDivBy = nr2mDivBy; 45 r>cfDivComp = nr2mDivComp; 46 r>cfGreater = nr2mGreater; 47 r>cfEqual = nr2mEqual; 48 r>cfIsZero = nr2mIsZero; 49 r>cfIsOne = nr2mIsOne; 50 r>cfIsMOne = nr2mIsMOne; 51 r>cfGreaterZero = nr2mGreaterZero; 52 r>cfWrite = nr2mWrite; 53 r>cfRead = nr2mRead; 54 r>cfPower = nr2mPower; 55 r>cfSetMap = nr2mSetMap; 56 r>cfNormalize = ndNormalize; 57 r>cfLcm = nr2mLcm; 58 r>cfGcd = nr2mGcd; 59 r>cfIsUnit = nr2mIsUnit; 60 r>cfGetUnit = nr2mGetUnit; 61 r>cfExtGcd = nr2mExtGcd; 62 r>cfName = ndName; 61 63 #ifdef LDEBUG 62 n>nDBTest = nr2mDBTest;64 r>cfDBTest = nr2mDBTest; 63 65 #endif 64 66 } … … 72 74 return (number)0; 73 75 else 74 return nr2mMultM(a,b );76 return nr2mMultM(a,b,r); 75 77 } 76 78 … … 138 140 { 139 141 *t = NULL; 140 *s = nr2mInvers(a );142 *s = nr2mInvers(a,r); 141 143 return (number) ((1L << res));// * (NATNUMBER) a); // (2**res)*a a ist Einheit 142 144 } … … 144 146 { 145 147 *s = NULL; 146 *t = nr2mInvers(b );148 *t = nr2mInvers(b,r); 147 149 return (number) ((1L << res));// * (NATNUMBER) b); // (2**res)*b b ist Einheit 148 150 } … … 161 163 else 162 164 { 163 nr2mPower(a,i1,result );164 *result = nr2mMultM(a,*result );165 nr2mPower(a,i1,result,r); 166 *result = nr2mMultM(a,*result,r); 165 167 } 166 168 } … … 200 202 number nr2mAdd (number a, number b, const coeffs r) 201 203 { 202 return nr2mAddM(a,b );204 return nr2mAddM(a,b,r); 203 205 } 204 206 205 207 number nr2mSub (number a, number b, const coeffs r) 206 208 { 207 return nr2mSubM(a,b );209 return nr2mSubM(a,b,r); 208 210 } 209 211 … … 241 243 BOOLEAN nr2mEqual (number a, number b, const coeffs r) 242 244 { 243 return nr2mEqualM(a,b);245 return a==b; 244 246 } 245 247 246 248 BOOLEAN nr2mGreater (number a, number b, const coeffs r) 247 249 { 248 return nr2mDivBy(a, b );250 return nr2mDivBy(a, b,r); 249 251 } 250 252 … … 390 392 { 391 393 assume((NATNUMBER)c % 2 != 0); 392 return (number)InvMod((NATNUMBER)c); 394 // Table !!! 395 NATNUMBER inv; 396 inv = InvMod((NATNUMBER)c,r); 397 return (number) inv; 393 398 } 394 399 … … 414 419 } 415 420 } 416 return (number) nr2mMult(a, nr2mInversM(b ));421 return (number) nr2mMult(a, nr2mInversM(b,r),r); 417 422 } 418 423 … … 492 497 return (number)0; 493 498 } 494 return nr2mInversM(c );499 return nr2mInversM(c,r); 495 500 } 496 501 … … 498 503 { 499 504 if ((NATNUMBER)c==0) return c; 500 return nr2mNegM(c );501 } 502 503 number nr2mMapMachineInt(number from, const coeffs r)504 { 505 NATNUMBER i = ((NATNUMBER) from) % r>nr2mModul ;505 return nr2mNegM(c,r); 506 } 507 508 number nr2mMapMachineInt(number from, const coeffs src, const coeffs dst) 509 { 510 NATNUMBER i = ((NATNUMBER) from) % dst>nr2mModul ; 506 511 return (number) i; 507 512 } 508 513 509 number nr2mCopy(number a, const coeffs) 510 { 511 return a; 512 } 513 514 number nr2mMapZp(number from, const coeffs r) 515 { 516 long ii = (long)from; 514 number nr2mMapZp(number from, const coeffs src, const coeffs dst) 515 { 517 516 NATNUMBER j = (NATNUMBER)1; 518 if (ii < 0) { j = r>nr2mModul; ii = ii; } 517 long ii = (long) from; 518 if (ii < 0) { j = dst>nr2mModul; ii = ii; } 519 519 NATNUMBER i = (NATNUMBER)ii; 520 i = i & r>nr2mModul;520 i = i & dst>nr2mModul; 521 521 /* now we have: from = j * i mod 2^m */ 522 return (number)nr2mMult((number)i, (number)j );523 } 524 525 number nr2mMapQ(number from, const coeffs r)526 { 527 int_number erg = (int_number) omAlloc(sizeof(mpz_t));522 return (number)nr2mMult((number)i, (number)j, dst); 523 } 524 525 number nr2mMapQ(number from, const coeffs src, const coeffs dst) 526 { 527 int_number erg = (int_number) omAllocBin(gmp_nrz_bin); 528 528 mpz_init(erg); 529 529 int_number k = (int_number) omAlloc(sizeof(mpz_t)); 530 mpz_init_set_ui(k, r>nr2mModul);530 mpz_init_set_ui(k, dst>nr2mModul); 531 531 532 532 nlGMP(from, (number)erg); … … 540 540 } 541 541 542 number nr2mMapGMP(number from, const coeffs r)543 { 544 int_number erg = (int_number) omAlloc(sizeof(mpz_t));542 number nr2mMapGMP(number from, const coeffs src, const coeffs dst) 543 { 544 int_number erg = (int_number) omAllocBin(gmp_nrz_bin); 545 545 mpz_init(erg); 546 546 int_number k = (int_number) omAlloc(sizeof(mpz_t)); 547 mpz_init_set_ui(k, r>nr2mModul);547 mpz_init_set_ui(k, dst>nr2mModul); 548 548 549 549 mpz_and(erg, (int_number)from, k); … … 556 556 } 557 557 558 nMapFunc nr2mSetMap(const ring src, const ringdst)559 { 560 if ( rField_is_Ring_2toM(src)558 nMapFunc nr2mSetMap(const coeffs src, const coeffs dst) 559 { 560 if (nField_is_Ring_2toM(src) 561 561 && (src>ringflagb == dst>ringflagb)) 562 562 { 563 return n r2mCopy;564 } 565 if ( rField_is_Ring_2toM(src)563 return ndCopyMap; 564 } 565 if (nField_is_Ring_2toM(src) 566 566 && (src>ringflagb < dst>ringflagb)) 567 567 { /* i.e. map an integer mod 2^s into Z mod 2^t, where t < s */ 568 568 return nr2mMapMachineInt; 569 569 } 570 if ( rField_is_Ring_2toM(src)570 if (nField_is_Ring_2toM(src) 571 571 && (src>ringflagb > dst>ringflagb)) 572 572 { /* i.e. map an integer mod 2^s into Z mod 2^t, where t > s */ 573 573 // to be done 574 574 } 575 if ( rField_is_Ring_Z(src))575 if (nField_is_Ring_Z(src)) 576 576 { 577 577 return nr2mMapGMP; 578 578 } 579 if ( rField_is_Q(src))579 if (nField_is_Q(src)) 580 580 { 581 581 return nr2mMapQ; 582 582 } 583 if ( rField_is_Zp(src)583 if (nField_is_Zp(src) 584 584 && (src>ch == 2) 585 585 && (dst>ringflagb == 1)) … … 587 587 return nr2mMapZp; 588 588 } 589 if ( rField_is_Ring_PtoM(src)  rField_is_Ring_ModN(src))589 if (nField_is_Ring_PtoM(src)  nField_is_Ring_ModN(src)) 590 590 { 591 591 // Computing the n of Z/n 592 int_number modul = (int_number) omAlloc(sizeof(mpz_t)); // evtl. spaeter mit bin592 int_number modul = (int_number) omAllocBin(gmp_nrz_bin); 593 593 mpz_init(modul); 594 594 mpz_set(modul, src>ringflaga); … … 672 672 int n=1; 673 673 674 s = nr2mEati(s, &z );674 s = nr2mEati(s, &z,r); 675 675 if ((*s) == '/') 676 676 { 677 677 s++; 678 s = nr2mEati(s, &n );678 s = nr2mEati(s, &n,r); 679 679 } 680 680 if (n == 1) 681 681 *a = (number)z; 682 682 else 683 *a = nr2mDiv((number)z,(number)n );683 *a = nr2mDiv((number)z,(number)n,r); 684 684 return s; 685 685 } 
coeffs/rmodulo2m.h
r37d318 r925a43c 16 16 17 17 void nr2mInitChar (coeffs r, void*); 18 number nr2mCopy (number a, const coeffs r);19 18 BOOLEAN nr2mGreaterZero (number k, const coeffs r); 20 19 number nr2mMult (number a, number b, const coeffs r);
Note: See TracChangeset
for help on using the changeset viewer.