1 | #ifndef COEFFS_H |
---|
2 | #define COEFFS_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* $Id$ */ |
---|
7 | /* |
---|
8 | * ABSTRACT |
---|
9 | */ |
---|
10 | |
---|
11 | #define TRUE 1 |
---|
12 | #define FALSE 0 |
---|
13 | |
---|
14 | #ifndef NULL |
---|
15 | #define NULL (0) |
---|
16 | #endif |
---|
17 | |
---|
18 | // #ifdef _TRY |
---|
19 | #ifndef ABS |
---|
20 | #define ABS(x) ((x)<0?(-(x)):(x)) |
---|
21 | #endif |
---|
22 | // #endif |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | #if (SIZEOF_LONG == 8) |
---|
27 | typedef int BOOLEAN; |
---|
28 | /* testet on x86_64, gcc 3.4.6: 2 % */ |
---|
29 | /* testet on IA64, gcc 3.4.6: 1 % */ |
---|
30 | #else |
---|
31 | /* testet on athlon, gcc 2.95.4: 1 % */ |
---|
32 | typedef short BOOLEAN; |
---|
33 | #endif |
---|
34 | #define loop for(;;) |
---|
35 | |
---|
36 | #if defined(SI_CPU_I386) || defined(SI_CPU_X86_64) |
---|
37 | // the following settings seems to be better on i386 and x86_64 processors |
---|
38 | // define if a*b is with mod instead of tables |
---|
39 | #define HAVE_MULT_MOD |
---|
40 | // #define HAVE_GENERIC_ADD |
---|
41 | // #ifdef HAVE_MULT_MOD |
---|
42 | // #define HAVE_DIV_MOD |
---|
43 | // #endif |
---|
44 | #elif defined(SI_CPU_IA64) |
---|
45 | // the following settings seems to be better on itanium processors |
---|
46 | // #define HAVE_MULT_MOD |
---|
47 | #define HAVE_GENERIC_ADD |
---|
48 | // #ifdef HAVE_MULT_MOD |
---|
49 | // #define HAVE_DIV_MOD |
---|
50 | // #endif |
---|
51 | #elif defined(SI_CPU_SPARC) |
---|
52 | // #define HAVE_GENERIC_ADD |
---|
53 | #define HAVE_MULT_MOD |
---|
54 | #ifdef HAVE_MULT_MOD |
---|
55 | #define HAVE_DIV_MOD |
---|
56 | #endif |
---|
57 | #elif defined(SI_CPU_PPC) |
---|
58 | // the following settings seems to be better on ppc processors |
---|
59 | // testet on: ppc_Linux, 740/750 PowerMac G3, 512k L2 cache |
---|
60 | #define HAVE_MULT_MOD |
---|
61 | // #ifdef HAVE_MULT_MOD |
---|
62 | // #define HAVE_DIV_MOD |
---|
63 | // #endif |
---|
64 | #endif |
---|
65 | |
---|
66 | enum n_coeffType |
---|
67 | { |
---|
68 | n_unknown=0, |
---|
69 | n_Zp, |
---|
70 | n_Q, |
---|
71 | n_R, |
---|
72 | n_GF, |
---|
73 | n_long_R, |
---|
74 | n_Zp_a, |
---|
75 | n_Q_a, |
---|
76 | n_long_C, |
---|
77 | // only used if HAVE_RINGS is defined |
---|
78 | n_Z, |
---|
79 | n_Zm, |
---|
80 | n_Zpn, |
---|
81 | n_Z2n |
---|
82 | }; |
---|
83 | |
---|
84 | struct n_Procs_s; |
---|
85 | typedef struct n_Procs_s n_Procs_s; |
---|
86 | typedef struct n_Procs_s *coeffs; |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | struct snumber; |
---|
91 | typedef struct snumber * number; |
---|
92 | typedef number (*numberfunc)(number a, number b, const coeffs r); |
---|
93 | |
---|
94 | /// maps "a" from aRing into r |
---|
95 | typedef number (*nMapFunc)(number a, const coeffs r, const coeffs aRing); |
---|
96 | |
---|
97 | // #define _TRY |
---|
98 | |
---|
99 | #ifdef _TRY |
---|
100 | typedef coeffs ring; |
---|
101 | |
---|
102 | extern ring currRing; |
---|
103 | #endif |
---|
104 | |
---|
105 | struct n_Procs_s |
---|
106 | { |
---|
107 | #ifdef _TRY |
---|
108 | ring cf; // this |
---|
109 | #endif |
---|
110 | |
---|
111 | coeffs next; |
---|
112 | n_coeffType fieldtype; |
---|
113 | unsigned int ringtype; /* 0 => coefficient field, 1 => coeffs from Z/2^m */ |
---|
114 | |
---|
115 | // the union stuff |
---|
116 | |
---|
117 | // Zp: |
---|
118 | int npPrimeM; |
---|
119 | int npPminus1M; |
---|
120 | #ifdef HAVE_DIV_MOD |
---|
121 | unsigned short *npInvTable; |
---|
122 | #endif |
---|
123 | #if !defined(HAVE_DIV_MOD) || !defined(HAVE_MULT_MOD) |
---|
124 | unsigned short *npExpTable; |
---|
125 | unsigned short *npLogTable; |
---|
126 | #endif |
---|
127 | // Zp_a, Q_a |
---|
128 | // ? |
---|
129 | // initialisation: |
---|
130 | void (*cfInitChar)(coeffs r); // do one-time initialisations |
---|
131 | void (*cfKillChar)(coeffs r); // undo all initialisations |
---|
132 | // or NULL |
---|
133 | void (*cfSetChar)(coeffs r); // initialisations after each ring change |
---|
134 | // or NULL |
---|
135 | // general stuff |
---|
136 | numberfunc nMult, nSub ,nAdd ,nDiv, nIntDiv, nIntMod, nExactDiv; |
---|
137 | /// init with an integer |
---|
138 | number (*cfInit)(int i,const coeffs r); |
---|
139 | number (*nPar)(int i, const coeffs r); |
---|
140 | int (*nParDeg)(number n, const coeffs r); |
---|
141 | /// how complicated, (0) => 0, or positive |
---|
142 | int (*nSize)(number n, const coeffs r); |
---|
143 | /// convertion, 0 if impossible |
---|
144 | int (*n_Int)(number &n, const coeffs r); |
---|
145 | #ifdef HAVE_RINGS |
---|
146 | int (*nDivComp)(number a,number b,const coeffs r); |
---|
147 | BOOLEAN (*nIsUnit)(number a,const coeffs r); |
---|
148 | number (*nGetUnit)(number a,const coeffs r); |
---|
149 | number (*nExtGcd)(number a, number b, number *s, number *t,const coeffs r); |
---|
150 | #endif |
---|
151 | /// changes argument inline: a:= -a |
---|
152 | number (*nNeg)(number a, const coeffs r); |
---|
153 | /// return 1/a |
---|
154 | number (*nInvers)(number a, const coeffs r); |
---|
155 | /// return a copy of a |
---|
156 | number (*cfCopy)(number a, const coeffs r); |
---|
157 | number (*nRePart)(number a, const coeffs r); |
---|
158 | number (*nImPart)(number a, const coeffs r); |
---|
159 | void (*cfWrite)(number &a, const coeffs r); |
---|
160 | const char * (*nRead)(const char * s, number * a, const coeffs r); |
---|
161 | void (*nNormalize)(number &a, const coeffs r); |
---|
162 | BOOLEAN (*nGreater)(number a,number b, const coeffs r), |
---|
163 | #ifdef HAVE_RINGS |
---|
164 | (*nDivBy)(number a, number b, const coeffs r), |
---|
165 | #endif |
---|
166 | /// tests |
---|
167 | (*nEqual)(number a,number b, const coeffs r), |
---|
168 | (*nIsZero)(number a, const coeffs r), |
---|
169 | (*nIsOne)(number a, const coeffs r), |
---|
170 | (*nIsMOne)(number a, const coeffs r), |
---|
171 | (*nGreaterZero)(number a, const coeffs r); |
---|
172 | void (*nPower)(number a, int i, number * result, const coeffs r); |
---|
173 | number (*cfGetDenom)(number &n, const coeffs r); |
---|
174 | number (*cfGetNumerator)(number &n, const coeffs r); |
---|
175 | number (*nGcd)(number a, number b, const coeffs r); |
---|
176 | number (*nLcm)(number a, number b, const coeffs r); |
---|
177 | void (*cfDelete)(number * a, const coeffs r); |
---|
178 | nMapFunc (*cfSetMap)(const coeffs src, const coeffs dst); |
---|
179 | |
---|
180 | /// For extensions (writes into global string buffer) |
---|
181 | char * (*nName)(number n, const coeffs r); |
---|
182 | |
---|
183 | /// Inline: a := b |
---|
184 | void (*nInpMult)(number &a, number b, const coeffs r); |
---|
185 | number (*nInit_bigint)(number i, const coeffs r); |
---|
186 | |
---|
187 | #ifdef LDEBUG |
---|
188 | /// Test: is "a" a correct number? |
---|
189 | BOOLEAN (*nDBTest)(number a, const char *f,const int l,const coeffs r); |
---|
190 | #endif |
---|
191 | |
---|
192 | number nNULL; /* the 0 as constant */ |
---|
193 | int char_flag; |
---|
194 | int ref; |
---|
195 | n_coeffType type; |
---|
196 | short nChar; |
---|
197 | ////----------------------------------------- |
---|
198 | char** parameter; /* names of parameters, rInit */ |
---|
199 | number minpoly; /* for Q_a/Zp_a, rInit */ |
---|
200 | |
---|
201 | #ifdef HAVE_RINGS |
---|
202 | int_number ringflaga; /* Z/(ringflag^ringflagb)=Z/nrnModul*/ |
---|
203 | unsigned long ringflagb; |
---|
204 | unsigned long nr2mModul; /* Z/nr2mModul */ |
---|
205 | int_number nrnModul; |
---|
206 | #endif |
---|
207 | int ch; /* characteristic, rInit */ |
---|
208 | |
---|
209 | short float_len; /* additional char-flags, rInit */ |
---|
210 | short float_len2; /* additional char-flags, rInit */ |
---|
211 | }; |
---|
212 | |
---|
213 | /// Returns the type of coeffs domain |
---|
214 | static inline n_coeffType getCoeffType(const coeffs r) |
---|
215 | { |
---|
216 | return r->type; |
---|
217 | } |
---|
218 | |
---|
219 | #define nInternalChar(r) ((r)->ch) |
---|
220 | |
---|
221 | #endif |
---|
222 | |
---|