1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | /* $Id: cf_char.cc,v 1.8 2008-08-18 10:36:24 Singular Exp $ */ |
---|
3 | |
---|
4 | #include <config.h> |
---|
5 | |
---|
6 | #include "assert.h" |
---|
7 | |
---|
8 | #include "cf_defs.h" |
---|
9 | #include "canonicalform.h" |
---|
10 | #include "imm.h" |
---|
11 | #include "int_pp.h" |
---|
12 | #include "cf_primes.h" |
---|
13 | #include "cf_binom.h" |
---|
14 | |
---|
15 | static int theCharacteristic = 0; |
---|
16 | static int theDegree = 1; |
---|
17 | |
---|
18 | int initializeCharacteristic () |
---|
19 | { |
---|
20 | theCharacteristic = 0; |
---|
21 | theDegree = 1; |
---|
22 | return 1; |
---|
23 | } |
---|
24 | |
---|
25 | void setCharacteristic( int c ) |
---|
26 | { |
---|
27 | if ( c == 0 ) |
---|
28 | { |
---|
29 | theDegree = 0; |
---|
30 | CFFactory::settype( IntegerDomain ); |
---|
31 | theCharacteristic = 0; |
---|
32 | } |
---|
33 | else |
---|
34 | { |
---|
35 | theDegree = 1; |
---|
36 | CFFactory::settype( FiniteFieldDomain ); |
---|
37 | theCharacteristic = c; |
---|
38 | ff_big = c > cf_getSmallPrime( cf_getNumSmallPrimes()-1 ); |
---|
39 | #ifdef SINGULAR |
---|
40 | extern int errorreported; |
---|
41 | void WerrorS(const char *s); |
---|
42 | if (!errorreported && (c > 536870909)) WerrorS("characteristic too large(max is 2^29)"); |
---|
43 | #endif |
---|
44 | ff_setprime( c ); |
---|
45 | resetFPT(); |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | void setCharacteristic( int c, int n ) |
---|
50 | { |
---|
51 | ASSERT( c > 1 && n > 0, "illegal characteristic" ); |
---|
52 | setCharacteristic( c ); |
---|
53 | InternalPrimePower::setPrimePower( c, n ); |
---|
54 | CFFactory::settype( PrimePowerDomain ); |
---|
55 | } |
---|
56 | |
---|
57 | void setCharacteristic( int c, int n, char name ) |
---|
58 | { |
---|
59 | ASSERT( c != 0 && n > 1, "illegal GF(q)" ); |
---|
60 | setCharacteristic( c ); |
---|
61 | gf_setcharacteristic( c, n, name ); |
---|
62 | theDegree = n; |
---|
63 | CFFactory::settype( GaloisFieldDomain ); |
---|
64 | } |
---|
65 | |
---|
66 | int getCharacteristic() |
---|
67 | { |
---|
68 | return theCharacteristic; |
---|
69 | } |
---|
70 | |
---|
71 | int getExp() |
---|
72 | { |
---|
73 | return InternalPrimePower::getk(); |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | int getGFDegree() |
---|
78 | { |
---|
79 | ASSERT( theDegree > 0, "not in GF(q)" ); |
---|
80 | return theDegree; |
---|
81 | } |
---|
82 | |
---|
83 | CanonicalForm getGFGenerator() |
---|
84 | { |
---|
85 | ASSERT( theDegree > 1, "not in GF(q)" ); |
---|
86 | return int2imm_gf( 1 ); |
---|
87 | } |
---|