Changeset 395bff in git
- Timestamp:
- Dec 12, 2016, 6:11:38 PM (7 years ago)
- Branches:
- (u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
- Children:
- 90f715a0b0b2d389f393a20365b7afde7cb4b18c
- Parents:
- 69f579ab8cbfafd79a2045061aa0a279ac135fc5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/coeffs/ffields.cc
r69f579 r395bff 16 16 #include "numbers.h" 17 17 #include "longrat.h" 18 #include "ffields.h" 18 19 19 20 #include <string.h> … … 21 22 #include <errno.h> 22 23 23 BOOLEAN nfGreaterZero (number k, const coeffs r);24 number nfMult (number a, number b, const coeffs r);25 number nfInit (long i, const coeffs r);26 number nfParameter (int i, const coeffs r);27 long nfInt (number &n, const coeffs r);28 number nfAdd (number a, number b, const coeffs r);29 number nfSub (number a, number b, const coeffs r);30 void nfPower (number a, int i, number * result, const coeffs r);31 BOOLEAN nfIsZero (number a, const coeffs r);32 BOOLEAN nfIsOne (number a, const coeffs r);33 BOOLEAN nfIsMOne (number a, const coeffs r);34 number nfDiv (number a, number b, const coeffs r);35 number nfNeg (number c, const coeffs r);36 number nfInvers (number c, const coeffs r);37 BOOLEAN nfGreater (number a, number b, const coeffs r);38 BOOLEAN nfEqual (number a, number b, const coeffs r);39 const char * nfRead (const char *s, number *a, const coeffs r);40 24 #ifdef LDEBUG 41 25 BOOLEAN nfDBTest (number a, const char *f, const int l, const coeffs r); 42 26 #endif 43 //void nfSetChar (const coeffs r);44 45 nMapFunc nfSetMap (const coeffs src, const coeffs dst);46 char * nfName (number n, const coeffs r);47 void nfReadTable (const int c, const coeffs r);48 49 void nfCoeffWrite(const coeffs r, BOOLEAN details);50 void nfShowMipo(const coeffs r);51 52 53 27 54 28 /// Our Type! … … 57 31 //unsigned short *nfPlus1Table=NULL; /* the table i=log(z^i) -> log(z^i+1) */ 58 32 59 const double sixteenlog2= 11.09035489;60 33 /* the q's from the table 'fftable' */ 61 34 const unsigned short fftable[]={ … … 163 136 164 137 /*2 138 * a == 0 ? 139 */ 140 static BOOLEAN nfIsZero (number a, const coeffs r) 141 { 142 #ifdef LDEBUG 143 nfTest(a, r); 144 #endif 145 return (long)r->m_nfCharQ == (long)a; 146 } 147 148 /*2 149 * a == -1 ? 150 */ 151 static BOOLEAN nfIsMOne (number a, const coeffs r) 152 { 153 #ifdef LDEBUG 154 nfTest(a, r); 155 #endif 156 if (0L == (long)a) return FALSE; /* special handling of char 2*/ 157 return (long)r->m_nfM1 == (long)a; 158 } 159 160 /*2 165 161 * k >= 0 ? 166 162 */ 167 BOOLEAN nfGreaterZero (number k, const coeffs r)163 static BOOLEAN nfGreaterZero (number k, const coeffs r) 168 164 { 169 165 #ifdef LDEBUG … … 176 172 * a*b 177 173 */ 178 number nfMult (number a,number b, const coeffs r)174 static number nfMult (number a,number b, const coeffs r) 179 175 { 180 176 #ifdef LDEBUG … … 196 192 * int -> number 197 193 */ 198 number nfInit (long i, const coeffs r)194 static number nfInit (long i, const coeffs r) 199 195 { 200 196 assume( r->m_nfPlus1Table != NULL ); … … 220 216 * the generating element `z` 221 217 */ 222 number nfParameter (int i, const coeffs)218 static number nfParameter (int i, const coeffs) 223 219 { 224 220 assume(i==1); … … 245 241 * number -> int 246 242 */ 247 long nfInt (number &n, const coeffs )243 static long nfInt (number &n, const coeffs ) 248 244 { 249 245 return (long)n; … … 253 249 * a + b 254 250 */ 255 number nfAdd (number a, number b, const coeffs R)251 static number nfAdd (number a, number b, const coeffs R) 256 252 { 257 253 /*4 z^a+z^b=z^b*(z^(a-b)+1), if a>=b; * … … 290 286 291 287 /*2 288 * -c 289 */ 290 static number nfNeg (number c, const coeffs r) 291 { 292 /*4 -z^c=z^c*(-1)=z^c*nfM1*/ 293 #ifdef LDEBUG 294 nfTest(c, r); 295 #endif 296 if ((long)r->m_nfCharQ == (long)c) return c; 297 long i=(long)c+(long)r->m_nfM1; 298 if (i>=(long)r->m_nfCharQ1) i-=(long)r->m_nfCharQ1; 299 #ifdef LDEBUG 300 nfTest((number)i, r); 301 #endif 302 return (number)i; 303 } 304 305 /*2 292 306 * a - b 293 307 */ 294 number nfSub (number a, number b, const coeffs r)308 static number nfSub (number a, number b, const coeffs r) 295 309 { 296 310 number mb = nfNeg(b, r); … … 299 313 300 314 /*2 301 * a == 0?302 */ 303 BOOLEAN nfIsZero (numbera, const coeffs r)315 * a == 1 ? 316 */ 317 static BOOLEAN nfIsOne (number a, const coeffs r) 304 318 { 305 319 #ifdef LDEBUG 306 320 nfTest(a, r); 307 321 #endif 308 return (long)r->m_nfCharQ == (long)a;309 }310 311 /*2312 * a == 1 ?313 */314 BOOLEAN nfIsOne (number a, const coeffs r)315 {316 #ifdef LDEBUG317 nfTest(a, r);318 #endif319 322 return 0L == (long)a; 320 323 } 321 324 322 325 /*2 323 * a == -1 ?324 */325 BOOLEAN nfIsMOne (number a, const coeffs r)326 {327 #ifdef LDEBUG328 nfTest(a, r);329 #endif330 if (0L == (long)a) return FALSE; /* special handling of char 2*/331 return (long)r->m_nfM1 == (long)a;332 }333 334 /*2335 326 * a / b 336 327 */ 337 number nfDiv (number a,number b, const coeffs r)328 static number nfDiv (number a,number b, const coeffs r) 338 329 { 339 330 #ifdef LDEBUG … … 363 354 * 1 / c 364 355 */ 365 number nfInvers (number c, const coeffs r)356 static number nfInvers (number c, const coeffs r) 366 357 { 367 358 #ifdef LDEBUG … … 380 371 381 372 /*2 382 * -c383 */384 number nfNeg (number c, const coeffs r)385 {386 /*4 -z^c=z^c*(-1)=z^c*nfM1*/387 #ifdef LDEBUG388 nfTest(c, r);389 #endif390 if ((long)r->m_nfCharQ == (long)c) return c;391 long i=(long)c+(long)r->m_nfM1;392 if (i>=(long)r->m_nfCharQ1) i-=(long)r->m_nfCharQ1;393 #ifdef LDEBUG394 nfTest((number)i, r);395 #endif396 return (number)i;397 }398 399 /*2400 373 * a > b ? 401 374 */ 402 BOOLEAN nfGreater (number a,number b, const coeffs r)375 static BOOLEAN nfGreater (number a,number b, const coeffs r) 403 376 { 404 377 #ifdef LDEBUG … … 412 385 * a == b ? 413 386 */ 414 BOOLEAN nfEqual (number a,number b, const coeffs r)387 static BOOLEAN nfEqual (number a,number b, const coeffs r) 415 388 { 416 389 #ifdef LDEBUG … … 465 438 466 439 /*2 467 *468 */469 char * nfName(number a, const coeffs r)470 {471 #ifdef LDEBUG472 nfTest(a, r);473 #endif474 char *s;475 const char * const nf_Parameter=n_ParameterNames(r)[0];476 if (((long)a==(long)r->m_nfCharQ) || ((long)a==0L)) return NULL;477 else if ((long)a==1L)478 {479 return omStrDup(nf_Parameter);480 }481 else482 {483 s=(char *)omAlloc(4+strlen(nf_Parameter));484 sprintf(s,"%s%d",nf_Parameter,(int)((long)a));485 }486 return s;487 }488 /*2489 440 * c ^ i with i>=0 490 441 */ 491 void nfPower (number a, int i, number * result, const coeffs r)442 static void nfPower (number a, int i, number * result, const coeffs r) 492 443 { 493 444 #ifdef LDEBUG … … 538 489 * read a number 539 490 */ 540 const char * nfRead (const char *s, number *a, const coeffs r)491 static const char * nfRead (const char *s, number *a, const coeffs r) 541 492 { 542 493 int i; … … 575 526 } 576 527 577 int gf_tab_numdigits62 ( int q ); 578 int convertback62 ( char * p, int n ); 579 580 int nfMinPoly[16];528 int gf_tab_numdigits62 ( int q ); /*factory/gf_tabitil.cc */ 529 int convertback62 ( char * p, int n ); /*factory/gf_tabitil.cc */ 530 531 static int nfMinPoly[16]; 581 532 582 533 void nfShowMipo(const coeffs r) … … 621 572 * init global variables from files 'gftables/%d' 622 573 */ 623 void nfReadTable(const int c, const coeffs r)574 static void nfReadTable(const int c, const coeffs r) 624 575 { 625 576 //Print("GF(%d)\n",c); … … 721 672 * map Z/p -> GF(p,n) 722 673 */ 723 number nfMapP(number c, const coeffs, const coeffs dst)674 static number nfMapP(number c, const coeffs, const coeffs dst) 724 675 { 725 676 return nfInit((int)((long)c), dst); … … 729 680 * map GF(p,n1) -> GF(p,n2), n1 < n2, n1 | n2 730 681 */ 731 int nfMapGG_factor;732 number nfMapGG(number c, const coeffs src, const coeffs)682 static int nfMapGG_factor; 683 static number nfMapGG(number c, const coeffs src, const coeffs) 733 684 { 734 685 int i=(long)c; … … 740 691 * map GF(p,n1) -> GF(p,n2), n1 > n2, n2 | n1 741 692 */ 742 number nfMapGGrev(number c, const coeffs src, const coeffs)693 static number nfMapGGrev(number c, const coeffs src, const coeffs) 743 694 { 744 695 int ex=(int)((long)c); … … 752 703 * set map function nMap ... -> GF(p,n) 753 704 */ 754 nMapFunc nfSetMap(const coeffs src, const coeffs dst)705 static nMapFunc nfSetMap(const coeffs src, const coeffs dst) 755 706 { 756 707 if (nCoeff_is_GF(src,src->m_nfCharQ)) … … 841 792 } 842 793 794 static void nfCoeffWrite (const coeffs r, BOOLEAN details) 795 { 796 // m_nfCharQ = p^k where p is the characteristic (r->CharP) and k is GFDegree 797 Print("ZZ/%d[%s]",r->m_nfCharQ,n_ParameterNames(r)[0]); 798 if ( details ) 799 { 800 StringSetS("\n// minpoly : "); 801 nfShowMipo(r); 802 StringAppendS(""); 803 char *s=StringEndS(); PrintS(s); omFree(s); 804 } 805 else PrintS("// minpoly : ..."); 806 } 807 808 static BOOLEAN nfCoeffIsEqual (const coeffs r, n_coeffType n, void * parameter) 809 { 810 if (n==n_GF) { 811 GFInfo* p = (GFInfo *)(parameter); 812 int c = pow (p->GFChar, p->GFDegree); 813 if ((c == r->m_nfCharQ) && (strcmp(n_ParameterNames(r)[0], p->GFPar_name) == 0)) 814 return TRUE; 815 } 816 return FALSE; 817 } 843 818 BOOLEAN nfInitChar(coeffs r, void * parameter) 844 819 { … … 948 923 const double check= log ((double) (p->GFChar)); 949 924 925 static const double sixteenlog2= 11.09035489; 950 926 if( (p->GFDegree * check) > sixteenlog2 ) 951 927 { … … 975 951 } 976 952 977 void nfCoeffWrite (const coeffs r, BOOLEAN details)978 {979 // m_nfCharQ = p^k where p is the characteristic (r->CharP) and k is GFDegree980 Print("ZZ/%d[%s]",r->m_nfCharQ,n_ParameterNames(r)[0]);981 if ( details )982 {983 StringSetS("\n// minpoly : ");984 nfShowMipo(r);985 StringAppendS("");986 char *s=StringEndS(); PrintS(s); omFree(s);987 }988 else PrintS("// minpoly : ...");989 }990 991 static BOOLEAN nfCoeffIsEqual (const coeffs r, n_coeffType n, void * parameter)992 {993 if (n==n_GF) {994 GFInfo* p = (GFInfo *)(parameter);995 int c = pow (p->GFChar, p->GFDegree);996 if ((c == r->m_nfCharQ) && (strcmp(n_ParameterNames(r)[0], p->GFPar_name) == 0))997 return TRUE;998 }999 return FALSE;1000 }
Note: See TracChangeset
for help on using the changeset viewer.