Changeset ef1632 in git
 Timestamp:
 Apr 3, 2018, 3:01:22 PM (5 years ago)
 Branches:
 (u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
 Children:
 f67afed8d454f54035cff586aa3cf35a06a7280e
 Parents:
 414cce519189e70ffda5ff4b972038335e5df374
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libpolys/coeffs/rmodulo2m.cc
r414cce5 ref1632 25 25 #ifdef HAVE_RINGS 26 26 27 #ifdef LDEBUG 28 BOOLEAN nr2mDBTest(number a, const char *f, const int l, const coeffs r) 29 { 30 if (((long)a<0L)  ((long)a>(long)r>mod2mMask)) 31 { 32 Print("wrong mod 2^n number %ld at %s,%d\n",(long)a,f,l); 33 return FALSE; 34 } 35 return TRUE; 36 } 37 #endif 38 39 27 40 static inline number nr2mMultM(number a, number b, const coeffs r) 28 41 { 29 42 return (number) 30 ((((unsigned long) a) * ((unsigned long) b)) & ((unsigned long)r>mod2mMask));43 ((((unsigned long) a) * ((unsigned long) b)) & r>mod2mMask); 31 44 } 32 45 … … 34 47 { 35 48 return (number) 36 ((((unsigned long) a) + ((unsigned long) b)) & ((unsigned long)r>mod2mMask));49 ((((unsigned long) a) + ((unsigned long) b)) & r>mod2mMask); 37 50 } 38 51 … … 40 53 { 41 54 return (number)((unsigned long)a < (unsigned long)b ? 42 r>mod2mMask  (unsigned long)b + (unsigned long)a + 1:55 r>mod2mMask+1  (unsigned long)b + (unsigned long)a: 43 56 (unsigned long)a  (unsigned long)b); 44 57 } 45 58 46 #define nr2mNegM(A,r) (number)((r>mod2mMask  (unsigned long)(A) + 1) & r>mod2mMask)59 #define nr2mNegM(A,r) (number)((r>mod2mMask+1  (unsigned long)(A)) & r>mod2mMask) 47 60 #define nr2mEqualM(A,B) ((A)==(B)) 48 61 … … 82 95 static coeffs nr2mQuot1(number c, const coeffs r) 83 96 { 84 coeffs rr; 85 long ch = r>cfInt(c, r); 86 mpz_t a,b; 87 mpz_init_set(a, r>modNumber); 88 mpz_init_set_ui(b, ch); 89 mpz_ptr gcd; 90 gcd = (mpz_ptr) omAlloc(sizeof(mpz_t)); 91 mpz_init(gcd); 92 mpz_gcd(gcd, a,b); 93 if(mpz_cmp_ui(gcd, 1) == 0) 94 { 95 WerrorS("constant in qideal is coprime to modulus in ground ring"); 96 WerrorS("Unable to create qring!"); 97 return NULL; 98 } 99 if(mpz_cmp_ui(gcd, 2) == 0) 97 coeffs rr; 98 long ch = r>cfInt(c, r); 99 mpz_t a,b; 100 mpz_init_set(a, r>modNumber); 101 mpz_init_set_ui(b, ch); 102 mpz_ptr gcd; 103 gcd = (mpz_ptr) omAlloc(sizeof(mpz_t)); 104 mpz_init(gcd); 105 mpz_gcd(gcd, a,b); 106 if(mpz_cmp_ui(gcd, 1) == 0) 107 { 108 WerrorS("constant in qideal is coprime to modulus in ground ring"); 109 WerrorS("Unable to create qring!"); 110 return NULL; 111 } 112 if(mpz_cmp_ui(gcd, 2) == 0) 113 { 114 rr = nInitChar(n_Zp, (void*)2); 115 } 116 else 117 { 118 int kNew = 1; 119 mpz_t baseTokNew; 120 mpz_init(baseTokNew); 121 mpz_set(baseTokNew, r>modBase); 122 while(mpz_cmp(gcd, baseTokNew) > 0) 100 123 { 101 rr = nInitChar(n_Zp, (void*)2); 124 kNew++; 125 mpz_mul(baseTokNew, baseTokNew, r>modBase); 102 126 } 103 else 104 { 105 int kNew = 1; 106 mpz_t baseTokNew; 107 mpz_init(baseTokNew); 108 mpz_set(baseTokNew, r>modBase); 109 while(mpz_cmp(gcd, baseTokNew) > 0) 110 { 111 kNew++; 112 mpz_mul(baseTokNew, baseTokNew, r>modBase); 113 } 114 mpz_clear(baseTokNew); 115 rr = nInitChar(n_Z2m, (void*)(long)kNew); 116 } 117 return(rr); 127 mpz_clear(baseTokNew); 128 rr = nInitChar(n_Z2m, (void*)(long)kNew); 129 } 130 return(rr); 118 131 } 119 132 … … 131 144 static number nr2mMult(number a, number b, const coeffs r) 132 145 { 146 number n; 133 147 if (((unsigned long)a == 0)  ((unsigned long)b == 0)) 134 148 return (number)0; 135 149 else 136 return nr2mMultM(a, b, r); 150 n=nr2mMultM(a, b, r); 151 n_Test(n,r); 152 return n; 137 153 } 138 154 … … 340 356 static long nr2mInt(number &n, const coeffs r) 341 357 { 342 unsigned long nn = (unsigned long) (unsigned long)n & r>mod2mMask;358 unsigned long nn = (unsigned long)n; 343 359 unsigned long l = r>mod2mMask >> 1; l++; /* now: l = 2^(m1) */ 344 360 if ((unsigned long)nn > l) … … 350 366 static number nr2mAdd(number a, number b, const coeffs r) 351 367 { 352 return nr2mAddM(a, b, r); 368 number n=nr2mAddM(a, b, r); 369 n_Test(n,r); 370 return n; 353 371 } 354 372 355 373 static number nr2mSub(number a, number b, const coeffs r) 356 374 { 357 return nr2mSubM(a, b, r); 375 number n=nr2mSubM(a, b, r); 376 n_Test(n,r); 377 return n; 358 378 } 359 379 … … 411 431 } 412 432 } 413 return (number)nr2mMult(a, nr2mInversM(b,r),r); 433 number n=(number)nr2mMult(a, nr2mInversM(b,r),r); 434 n_Test(n,r); 435 return n; 414 436 } 415 437 … … 578 600 { 579 601 if ((unsigned long)c == 0) return c; 580 return nr2mNegM(c, r); 602 number n=nr2mNegM(c, r); 603 n_Test(n,r); 604 return n; 581 605 } 582 606 583 607 static number nr2mMapMachineInt(number from, const coeffs /*src*/, const coeffs dst) 584 608 { 585 unsigned long i = ((unsigned long)from) % dst>mod2mMask;609 unsigned long i = ((unsigned long)from) % (dst>mod2mMask + 1) ; 586 610 return (number)i; 587 611 } … … 711 735 WarnS("nr2mInitExp unexpectedly called with m = 1 (we continue with Z/2^2"); 712 736 } 713 714 #ifdef LDEBUG715 static BOOLEAN nr2mDBTest (number a, const char *, const int, const coeffs r)716 {717 //if ((unsigned long)a < 0) return FALSE; // is unsigned!718 if (((unsigned long)a & r>mod2mMask) != (unsigned long)a) return FALSE;719 return TRUE;720 }721 #endif722 737 723 738 static void nr2mWrite (number a, const coeffs r)
Note: See TracChangeset
for help on using the changeset viewer.