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.42 1999-11-17 18:22:56 Singular 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, BOOLEAN complete = TRUE); |
---|
19 | void rSetHdl(idhdl h, BOOLEAN complete = TRUE); |
---|
20 | ring rInit(sleftv* pn, sleftv* rv, sleftv* ord); |
---|
21 | idhdl rDefault(char *s); |
---|
22 | int rIsRingVar(char *n); |
---|
23 | char * RingVar(short); |
---|
24 | void rWrite(ring r); |
---|
25 | void rKill(idhdl h); |
---|
26 | void rKill(ring r); |
---|
27 | ring rCopy(ring r); |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | #ifdef PDEBUG |
---|
32 | #define rChangeSComps(c,s,l) rDBChangeSComps(c,s,l) |
---|
33 | #define rGetSComps(c,s,l) rDBGetSComps(c,s,l) |
---|
34 | void rDBChangeSComps(int* currComponents, |
---|
35 | long* currShiftedComponents, |
---|
36 | int length, |
---|
37 | ring r = currRing); |
---|
38 | void rDBGetSComps(int** currComponents, |
---|
39 | long** currShiftedComponents, |
---|
40 | int *length, |
---|
41 | ring r = currRing); |
---|
42 | #else |
---|
43 | #define rChangeSComps(c,s,l) rNChangeSComps(c,s) |
---|
44 | #define rGetSComps(c,s,l) rNGetSComps(c,s) |
---|
45 | #endif |
---|
46 | |
---|
47 | void rNChangeSComps(int* currComponents, long* currShiftedComponents, ring r = currRing); |
---|
48 | void rNGetSComps(int** currComponents, long** currShiftedComponents, ring r = currRing); |
---|
49 | |
---|
50 | idhdl rFindHdl(ring r, idhdl n, idhdl w); |
---|
51 | void rDInit(); |
---|
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 | inline BOOLEAN rField_is_Zp(ring r=currRing) |
---|
73 | { return (r->ch > 1) && (r->parameter==NULL); } |
---|
74 | |
---|
75 | inline BOOLEAN rField_is_Zp(ring r, int p) |
---|
76 | { return (r->ch > 1 && r->ch == ABS(p) && r->parameter==NULL); } |
---|
77 | |
---|
78 | inline BOOLEAN rField_is_Q(ring r=currRing) |
---|
79 | { return (r->ch == 0) && (r->parameter==NULL); } |
---|
80 | |
---|
81 | inline BOOLEAN rField_is_numeric(ring r=currRing) /* R, long R, long C */ |
---|
82 | { return (r->ch == -1); } |
---|
83 | |
---|
84 | inline BOOLEAN rField_is_R(ring r=currRing) |
---|
85 | { |
---|
86 | if (rField_is_numeric(r) && (r->ch_flags <= (short)SHORT_REAL_LENGTH)) |
---|
87 | return (r->parameter==NULL); |
---|
88 | return FALSE; |
---|
89 | } |
---|
90 | |
---|
91 | inline BOOLEAN rField_is_GF(ring r=currRing) |
---|
92 | { return (r->ch > 1) && (r->parameter!=NULL); } |
---|
93 | |
---|
94 | inline BOOLEAN rField_is_GF(ring r, int q) |
---|
95 | { return (r->ch == q); } |
---|
96 | |
---|
97 | inline BOOLEAN rField_is_Zp_a(ring r=currRing) |
---|
98 | { return (r->ch < -1); } |
---|
99 | |
---|
100 | inline BOOLEAN rField_is_Zp_a(ring r, int p) |
---|
101 | { return (r->ch < -1 ) && (-(r->ch) == ABS(p)); } |
---|
102 | |
---|
103 | inline BOOLEAN rField_is_Q_a(ring r=currRing) |
---|
104 | { return (r->ch == 1); } |
---|
105 | |
---|
106 | inline BOOLEAN rField_is_long_R(ring r=currRing) |
---|
107 | { |
---|
108 | if (rField_is_numeric(r) && (r->ch_flags >(short)SHORT_REAL_LENGTH)) |
---|
109 | return (r->parameter==NULL); |
---|
110 | return FALSE; |
---|
111 | } |
---|
112 | |
---|
113 | inline BOOLEAN rField_is_long_C(ring r=currRing) |
---|
114 | { |
---|
115 | if (rField_is_numeric(r)) |
---|
116 | return (r->parameter!=NULL); |
---|
117 | return FALSE; |
---|
118 | } |
---|
119 | |
---|
120 | inline BOOLEAN rField_has_simple_inverse(ring r=currRing) |
---|
121 | { return (r->ch>1) || (r->ch== -1); } /* Z/p, GF(p,n), R, long_R, long_C*/ |
---|
122 | |
---|
123 | inline BOOLEAN rField_has_simple_Alloc(ring r=currRing) |
---|
124 | { return (rField_is_Zp(r) || rField_is_GF(r) || rField_is_R(r)); } |
---|
125 | |
---|
126 | /* Z/p, GF(p,n), R: nCopy, nNew, nDelete are dummies*/ |
---|
127 | |
---|
128 | inline BOOLEAN rField_is_Extension(ring r=currRing) |
---|
129 | { return (rField_is_Q_a(r)) || (rField_is_Zp_a(r)); } /* Z/p(a) and Q(a)*/ |
---|
130 | |
---|
131 | // this needs to be called whenever a new ring is created: new fields |
---|
132 | // in ring are created (like VarOffset), unless they already exist |
---|
133 | // with force == 1, new fields are _always_ created (overwritten), |
---|
134 | // even if they exist |
---|
135 | BOOLEAN rComplete(ring r, int force = 0); |
---|
136 | // use this to free fields created by rComplete |
---|
137 | void rUnComplete(ring r); |
---|
138 | inline int rBlocks(ring r) |
---|
139 | { |
---|
140 | int i=0; |
---|
141 | while (r->order[i]!=0) i++; |
---|
142 | return i+1; |
---|
143 | } |
---|
144 | |
---|
145 | typedef enum rRingOrder_t |
---|
146 | { |
---|
147 | ringorder_no = 0, |
---|
148 | ringorder_a, |
---|
149 | ringorder_c, |
---|
150 | ringorder_C, |
---|
151 | ringorder_M, |
---|
152 | ringorder_S, |
---|
153 | ringorder_s, |
---|
154 | ringorder_lp, |
---|
155 | ringorder_dp, |
---|
156 | ringorder_Dp, |
---|
157 | ringorder_wp, |
---|
158 | ringorder_Wp, |
---|
159 | ringorder_ls, |
---|
160 | ringorder_ds, |
---|
161 | ringorder_Ds, |
---|
162 | ringorder_ws, |
---|
163 | ringorder_Ws, |
---|
164 | #ifdef HAVE_SHIFTED_EXPONENTS |
---|
165 | ringorder_L, |
---|
166 | #endif |
---|
167 | ringorder_unspec |
---|
168 | } rRingOrder_t; |
---|
169 | |
---|
170 | typedef enum rOrderType_t |
---|
171 | { |
---|
172 | rOrderType_General = 0, // non-simple ordering as specified by currRing |
---|
173 | rOrderType_CompExp, // simple ordering, component has priority |
---|
174 | rOrderType_ExpComp, // simple ordering, exponent vector has priority |
---|
175 | // component not compatible with exp-vector order |
---|
176 | rOrderType_Exp, // simple ordering, exponent vector has priority |
---|
177 | // component is compatible with exp-vector order |
---|
178 | rOrderType_Syz, // syzygy ordering |
---|
179 | rOrderType_Schreyer, // Schreyer ordering |
---|
180 | rOrderType_Syz2dpc, // syzcomp2dpc |
---|
181 | rOrderType_ExpNoComp // simple ordering, differences in component are |
---|
182 | // not considered |
---|
183 | } rOrderType_t; |
---|
184 | |
---|
185 | inline BOOLEAN rIsSyzIndexRing(ring r) |
---|
186 | { return r->order[0] == ringorder_s;} |
---|
187 | |
---|
188 | inline int rGetCurrSyzLimit() |
---|
189 | { return (currRing->order[0] == ringorder_s ? |
---|
190 | currRing->typ[0].data.syz.limit : 0);} |
---|
191 | |
---|
192 | // Ring Manipulations |
---|
193 | ring rCurrRingAssureSyzComp(); |
---|
194 | void rSetSyzComp(int k); |
---|
195 | ring rCurrRingAssure_dp_S(); |
---|
196 | ring rCurrRingAssure_dp_C(); |
---|
197 | ring rCurrRingAssure_C_dp(); |
---|
198 | // return the max-comonent wchich has syzIndex i |
---|
199 | // Assume: i<= syzIndex_limit |
---|
200 | int rGetMaxSyzComp(int i); |
---|
201 | |
---|
202 | BOOLEAN rHasSimpleOrder(ring r); |
---|
203 | // returns TRUE, if simple lp or ls ordering |
---|
204 | BOOLEAN rHasSimpleLexOrder(ring r); |
---|
205 | rOrderType_t rGetOrderType(ring r); |
---|
206 | BOOLEAN rIsPolyVar(int i); /* returns TRUE if var(i) belongs to p-block */ |
---|
207 | |
---|
208 | void rOptimizeOrder(ring r); |
---|
209 | |
---|
210 | #ifdef RDEBUG |
---|
211 | #define rTest(r) rDBTest(r, __FILE__, __LINE__) |
---|
212 | extern BOOLEAN rDBTest(ring r, char* fn, int l); |
---|
213 | #else |
---|
214 | #define rTest(r) |
---|
215 | #endif |
---|
216 | |
---|
217 | void rDebugPrint(ring r); |
---|
218 | void pDebugPrint(poly p); |
---|
219 | |
---|
220 | #endif |
---|
221 | |
---|