[493c477] | 1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
[2dd068] | 2 | |
---|
[abddbe] | 3 | /** |
---|
| 4 | * @file cf_char.cc |
---|
| 5 | * |
---|
| 6 | * getting and setting the characteristic of a finite field |
---|
| 7 | **/ |
---|
[9f7665] | 8 | |
---|
[e4fe2b] | 9 | #include "config.h" |
---|
[9f7665] | 10 | |
---|
[cc1367] | 11 | |
---|
[650f2d8] | 12 | #include "cf_assert.h" |
---|
[cc1367] | 13 | |
---|
[2dd068] | 14 | #include "cf_defs.h" |
---|
| 15 | #include "canonicalform.h" |
---|
| 16 | #include "imm.h" |
---|
[e82860] | 17 | #include "cf_primes.h" |
---|
[a41f4b6] | 18 | #include "cf_util.h" |
---|
[e73082] | 19 | #include "int_pp.h" |
---|
[2dd068] | 20 | |
---|
[7fdedf] | 21 | #ifdef HAVE_FLINT |
---|
| 22 | #include "FLINTconvert.h" // for __FLINT_RELEASE |
---|
| 23 | #endif |
---|
| 24 | |
---|
[a3f0fea] | 25 | STATIC_VAR int theCharacteristic = 0; |
---|
| 26 | STATIC_VAR int theDegree = 1; |
---|
[2dd068] | 27 | |
---|
| 28 | void setCharacteristic( int c ) |
---|
| 29 | { |
---|
[d09118] | 30 | if ( c == 0 ) |
---|
| 31 | { |
---|
| 32 | theDegree = 0; |
---|
| 33 | CFFactory::settype( IntegerDomain ); |
---|
| 34 | theCharacteristic = 0; |
---|
[2dd068] | 35 | } |
---|
[d09118] | 36 | else |
---|
| 37 | { |
---|
| 38 | theDegree = 1; |
---|
| 39 | CFFactory::settype( FiniteFieldDomain ); |
---|
| 40 | ff_big = c > cf_getSmallPrime( cf_getNumSmallPrimes()-1 ); |
---|
[35a153] | 41 | if (c!=theCharacteristic) |
---|
| 42 | { |
---|
| 43 | if (c > 536870909) factoryError("characteristic is too large(max is 2^29)"); |
---|
| 44 | ff_setprime( c ); |
---|
| 45 | } |
---|
| 46 | theCharacteristic = c; |
---|
[2dd068] | 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
[7fdedf] | 50 | #if !defined(HAVE_NTL) |
---|
[e73082] | 51 | void setCharacteristic( int c, int n ) |
---|
| 52 | { |
---|
| 53 | ASSERT( c > 1 && n > 0, "illegal characteristic" ); |
---|
| 54 | setCharacteristic( c ); |
---|
| 55 | InternalPrimePower::setPrimePower( c, n ); |
---|
| 56 | CFFactory::settype( PrimePowerDomain ); |
---|
| 57 | } |
---|
| 58 | #endif |
---|
| 59 | |
---|
| 60 | |
---|
[2dd068] | 61 | void setCharacteristic( int c, int n, char name ) |
---|
| 62 | { |
---|
| 63 | ASSERT( c != 0 && n > 1, "illegal GF(q)" ); |
---|
| 64 | setCharacteristic( c ); |
---|
| 65 | gf_setcharacteristic( c, n, name ); |
---|
| 66 | theDegree = n; |
---|
| 67 | CFFactory::settype( GaloisFieldDomain ); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | int getCharacteristic() |
---|
| 71 | { |
---|
| 72 | return theCharacteristic; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | int getGFDegree() |
---|
| 76 | { |
---|
[050d1b] | 77 | //ASSERT( theDegree > 0, "not in GF(q)" ); |
---|
[2dd068] | 78 | return theDegree; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | CanonicalForm getGFGenerator() |
---|
| 82 | { |
---|
| 83 | ASSERT( theDegree > 1, "not in GF(q)" ); |
---|
| 84 | return int2imm_gf( 1 ); |
---|
| 85 | } |
---|