1 | #ifndef RING_H |
---|
2 | #define RING_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* |
---|
7 | * ABSTRACT - the interpreter related ring operations |
---|
8 | */ |
---|
9 | /* $Id: ring.h,v 1.62 2000-12-31 15:14:44 obachman Exp $ */ |
---|
10 | |
---|
11 | /* includes */ |
---|
12 | #include "structs.h" |
---|
13 | #include "polys-impl.h" |
---|
14 | |
---|
15 | #define SHORT_REAL_LENGTH 6 // use short reals for real <= 6 digits |
---|
16 | |
---|
17 | |
---|
18 | void rChangeCurrRing(ring r); |
---|
19 | void rSetHdl(idhdl h); |
---|
20 | ring rInit(sleftv* pn, sleftv* rv, sleftv* ord); |
---|
21 | idhdl rDefault(char *s); |
---|
22 | ring rDefault(int ch, int N, char **n); |
---|
23 | #define rIsRingVar(A) r_IsRingVar(A,currRing) |
---|
24 | int r_IsRingVar(char *n, ring r); |
---|
25 | void rWrite(ring r); |
---|
26 | void rKill(idhdl h); |
---|
27 | void rKill(ring r); |
---|
28 | ring rCopy(ring r); |
---|
29 | |
---|
30 | |
---|
31 | |
---|
32 | #ifdef PDEBUG |
---|
33 | #define rChangeSComps(c,s,l) rDBChangeSComps(c,s,l) |
---|
34 | #define rGetSComps(c,s,l) rDBGetSComps(c,s,l) |
---|
35 | void rDBChangeSComps(int* currComponents, |
---|
36 | long* currShiftedComponents, |
---|
37 | int length, |
---|
38 | ring r = currRing); |
---|
39 | void rDBGetSComps(int** currComponents, |
---|
40 | long** currShiftedComponents, |
---|
41 | int *length, |
---|
42 | ring r = currRing); |
---|
43 | #else |
---|
44 | #define rChangeSComps(c,s,l) rNChangeSComps(c,s) |
---|
45 | #define rGetSComps(c,s,l) rNGetSComps(c,s) |
---|
46 | #endif |
---|
47 | |
---|
48 | void rNChangeSComps(int* currComponents, long* currShiftedComponents, ring r = currRing); |
---|
49 | void rNGetSComps(int** currComponents, long** currShiftedComponents, ring r = currRing); |
---|
50 | |
---|
51 | idhdl rFindHdl(ring r, idhdl n, idhdl w); |
---|
52 | int rOrderName(char * ordername); |
---|
53 | char * rOrdStr(ring r); |
---|
54 | char * rVarStr(ring r); |
---|
55 | char * rCharStr(ring r); |
---|
56 | char * rString(ring r); |
---|
57 | int rChar(ring r=currRing); |
---|
58 | #define rPar(r) (r->P) |
---|
59 | char * rParStr(ring r); |
---|
60 | int rIsExtension(ring r); |
---|
61 | int rIsExtension(); |
---|
62 | int rSum(ring r1, ring r2, ring &sum); |
---|
63 | |
---|
64 | BOOLEAN rEqual(ring r1, ring r2, BOOLEAN qr = 1); |
---|
65 | void rUnComplete(ring r); |
---|
66 | |
---|
67 | #define rInternalChar(r) ((r)->ch) |
---|
68 | #ifndef ABS |
---|
69 | #define ABS(x) ((x) < 0 ? (-(x)) : (x)) |
---|
70 | #endif |
---|
71 | |
---|
72 | BOOLEAN rRing_is_Homog(ring r=currRing); |
---|
73 | BOOLEAN rRing_has_CompLastBlock(ring r=currRing); |
---|
74 | |
---|
75 | inline BOOLEAN rField_is_Zp(ring r=currRing) |
---|
76 | { return (r->ch > 1) && (r->parameter==NULL); } |
---|
77 | |
---|
78 | inline BOOLEAN rField_is_Zp(ring r, int p) |
---|
79 | { return (r->ch > 1 && r->ch == ABS(p) && r->parameter==NULL); } |
---|
80 | |
---|
81 | inline BOOLEAN rField_is_Q(ring r=currRing) |
---|
82 | { return (r->ch == 0) && (r->parameter==NULL); } |
---|
83 | |
---|
84 | inline BOOLEAN rField_is_numeric(ring r=currRing) /* R, long R, long C */ |
---|
85 | { return (r->ch == -1); } |
---|
86 | |
---|
87 | inline BOOLEAN rField_is_R(ring r=currRing) |
---|
88 | { |
---|
89 | if (rField_is_numeric(r) && (r->ch_flags <= (short)SHORT_REAL_LENGTH)) |
---|
90 | return (r->parameter==NULL); |
---|
91 | return FALSE; |
---|
92 | } |
---|
93 | |
---|
94 | inline BOOLEAN rField_is_GF(ring r=currRing) |
---|
95 | { return (r->ch > 1) && (r->parameter!=NULL); } |
---|
96 | |
---|
97 | inline BOOLEAN rField_is_GF(ring r, int q) |
---|
98 | { return (r->ch == q); } |
---|
99 | |
---|
100 | inline BOOLEAN rField_is_Zp_a(ring r=currRing) |
---|
101 | { return (r->ch < -1); } |
---|
102 | |
---|
103 | inline BOOLEAN rField_is_Zp_a(ring r, int p) |
---|
104 | { return (r->ch < -1 ) && (-(r->ch) == ABS(p)); } |
---|
105 | |
---|
106 | inline BOOLEAN rField_is_Q_a(ring r=currRing) |
---|
107 | { return (r->ch == 1); } |
---|
108 | |
---|
109 | inline BOOLEAN rField_is_long_R(ring r=currRing) |
---|
110 | { |
---|
111 | if (rField_is_numeric(r) && (r->ch_flags >(short)SHORT_REAL_LENGTH)) |
---|
112 | return (r->parameter==NULL); |
---|
113 | return FALSE; |
---|
114 | } |
---|
115 | |
---|
116 | inline BOOLEAN rField_is_long_C(ring r=currRing) |
---|
117 | { |
---|
118 | if (rField_is_numeric(r)) |
---|
119 | return (r->parameter!=NULL); |
---|
120 | return FALSE; |
---|
121 | } |
---|
122 | |
---|
123 | inline BOOLEAN rField_has_simple_inverse(ring r=currRing) |
---|
124 | /* { return (r->ch>1) || (r->ch== -1); } *//* Z/p, GF(p,n), R, long_R, long_C*/ |
---|
125 | { return (r->ch>1) || ((r->ch== -1) && (r->ch_flags < 10)); } /* Z/p, GF(p,n), R, long_R, long_C*/ |
---|
126 | |
---|
127 | inline BOOLEAN rField_has_simple_Alloc(ring r=currRing) |
---|
128 | { return (rField_is_Zp(r) || rField_is_GF(r) || rField_is_R(r)); } |
---|
129 | |
---|
130 | /* Z/p, GF(p,n), R: nCopy, nNew, nDelete are dummies*/ |
---|
131 | inline BOOLEAN rField_is_Extension(ring r=currRing) |
---|
132 | { return (rField_is_Q_a(r)) || (rField_is_Zp_a(r)); } /* Z/p(a) and Q(a)*/ |
---|
133 | |
---|
134 | n_coeffType rFieldType(ring r); |
---|
135 | |
---|
136 | // this needs to be called whenever a new ring is created: new fields |
---|
137 | // in ring are created (like VarOffset), unless they already exist |
---|
138 | // with force == 1, new fields are _always_ created (overwritten), |
---|
139 | // even if they exist |
---|
140 | BOOLEAN rComplete(ring r, int force = 0); |
---|
141 | // use this to free fields created by rComplete |
---|
142 | void rUnComplete(ring r); |
---|
143 | inline int rBlocks(ring r) |
---|
144 | { |
---|
145 | int i=0; |
---|
146 | while (r->order[i]!=0) i++; |
---|
147 | return i+1; |
---|
148 | } |
---|
149 | |
---|
150 | // misc things |
---|
151 | inline char* rRingVar(short i) |
---|
152 | { |
---|
153 | return currRing->names[i]; |
---|
154 | } |
---|
155 | inline char* rRingVar(short i, ring r) |
---|
156 | { |
---|
157 | return r->names[i]; |
---|
158 | } |
---|
159 | inline BOOLEAN rShortOut(ring r) |
---|
160 | { |
---|
161 | return (r->ShortOut); |
---|
162 | } |
---|
163 | |
---|
164 | // order stuff |
---|
165 | typedef enum rRingOrder_t |
---|
166 | { |
---|
167 | ringorder_no = 0, |
---|
168 | ringorder_a, |
---|
169 | ringorder_c, |
---|
170 | ringorder_C, |
---|
171 | ringorder_M, |
---|
172 | ringorder_S, |
---|
173 | ringorder_s, |
---|
174 | ringorder_lp, |
---|
175 | ringorder_dp, |
---|
176 | ringorder_rp, |
---|
177 | ringorder_Dp, |
---|
178 | ringorder_wp, |
---|
179 | ringorder_Wp, |
---|
180 | ringorder_ls, |
---|
181 | ringorder_ds, |
---|
182 | ringorder_Ds, |
---|
183 | ringorder_ws, |
---|
184 | ringorder_Ws, |
---|
185 | ringorder_L, |
---|
186 | // the following are only used internally |
---|
187 | ringorder_aa, // for idElimination, like a, except pFDeg, pWeigths ignore it |
---|
188 | ringorder_unspec |
---|
189 | } rRingOrder_t; |
---|
190 | |
---|
191 | typedef enum rOrderType_t |
---|
192 | { |
---|
193 | rOrderType_General = 0, // non-simple ordering as specified by currRing |
---|
194 | rOrderType_CompExp, // simple ordering, component has priority |
---|
195 | rOrderType_ExpComp, // simple ordering, exponent vector has priority |
---|
196 | // component not compatible with exp-vector order |
---|
197 | rOrderType_Exp, // simple ordering, exponent vector has priority |
---|
198 | // component is compatible with exp-vector order |
---|
199 | rOrderType_Syz, // syzygy ordering |
---|
200 | rOrderType_Schreyer, // Schreyer ordering |
---|
201 | rOrderType_Syz2dpc, // syzcomp2dpc |
---|
202 | rOrderType_ExpNoComp // simple ordering, differences in component are |
---|
203 | // not considered |
---|
204 | } rOrderType_t; |
---|
205 | |
---|
206 | inline BOOLEAN rIsSyzIndexRing(ring r) |
---|
207 | { return r->order[0] == ringorder_s;} |
---|
208 | |
---|
209 | inline int rGetCurrSyzLimit(ring r = currRing) |
---|
210 | { return (r->order[0] == ringorder_s ? |
---|
211 | r->typ[0].data.syz.limit : 0);} |
---|
212 | |
---|
213 | // Ring Manipulations |
---|
214 | ring rCurrRingAssure_SyzComp(); |
---|
215 | void rSetSyzComp(int k); |
---|
216 | ring rCurrRingAssure_dp_S(); |
---|
217 | ring rCurrRingAssure_dp_C(); |
---|
218 | ring rCurrRingAssure_C_dp(); |
---|
219 | // makes sure that c/C ordering is last ordering |
---|
220 | ring rCurrRingAssure_CompLastBlock(); |
---|
221 | // makes sure that c/C ordering is last ordering and SyzIndex is first |
---|
222 | ring rCurrRingAssure_SyzComp_CompLastBlock(); |
---|
223 | |
---|
224 | // return the max-comonent wchich has syzIndex i |
---|
225 | // Assume: i<= syzIndex_limit |
---|
226 | int rGetMaxSyzComp(int i); |
---|
227 | |
---|
228 | BOOLEAN rHasSimpleOrder(ring r); |
---|
229 | // returns TRUE, if simple lp or ls ordering |
---|
230 | BOOLEAN rHasSimpleLexOrder(ring r); |
---|
231 | // return TRUE if p->exp[r->pOrdIndex] holds total degree of p */ |
---|
232 | BOOLEAN rOrd_is_Totaldegree_Ordering(ring r =currRing); |
---|
233 | // return TRUE if p_SetComp requires p_Setm |
---|
234 | BOOLEAN rOrd_SetCompRequiresSetm(ring r); |
---|
235 | rOrderType_t rGetOrderType(ring r); |
---|
236 | /* returns TRUE if var(i) belongs to p-block */ |
---|
237 | BOOLEAN rIsPolyVar(int i, ring r = currRing); |
---|
238 | |
---|
239 | inline BOOLEAN rOrd_is_c_dp(ring r) |
---|
240 | { |
---|
241 | return (r->order[0] == ringorder_c && |
---|
242 | r->order[1] == ringorder_dp && |
---|
243 | r->order[2] == 0); |
---|
244 | } |
---|
245 | |
---|
246 | #ifdef HAVE_PLURAL |
---|
247 | inline BOOLEAN rIsPluralRing(ring r) |
---|
248 | { |
---|
249 | return r->nc != NULL; |
---|
250 | } |
---|
251 | #endif |
---|
252 | |
---|
253 | #ifdef RDEBUG |
---|
254 | #define rTest(r) rDBTest(r, __FILE__, __LINE__) |
---|
255 | extern BOOLEAN rDBTest(ring r, char* fn, int l); |
---|
256 | #else |
---|
257 | #define rTest(r) |
---|
258 | #endif |
---|
259 | |
---|
260 | ring rModifyRing(ring r, BOOLEAN omit_degree, |
---|
261 | BOOLEAN omit_comp, |
---|
262 | unsigned long exp_limit); |
---|
263 | void rKillModifiedRing(ring r); |
---|
264 | |
---|
265 | void rDebugPrint(ring r); |
---|
266 | void pDebugPrint(poly p); |
---|
267 | #endif |
---|