Changeset 94b759 in git
- Timestamp:
- Apr 30, 2010, 7:26:10 PM (13 years ago)
- Branches:
- (u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
- Children:
- 6ce7579378e276236fc3dfffd7b704449b1e306a
- Parents:
- 97d8a41a15dadbaebb9ddaa1705f32a135ccb013
- git-author:
- Oleksandr Motsak <motsak@mathematik.uni-kl.de>2010-04-30 19:26:10+02:00
- git-committer:
- Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 11:50:24+01:00
- Location:
- coeffs
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
coeffs/coeffs.h
r97d8a4 r94b759 15 15 #define NULL (0) 16 16 #endif 17 18 // #ifdef _TRY 19 #ifndef ABS 20 #define ABS(x) ((x)<0?(-(x)):(x)) 21 #endif 22 // #endif 23 24 17 25 18 26 #if (SIZEOF_LONG == 8) … … 83 91 struct snumber; 84 92 typedef struct snumber * number; 85 typedef number (*numberfunc)(number a,number b, const coeffs r); 86 typedef number (*nMapFunc)(number a, const coeffs r); 87 88 #define _TRY 93 typedef number (*numberfunc)(number a, number b, const coeffs r); 94 95 /// maps "a" from aRing into r 96 typedef number (*nMapFunc)(number a, const coeffs r, const coeffs aRing); 97 98 // #define _TRY 89 99 90 100 #ifdef _TRY … … 114 124 #endif 115 125 // Zp_a, Q_a 126 // ? 116 127 117 128 // general stuff … … 192 203 short float_len; /* additional char-flags, rInit */ 193 204 short float_len2; /* additional char-flags, rInit */ 194 195 205 }; 196 206 207 /// Returns the type of coeffs domain 208 static inline n_coeffType getCoeffType(const coeffs r) 209 { 210 return r->type; 211 } 212 197 213 #define nInternalChar(r) ((r)->ch) 198 214 -
coeffs/gnumpc.cc
r97d8a4 r94b759 19 19 #include "omalloc.h" 20 20 21 extern size_t gmp_output_digits; 22 23 24 number ngcMapQ(number from, const coeffs) 25 { 21 22 #ifdef LDEBUG 23 // not yet implemented 24 BOOLEAN ngcDBTest(number a, const char *f, const int l, const coeffs r) 25 { 26 assume( getCoeffType(r) == ID ); 27 28 return TRUE; 29 } 30 #endif 31 32 #ifndef assume 33 # define assume(a) if(!(a)){ Werror( "Assumption: is wrong: %s\n", #a ); }; 34 #endif 35 36 const n_coeffType ID = n_long_C; 37 38 number ngcMapQ(number from, const coeffs r, const coeffs aRing) 39 { 40 assume( getCoeffType(r) == ID ); 41 assume( getCoeffType(aRing) == n_Q ); 42 26 43 if ( from != NULL ) 27 44 { … … 32 49 return NULL; 33 50 } 34 union nf 35 { 36 float _f; 37 number _n; 38 nf(float f) {_f = f;} 39 nf(number n) {_n = n;} 40 float F() const {return _f;} 41 number N() const {return _n;} 42 }; 43 static number ngcMapLongR(number from, const coeffs) 44 { 51 52 static number ngcMapLongR(number from, const coeffs r, const coeffs aRing) 53 { 54 assume( getCoeffType(r) == ID ); 55 assume( getCoeffType(aRing) == n_long_R ); 56 45 57 if ( from != NULL ) 46 58 { … … 51 63 return NULL; 52 64 } 53 static number ngcMapR(number from, const coeffs) 54 { 65 66 static number ngcMapR(number from, const coeffs r, const coeffs aRing) 67 { 68 assume( getCoeffType(r) == ID ); 69 assume( getCoeffType(aRing) == n_R ); 70 71 union nf 72 { 73 float _f; 74 number _n; 75 nf(float f) {_f = f;} 76 nf(number n) {_n = n;} 77 float F() const {return _f;} 78 number N() const {return _n;} 79 }; 80 55 81 if ( from != NULL ) 56 82 { … … 61 87 return NULL; 62 88 } 63 extern ring ngfMapRing; 64 static number ngcMapP(number from, const coeffs) 65 { 89 90 static number ngcMapP(number from, const coeffs r, const coeffs aRing) 91 { 92 assume( getCoeffType(r) == ID ); 93 assume( getCoeffType(aRing) == n_Zp ); 94 66 95 if ( from != NULL) 67 return ngcInit(npInt(from, ngfMapRing), currRing);96 return ngcInit(npInt(from, aRing), r); 68 97 else 69 98 return NULL; 70 99 } 71 100 72 nMapFunc ngcSetMap(const coeffs src,const coeffs dst) 73 { 74 if(rField_is_Q(src)) 101 102 103 static number ngcCopyMap(number from, const coeffs r, const coeffs aRing) 104 { 105 assume( getCoeffType(r) == ID ); 106 assume( getCoeffType(aRing) == ID ); 107 108 gmp_complex* b = NULL; 109 110 if ( from != NULL ) 111 { 112 b = new gmp_complex( *(gmp_complex*)from ); 113 } 114 return (number)b; 115 } 116 117 nMapFunc ngcSetMap(const coeffs src/*, const coeffs dst */) 118 { 119 // assume( getCoeffType(dst) == ID ); 120 121 if(nField_is_Q(src)) 75 122 { 76 123 return ngcMapQ; 77 124 } 78 if ( rField_is_long_R(src))125 if (nField_is_long_R(src)) 79 126 { 80 127 return ngcMapLongR; 81 128 } 82 if ( rField_is_long_C(src))83 { 84 return ngcCopy ;85 } 86 if( rField_is_R(src))129 if (nField_is_long_C(src)) 130 { 131 return ngcCopyMap; 132 } 133 if(nField_is_R(src)) 87 134 { 88 135 return ngcMapR; 89 136 } 90 if (rField_is_Zp(src)) 91 { 92 ngfMapRing=src; 137 if (nField_is_Zp(src)) 138 { 93 139 return ngcMapP; 94 140 } … … 96 142 } 97 143 98 number ngcPar(int i) 99 { 144 145 146 number ngcPar(int i, const coeffs r) 147 { 148 assume( getCoeffType(r) == ID ); 149 100 150 gmp_complex* n= new gmp_complex( (long)0, (long)1 ); 101 151 return (number)n; … … 107 157 number ngcInit (int i, const coeffs r) 108 158 { 159 assume( getCoeffType(r) == ID ); 160 109 161 gmp_complex* n= new gmp_complex( (long)i, (long)0 ); 162 110 163 return (number)n; 111 164 } … … 116 169 int ngcInt(number &i, const coeffs r) 117 170 { 171 assume( getCoeffType(r) == ID ); 172 118 173 return (int)((gmp_complex*)i)->real(); 119 174 } … … 139 194 void ngcDelete (number * a, const coeffs r) 140 195 { 196 assume( getCoeffType(r) == ID ); 197 141 198 if ( *a != NULL ) 142 199 { … … 149 206 * copy a to b 150 207 */ 151 number ngcCopy(number a, const coeffs) 152 { 208 number ngcCopy(number a, const coeffs r) 209 { 210 assume( getCoeffType(r) == ID ); 211 153 212 gmp_complex* b= new gmp_complex( *(gmp_complex*)a ); 154 213 return (number)b; 155 214 } 156 number ngc_Copy(number a, const coeffs r) 157 { 158 gmp_complex* b=new gmp_complex( *(gmp_complex*)a ); 159 return (number)b; 160 } 215 161 216 162 217 /*2 163 218 * za:= - za 164 219 */ 165 gmp_complex ngc_m1(-1); 166 167 number ngcNeg (number a, const coeffs) 168 { 220 number ngcNeg (number a, const coeffs R) 221 { 222 assume( getCoeffType(R) == ID ); 223 169 224 gmp_complex* r=(gmp_complex*)a; 170 225 (*r) *= ngc_m1; … … 175 230 * 1/a 176 231 */ 177 number ngcInvers(number a, const coeffs) 178 { 232 number ngcInvers(number a, const coeffs R) 233 { 234 assume( getCoeffType(R) == ID ); 235 179 236 gmp_complex* r = NULL; 180 237 if (((gmp_complex*)a)->isZero()) … … 184 241 else 185 242 { 186 r= new gmp_complex( (gmp_complex)1 / (*(gmp_complex*)a) );187 } 188 return (number) r;243 b = new gmp_complex( (gmp_complex)1 / (*(gmp_complex*)a) ); 244 } 245 return (number)b; 189 246 } 190 247 … … 192 249 * u:= a + b 193 250 */ 194 number ngcAdd (number a, number b, const coeffs) 195 { 251 number ngcAdd (number a, number b, const coeffs R) 252 { 253 assume( getCoeffType(R) == ID ); 254 196 255 gmp_complex* r= new gmp_complex( (*(gmp_complex*)a) + (*(gmp_complex*)b) ); 197 256 return (number)r; … … 203 262 number ngcSub (number a, number b, const coeffs R) 204 263 { 264 assume( getCoeffType(R) == ID ); 265 205 266 gmp_complex* r= new gmp_complex( (*(gmp_complex*)a) - (*(gmp_complex*)b) ); 206 267 return (number)r; … … 210 271 * u := a * b 211 272 */ 212 number ngcMult (number a, number b) 213 { 273 number ngcMult (number a, number b, const coeffs R) 274 { 275 assume( getCoeffType(R) == ID ); 276 214 277 gmp_complex* r= new gmp_complex( (*(gmp_complex*)a) * (*(gmp_complex*)b) ); 215 278 return (number)r; … … 219 282 * u := a / b 220 283 */ 221 number ngcDiv (number a, number b, const coeffs) 222 { 284 number ngcDiv (number a, number b, const coeffs r) 285 { 286 assume( getCoeffType(r) == ID ); 287 223 288 if (((gmp_complex*)b)->isZero()) 224 289 { … … 227 292 return NULL; 228 293 } 229 gmp_complex* r = new gmp_complex( (*(gmp_complex*)a) / (*(gmp_complex*)b) );230 return (number)r ;294 gmp_complex* res = new gmp_complex( (*(gmp_complex*)a) / (*(gmp_complex*)b) ); 295 return (number)res; 231 296 } 232 297 … … 234 299 * u:= x ^ exp 235 300 */ 236 void ngcPower ( number x, int exp, number * u, const coeffs R) 237 { 301 void ngcPower ( number x, int exp, number * u, const coeffs r) 302 { 303 assume( getCoeffType(r) == ID ); 304 238 305 if ( exp == 0 ) 239 306 { … … 244 311 else if ( exp == 1 ) 245 312 { 246 n New(u);313 n_New(u, r); 247 314 gmp_complex* n = new gmp_complex(); 248 315 *n= *(gmp_complex*)x; … … 252 319 else if (exp == 2) 253 320 { 254 n New(u);321 n_New(u, r); 255 322 gmp_complex* n = new gmp_complex(); 256 323 *n= *(gmp_complex*)x; … … 261 328 if (exp&1==1) 262 329 { 263 ngcPower(x,exp-1,u, R);264 gmp_complex *n =new gmp_complex();330 ngcPower(x,exp-1,u, r); 331 gmp_complex *n = new gmp_complex(); 265 332 *n=*(gmp_complex*)x; 266 333 *(gmp_complex*)(*u) *= *(gmp_complex*)n; … … 270 337 { 271 338 number w; 272 nNew(&w); 273 ngcPower(x,exp/2,&w, R); 274 ngcPower(w,2,u, R); 275 nDelete(&w); 276 } 277 } 278 279 BOOLEAN ngcIsZero (number a, const coeffs) 280 { 339 n_New(&w, r); 340 ngcPower(x,exp/2,&w, r); 341 ngcPower(w,2,u, r); 342 n_Delete(&w, r); 343 } 344 } 345 346 BOOLEAN ngcIsZero (number a, const coeffs r) 347 { 348 assume( getCoeffType(r) == ID ); 349 281 350 return ( ((gmp_complex*)a)->real().isZero() && ((gmp_complex*)a)->imag().isZero()); 282 351 } 283 352 284 number ngcRePart(number a, const coeffs) 285 { 353 number ngcRePart(number a, const coeffs r) 354 { 355 assume( getCoeffType(r) == ID ); 356 286 357 gmp_complex* n = new gmp_complex(((gmp_complex*)a)->real()); 287 358 return (number)n; 288 359 } 289 360 290 number ngcImPart(number a, const coeffs) 291 { 361 number ngcImPart(number a, const coeffs r) 362 { 363 assume( getCoeffType(r) == ID ); 364 292 365 gmp_complex* n = new gmp_complex(((gmp_complex*)a)->imag()); 293 366 return (number)n; … … 297 370 * za >= 0 ? 298 371 */ 299 BOOLEAN ngcGreaterZero (number a, const coeffs) 300 { 372 BOOLEAN ngcGreaterZero (number a, const coeffs r) 373 { 374 assume( getCoeffType(r) == ID ); 375 301 376 if ( ! ((gmp_complex*)a)->imag().isZero() ) 302 377 return ( abs( *(gmp_complex*)a).sign() >= 0 ); … … 308 383 * a > b ? 309 384 */ 310 BOOLEAN ngcGreater (number a, number b, const coeffs) 311 { 385 BOOLEAN ngcGreater (number a, number b, const coeffs r) 386 { 387 assume( getCoeffType(r) == ID ); 388 312 389 gmp_complex *aa=(gmp_complex*)a; 313 390 gmp_complex *bb=(gmp_complex*)b; … … 318 395 * a = b ? 319 396 */ 320 BOOLEAN ngcEqual (number a, number b, const coeffs) 321 { 397 BOOLEAN ngcEqual (number a, number b, const coeffs r) 398 { 399 assume( getCoeffType(r) == ID ); 400 322 401 gmp_complex *aa=(gmp_complex*)a; 323 402 gmp_complex *bb=(gmp_complex*)b; … … 328 407 * a == 1 ? 329 408 */ 330 BOOLEAN ngcIsOne (number a, const coeffs) 331 { 409 BOOLEAN ngcIsOne (number a, const coeffs r) 410 { 411 assume( getCoeffType(r) == ID ); 412 332 413 return (((gmp_complex*)a)->real().isOne() && ((gmp_complex*)a)->imag().isZero()); 333 414 //return (((gmp_complex*)a)->real().isOne()); … … 337 418 * a == -1 ? 338 419 */ 339 BOOLEAN ngcIsMOne (number a, const coeffs) 340 { 420 BOOLEAN ngcIsMOne (number a, const coeffs r) 421 { 422 assume( getCoeffType(r) == ID ); 423 341 424 return (((gmp_complex*)a)->real().isMOne() && ((gmp_complex*)a)->imag().isZero()); 342 425 //return (((gmp_complex*)a)->real().isMOne()); … … 346 429 * extracts the number a from s, returns the rest 347 430 */ 348 const char * ngcRead (const char * s, number * a, const coeffs R) 349 { 431 const char * ngcRead (const char * s, number * a, const coeffs r) 432 { 433 assume( getCoeffType(r) == ID ); 434 350 435 if ((*s >= '0') && (*s <= '9')) 351 436 { 352 437 gmp_float *re=NULL; 353 s=ngfRead(s,(number *)&re, R);438 s=ngfRead(s,(number *)&re, r); 354 439 gmp_complex *aa=new gmp_complex(*re); 355 440 *a=(number)aa; 356 441 delete re; 357 442 } 358 else if (strncmp(s, currRing->parameter[0],strlen(currRing->parameter[0]))==0)359 { 360 s+=strlen( currRing->parameter[0]);443 else if (strncmp(s, r->parameter[0],strlen(r->parameter[0]))==0) 444 { 445 s+=strlen(r->parameter[0]); 361 446 gmp_complex *aa=new gmp_complex((long)0,(long)1); 362 447 *a=(number)aa; … … 369 454 } 370 455 456 457 371 458 /*2 372 459 * write a floating point number … … 374 461 void ngcWrite (number &a, const coeffs r) 375 462 { 463 assume( getCoeffType(r) == ID ); 464 465 extern size_t gmp_output_digits; /// comes from mpr_complex.cc 466 376 467 if (a==NULL) 377 468 StringAppendS("0"); … … 379 470 { 380 471 char *out; 381 out= complexToStr(*(gmp_complex*)a, gmp_output_digits);472 out= complexToStr(*(gmp_complex*)a, gmp_output_digits); 382 473 StringAppendS(out); 383 474 // omFreeSize((void *)out, (strlen(out)+1)* sizeof(char) ); … … 385 476 } 386 477 } 387 388 #ifdef LDEBUG389 // not yet implemented390 //BOOLEAN ngcDBTest(number a, const char *f, const int l)391 //{392 // return TRUE;393 //}394 #endif395 478 396 479 // local Variables: *** -
coeffs/gnumpc.h
r97d8a4 r94b759 26 26 number ngcDiv(number a, number b, const coeffs r); 27 27 void ngcPower(number x, int exp, number *lu, const coeffs r); 28 number ngcCopy(number a, const coeffs );28 number ngcCopy(number a, const coeffs r); 29 29 number ngc_Copy(number a, coeffs r); 30 30 const char * ngcRead (const char *s, number *a, const coeffs r); … … 33 33 number ngcImPart(number a, const coeffs r); 34 34 35 void ngcDelete(number *a, const coeffs r); 35 36 36 37 #ifdef LDEBUG 37 BOOLEAN ngcDBTest(number a, const char *f, const int l, const coeffs );38 BOOLEAN ngcDBTest(number a, const char *f, const int l, const coeffs r); 38 39 #endif 39 void ngcDelete(number *a, const coeffs r);40 40 41 nMapFunc ngcSetMap(const coeffs src, const coeffs dst); 41 /// Get a mapping function from src into this domain: long_C 42 /// no need in dst!? 43 nMapFunc ngcSetMap(const coeffs src/*, const coeffs dst*/); 42 44 43 number ngcMapQ(number from, const coeffs r); 45 // Why is this here? who needs it? 46 // number ngcMapQ(number from, const coeffs r, const coeffs aRing); 44 47 #endif 45 48 -
coeffs/numbers.h
r97d8a4 r94b759 51 51 52 52 #define nTest(a) (1) 53 #define nDelete(A) (currRing)->cf->cfDelete(A,currRing) 54 #define nGetDenom(N) (currRing->cf->cfGetDenom((N),currRing)) 55 #define nGetNumerator(N) (currRing->cf->cfGetNumerator((N),currRing)) 53 54 // please use n_* counterparts instead!!! 55 // #define nDelete(A) (currRing)->cf->cfDelete(A,currRing) 56 // #define nGetDenom(N) (currRing->cf->cfGetDenom((N),currRing)) 57 // #define nGetNumerator(N) (currRing->cf->cfGetNumerator((N),currRing)) 58 56 59 57 60 #define nSetMap(R) (currRing->cf->cfSetMap(R,currRing)) … … 107 110 108 111 #ifdef _TRY 109 #ifndef ABS110 #define ABS(x) ((x)<0?(-(x)):(x))111 #endif112 #endif113 114 115 116 #ifdef _TRY117 112 #define rField_is_Q(r) nField_is_Q(r) 118 113 #define rField_is_long_R(r) nField_is_long_R(r)
Note: See TracChangeset
for help on using the changeset viewer.