source: git/kernel/ring.h @ 935bb1b

spielwiese
Last change on this file since 935bb1b was 935bb1b, checked in by Hans Schönemann <hannes@…>, 16 years ago
*hannes: rAssure_HasComp git-svn-id: file:///usr/local/Singular/svn/trunk@10548 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 11.1 KB
Line 
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.25 2008-02-01 13:46:08 Singular Exp $ */
10
11/* includes */
12#include "structs.h"
13#include "structs.h"  // we need ABS
14#include "polys-impl.h"
15
16#define SHORT_REAL_LENGTH 6 // use short reals for real <= 6 digits
17
18
19void   rChangeCurrRing(ring r);
20void   rSetHdl(idhdl h);
21ring   rInit(sleftv* pn, sleftv* rv, sleftv* ord);
22idhdl  rDefault(char *s);
23ring   rDefault(int ch, int N, char **n);
24#define rIsRingVar(A) r_IsRingVar(A,currRing)
25int    r_IsRingVar(const char *n, ring r);
26void   rWrite(ring r);
27void   rKill(idhdl h);
28void   rKill(ring r);
29ring   rCopy(ring r);
30ring rCopy0(ring r, BOOLEAN copy_qideal = TRUE, BOOLEAN copy_ordering = TRUE);
31void   rNameCheck(ring R);
32ring   rOpposite(ring r);
33ring   rEnvelope(ring r);
34
35// we must always have this test!
36inline bool rIsPluralRing(const ring r)
37{
38#ifdef HAVE_PLURAL
39  return (r != NULL) && (r->nc != NULL) && (r->nc->type != nc_error); 
40#else
41  return false;
42#endif
43}
44
45
46
47
48#ifdef PDEBUG
49#define rChangeSComps(c,s,l) rDBChangeSComps(c,s,l)
50#define rGetSComps(c,s,l) rDBGetSComps(c,s,l)
51void rDBChangeSComps(int* currComponents,
52                     long* currShiftedComponents,
53                     int length,
54                     ring r = currRing);
55void rDBGetSComps(int** currComponents,
56                  long** currShiftedComponents,
57                  int *length,
58                  ring r = currRing);
59#else
60#define rChangeSComps(c,s,l) rNChangeSComps(c,s)
61#define rGetSComps(c,s,l) rNGetSComps(c,s)
62#endif
63
64void rNChangeSComps(int* currComponents, long* currShiftedComponents, ring r = currRing);
65void rNGetSComps(int** currComponents, long** currShiftedComponents, ring r = currRing);
66
67idhdl  rFindHdl(ring r, idhdl n, idhdl w);
68idhdl rSimpleFindHdl(ring r, idhdl root, idhdl n);
69const char * rSimpleOrdStr(int ord);
70int rOrderName(char * ordername);
71char * rOrdStr(ring r);
72char * rVarStr(ring r);
73char * rCharStr(ring r);
74char * rString(ring r);
75int    rChar(ring r=currRing);
76#define rPar(r) (r->P)
77#define rVar(r) (r->N)
78char * rParStr(ring r);
79int    rIsExtension(ring r);
80int    rIsExtension();
81int    rSum(ring r1, ring r2, ring &sum);
82
83BOOLEAN rEqual(ring r1, ring r2, BOOLEAN qr = 1);
84BOOLEAN rSamePolyRep(ring r1, ring r2);
85void   rUnComplete(ring r);
86
87#define  rInternalChar(r) ((r)->ch)
88
89BOOLEAN rRing_is_Homog(ring r=currRing);
90BOOLEAN rRing_has_CompLastBlock(ring r=currRing);
91
92#ifdef HAVE_RING2TOM
93inline BOOLEAN rField_is_Ring_2toM(ring r=currRing)
94{ return (r->ringtype == 1); }
95#endif
96
97#ifdef HAVE_RINGMODN
98inline BOOLEAN rField_is_Ring_ModN(ring r=currRing)
99{ return (r->ringtype == 2); }
100
101inline BOOLEAN rField_is_Ring_PtoM(ring r=currRing)
102{ return (r->ringtype == 3); }
103#endif
104
105#ifdef HAVE_RINGZ
106inline BOOLEAN rField_is_Ring_Z(ring r=currRing)
107{ return (r->ringtype == 4); }
108#endif
109
110#ifdef HAVE_RINGS
111inline BOOLEAN rField_is_Ring(ring r=currRing)
112{ return (r->ringtype != 0); }
113
114inline BOOLEAN rField_is_Domain(ring r=currRing)
115{ return (r->ringtype == 4 || r->ringtype == 0); }
116
117inline BOOLEAN rField_has_Units(ring r=currRing)
118{ return ((r->ringtype == 1) || (r->ringtype == 2) || (r->ringtype == 3)); }
119#endif
120
121#ifdef HAVE_RINGS
122inline BOOLEAN rField_is_Zp(ring r=currRing)
123{ return (r->ringtype == 0) && (r->ch > 1) && (r->parameter==NULL); }
124
125inline BOOLEAN rField_is_Zp(ring r, int p)
126{ return (r->ringtype == 0) && (r->ch > 1 && r->ch == ABS(p) && r->parameter==NULL); }
127
128inline BOOLEAN rField_is_Q(ring r=currRing)
129{ return (r->ringtype == 0) && (r->ch == 0) && (r->parameter==NULL); }
130
131inline BOOLEAN rField_is_numeric(ring r=currRing) /* R, long R, long C */
132{ return (r->ringtype == 0) && (r->ch ==  -1); }
133
134inline BOOLEAN rField_is_R(ring r=currRing)
135{
136  if (rField_is_numeric(r) && (r->float_len <= (short)SHORT_REAL_LENGTH))
137    return (r->ringtype == 0) && (r->parameter==NULL);
138  return FALSE;
139}
140
141inline BOOLEAN rField_is_GF(ring r=currRing)
142{ return (r->ringtype == 0) && (r->ch > 1) && (r->parameter!=NULL); }
143
144inline BOOLEAN rField_is_GF(ring r, int q)
145{ return (r->ringtype == 0) && (r->ch == q); }
146
147inline BOOLEAN rField_is_Zp_a(ring r=currRing)
148{ return (r->ringtype == 0) && (r->ch < -1); }
149
150inline BOOLEAN rField_is_Zp_a(ring r, int p)
151{ return (r->ringtype == 0) && (r->ch < -1 ) && (-(r->ch) == ABS(p)); }
152
153inline BOOLEAN rField_is_Q_a(ring r=currRing)
154{ return (r->ringtype == 0) && (r->ch == 1); }
155
156inline BOOLEAN rField_is_long_R(ring r=currRing)
157{
158  if (rField_is_numeric(r) && (r->float_len >(short)SHORT_REAL_LENGTH))
159    return (r->ringtype == 0) && (r->parameter==NULL);
160  return FALSE;
161}
162
163inline BOOLEAN rField_is_long_C(ring r=currRing)
164{
165  if (rField_is_numeric(r))
166    return (r->ringtype == 0) && (r->parameter!=NULL);
167  return FALSE;
168}
169#else
170inline BOOLEAN rField_is_Zp(ring r=currRing)
171{ return (r->ch > 1) && (r->parameter==NULL); }
172
173inline BOOLEAN rField_is_Zp(ring r, int p)
174{ return (r->ch > 1 && r->ch == ABS(p) && r->parameter==NULL); }
175
176inline BOOLEAN rField_is_Q(ring r=currRing)
177{ return (r->ch == 0) && (r->parameter==NULL); }
178
179inline BOOLEAN rField_is_numeric(ring r=currRing) /* R, long R, long C */
180{ return (r->ch ==  -1); }
181
182inline BOOLEAN rField_is_R(ring r=currRing)
183{
184  if (rField_is_numeric(r) && (r->float_len <= (short)SHORT_REAL_LENGTH))
185    return (r->parameter==NULL);
186  return FALSE;
187}
188
189inline BOOLEAN rField_is_GF(ring r=currRing)
190{ return (r->ch > 1) && (r->parameter!=NULL); }
191
192inline BOOLEAN rField_is_GF(ring r, int q)
193{ return (r->ch == q); }
194
195inline BOOLEAN rField_is_Zp_a(ring r=currRing)
196{ return (r->ch < -1); }
197
198inline BOOLEAN rField_is_Zp_a(ring r, int p)
199{ return (r->ch < -1 ) && (-(r->ch) == ABS(p)); }
200
201inline BOOLEAN rField_is_Q_a(ring r=currRing)
202{ return (r->ch == 1); }
203
204inline BOOLEAN rField_is_long_R(ring r=currRing)
205{
206  if (rField_is_numeric(r) && (r->float_len >(short)SHORT_REAL_LENGTH))
207    return (r->parameter==NULL);
208  return FALSE;
209}
210
211inline BOOLEAN rField_is_long_C(ring r=currRing)
212{
213  if (rField_is_numeric(r))
214    return (r->parameter!=NULL);
215  return FALSE;
216}
217#endif
218
219inline BOOLEAN rField_has_simple_inverse(ring r=currRing)
220/* { return (r->ch>1) || (r->ch== -1); } *//* Z/p, GF(p,n), R, long_R, long_C*/
221#ifdef HAVE_RINGS
222{ return (r->ringtype > 0) || (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/2^n, Z/p, GF(p,n), R, long_R, long_C*/
223#else
224{ return (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/p, GF(p,n), R, long_R, long_C*/
225#endif
226
227inline BOOLEAN rField_has_simple_Alloc(ring r=currRing)
228{ return (rField_is_Zp(r)
229       || rField_is_GF(r)
230#ifdef HAVE_RING2TOM
231       || rField_is_Ring_2toM(r)
232#endif
233#ifdef HAVE_RINGMODN
234       || rField_is_Ring_ModN(r)
235#endif
236       || rField_is_R(r)); }
237
238/* Z/p, GF(p,n), R: nCopy, nNew, nDelete are dummies*/
239inline BOOLEAN rField_is_Extension(ring r=currRing)
240{ return (rField_is_Q_a(r)) || (rField_is_Zp_a(r)); } /* Z/p(a) and Q(a)*/
241
242n_coeffType rFieldType(ring r);
243
244// this needs to be called whenever a new ring is created: new fields
245// in ring are created (like VarOffset), unless they already exist
246// with force == 1, new fields are _always_ created (overwritten),
247// even if they exist
248BOOLEAN rComplete(ring r, int force = 0);
249// use this to free fields created by rComplete
250
251BOOLEAN nc_rComplete(ring src, ring dest);
252
253void rUnComplete(ring r);
254inline int rBlocks(ring r)
255{
256  int i=0;
257  while (r->order[i]!=0) i++;
258  return i+1;
259}
260
261// misc things
262inline char* rRingVar(short i)
263{
264  return currRing->names[i];
265}
266inline char* rRingVar(short i, ring r)
267{
268  return r->names[i];
269}
270inline BOOLEAN rShortOut(ring r)
271{
272  return (r->ShortOut);
273}
274
275// order stuff
276typedef enum rRingOrder_t
277{
278  ringorder_no = 0,
279  ringorder_a,
280  ringorder_a64, // for int64 weights
281  ringorder_c,
282  ringorder_C,
283  ringorder_M,
284  ringorder_S,
285  ringorder_s,
286  ringorder_lp,
287  ringorder_dp,
288  ringorder_rp,
289  ringorder_Dp,
290  ringorder_wp,
291  ringorder_Wp,
292  ringorder_ls,
293  ringorder_ds,
294  ringorder_Ds,
295  ringorder_ws,
296  ringorder_Ws,
297  ringorder_L,
298  // the following are only used internally
299  ringorder_aa, // for idElimination, like a, except pFDeg, pWeigths ignore it
300  ringorder_rs,
301  ringorder_unspec
302} rRingOrder_t;
303
304typedef enum rOrderType_t
305{
306  rOrderType_General = 0, // non-simple ordering as specified by currRing
307  rOrderType_CompExp,     // simple ordering, component has priority
308  rOrderType_ExpComp,     // simple ordering, exponent vector has priority
309                          // component not compatible with exp-vector order
310  rOrderType_Exp,         // simple ordering, exponent vector has priority
311                          // component is compatible with exp-vector order
312  rOrderType_Syz,         // syzygy ordering
313  rOrderType_Schreyer,    // Schreyer ordering
314  rOrderType_Syz2dpc,     // syzcomp2dpc
315  rOrderType_ExpNoComp    // simple ordering, differences in component are
316                          // not considered
317} rOrderType_t;
318
319inline BOOLEAN rIsSyzIndexRing(ring r)
320{ return r->order[0] == ringorder_s;}
321
322inline int rGetCurrSyzLimit(ring r = currRing)
323{ return (r->order[0] == ringorder_s ?
324          r->typ[0].data.syz.limit : 0);}
325
326// Ring Manipulations
327ring   rAssure_HasComp(ring r);
328ring   rCurrRingAssure_SyzComp();
329void   rSetSyzComp(int k);
330ring   rCurrRingAssure_dp_S();
331ring   rCurrRingAssure_dp_C();
332ring   rCurrRingAssure_C_dp();
333// makes sure that c/C ordering is last ordering
334ring   rCurrRingAssure_CompLastBlock();
335// makes sure that c/C ordering is last ordering and SyzIndex is first
336ring   rCurrRingAssure_SyzComp_CompLastBlock();
337
338// return the max-comonent wchich has syzIndex i
339// Assume: i<= syzIndex_limit
340int rGetMaxSyzComp(int i);
341
342BOOLEAN rHasSimpleOrder(ring r);
343// returns TRUE, if simple lp or ls ordering
344BOOLEAN rHasSimpleLexOrder(ring r);
345// return TRUE if p->exp[r->pOrdIndex] holds total degree of p */
346BOOLEAN rOrd_is_Totaldegree_Ordering(ring r =currRing);
347// return TRUE if p_SetComp requires p_Setm
348BOOLEAN rOrd_SetCompRequiresSetm(ring r);
349rOrderType_t    rGetOrderType(ring r);
350/* returns TRUE if var(i) belongs to p-block */
351BOOLEAN rIsPolyVar(int i, ring r = currRing);
352
353inline BOOLEAN rOrd_is_Comp_dp(ring r)
354{
355  return ((r->order[0] == ringorder_c || r->order[0] == ringorder_C) &&
356          r->order[1] == ringorder_dp &&
357          r->order[2] == 0);
358}
359
360#ifdef RDEBUG
361#define rTest(r)    rDBTest(r, __FILE__, __LINE__)
362extern BOOLEAN rDBTest(ring r, char* fn, int l);
363#else
364#define rTest(r)
365#endif
366
367ring rModifyRing(ring r, BOOLEAN omit_degree,
368                         BOOLEAN omit_comp,
369                         unsigned long exp_limit);
370// construct Wp, C ring
371ring rModifyRing_Wp(ring r, int* weights);
372void rModify_a_to_A(ring r);
373
374void rKillModifiedRing(ring r);
375// also frees weights
376void rKillModified_Wp_Ring(ring r);
377
378ring rModifyRing_Simple(ring r, BOOLEAN omit_degree, BOOLEAN omit_comp, unsigned long exp_limit, BOOLEAN &simple);
379void rKillModifiedRing_Simple(ring r);
380
381void rDebugPrint(ring r);
382void pDebugPrint(poly p);
383
384int64 * rGetWeightVec(ring r);
385void rSetWeightVec(ring r, int64 *wv);
386
387lists rDecompose(const ring r);
388ring rCompose(const lists  L);
389/////////////////////////////
390// Auxillary functions
391//
392
393BOOLEAN rCheckIV(intvec *iv);
394int rTypeOfMatrixOrder(intvec * order);
395void rDelete(ring r);
396
397#endif
Note: See TracBrowser for help on using the repository browser.