source: git/kernel/ring.h @ 206e158

spielwiese
Last change on this file since 206e158 was 206e158, checked in by Oliver Wienand <wienand@…>, 17 years ago
structs.h, numbers.*, rmodulo*: new method nComp nIntDiv(0, a) = module / a in rmodulo ringgb.*: adapted for more generic rings ring.h: rField_is_Domain new k*: adapted for gbs over Z/m git-svn-id: file:///usr/local/Singular/svn/trunk@10034 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 10.7 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.20 2007-05-11 10:48:05 wienand 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);
84void   rUnComplete(ring r);
85
86#define  rInternalChar(r) ((r)->ch)
87
88BOOLEAN rRing_is_Homog(ring r=currRing);
89BOOLEAN rRing_has_CompLastBlock(ring r=currRing);
90
91#ifdef HAVE_RING2TOM
92inline BOOLEAN rField_is_Ring_2toM(ring r=currRing)
93{ return (r->ringtype == 1); }
94#endif
95
96#ifdef HAVE_RINGMODN
97inline BOOLEAN rField_is_Ring_ModN(ring r=currRing)
98{ return (r->ringtype == 2); }
99#endif
100
101#ifdef HAVE_RINGS
102inline BOOLEAN rField_is_Ring(ring r=currRing)
103{ return (r->ringtype != 0); }
104
105inline BOOLEAN rField_is_Domain(ring r=currRing)
106{ return (r->ringtype < 0); }
107#endif
108
109#ifdef HAVE_RINGS
110inline BOOLEAN rField_is_Zp(ring r=currRing)
111{ return (r->ringtype == 0) && (r->ch > 1) && (r->parameter==NULL); }
112
113inline BOOLEAN rField_is_Zp(ring r, int p)
114{ return (r->ringtype == 0) && (r->ch > 1 && r->ch == ABS(p) && r->parameter==NULL); }
115
116inline BOOLEAN rField_is_Q(ring r=currRing)
117{ return (r->ringtype == 0) && (r->ch == 0) && (r->parameter==NULL); }
118
119inline BOOLEAN rField_is_numeric(ring r=currRing) /* R, long R, long C */
120{ return (r->ringtype == 0) && (r->ch ==  -1); }
121
122inline BOOLEAN rField_is_R(ring r=currRing)
123{
124  if (rField_is_numeric(r) && (r->float_len <= (short)SHORT_REAL_LENGTH))
125    return (r->ringtype == 0) && (r->parameter==NULL);
126  return FALSE;
127}
128
129inline BOOLEAN rField_is_GF(ring r=currRing)
130{ return (r->ringtype == 0) && (r->ch > 1) && (r->parameter!=NULL); }
131
132inline BOOLEAN rField_is_GF(ring r, int q)
133{ return (r->ringtype == 0) && (r->ch == q); }
134
135inline BOOLEAN rField_is_Zp_a(ring r=currRing)
136{ return (r->ringtype == 0) && (r->ch < -1); }
137
138inline BOOLEAN rField_is_Zp_a(ring r, int p)
139{ return (r->ringtype == 0) && (r->ch < -1 ) && (-(r->ch) == ABS(p)); }
140
141inline BOOLEAN rField_is_Q_a(ring r=currRing)
142{ return (r->ringtype == 0) && (r->ch == 1); }
143
144inline BOOLEAN rField_is_long_R(ring r=currRing)
145{
146  if (rField_is_numeric(r) && (r->float_len >(short)SHORT_REAL_LENGTH))
147    return (r->ringtype == 0) && (r->parameter==NULL);
148  return FALSE;
149}
150
151inline BOOLEAN rField_is_long_C(ring r=currRing)
152{
153  if (rField_is_numeric(r))
154    return (r->ringtype == 0) && (r->parameter!=NULL);
155  return FALSE;
156}
157#else
158inline BOOLEAN rField_is_Zp(ring r=currRing)
159{ return (r->ch > 1) && (r->parameter==NULL); }
160
161inline BOOLEAN rField_is_Zp(ring r, int p)
162{ return (r->ch > 1 && r->ch == ABS(p) && r->parameter==NULL); }
163
164inline BOOLEAN rField_is_Q(ring r=currRing)
165{ return (r->ch == 0) && (r->parameter==NULL); }
166
167inline BOOLEAN rField_is_numeric(ring r=currRing) /* R, long R, long C */
168{ return (r->ch ==  -1); }
169
170inline BOOLEAN rField_is_R(ring r=currRing)
171{
172  if (rField_is_numeric(r) && (r->float_len <= (short)SHORT_REAL_LENGTH))
173    return (r->parameter==NULL);
174  return FALSE;
175}
176
177inline BOOLEAN rField_is_GF(ring r=currRing)
178{ return (r->ch > 1) && (r->parameter!=NULL); }
179
180inline BOOLEAN rField_is_GF(ring r, int q)
181{ return (r->ch == q); }
182
183inline BOOLEAN rField_is_Zp_a(ring r=currRing)
184{ return (r->ch < -1); }
185
186inline BOOLEAN rField_is_Zp_a(ring r, int p)
187{ return (r->ch < -1 ) && (-(r->ch) == ABS(p)); }
188
189inline BOOLEAN rField_is_Q_a(ring r=currRing)
190{ return (r->ch == 1); }
191
192inline BOOLEAN rField_is_long_R(ring r=currRing)
193{
194  if (rField_is_numeric(r) && (r->float_len >(short)SHORT_REAL_LENGTH))
195    return (r->parameter==NULL);
196  return FALSE;
197}
198
199inline BOOLEAN rField_is_long_C(ring r=currRing)
200{
201  if (rField_is_numeric(r))
202    return (r->parameter!=NULL);
203  return FALSE;
204}
205#endif
206
207inline BOOLEAN rField_has_simple_inverse(ring r=currRing)
208/* { return (r->ch>1) || (r->ch== -1); } *//* Z/p, GF(p,n), R, long_R, long_C*/
209#ifdef HAVE_RINGS
210{ 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*/
211#else
212{ return (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/p, GF(p,n), R, long_R, long_C*/
213#endif
214
215inline BOOLEAN rField_has_simple_Alloc(ring r=currRing)
216{ return (rField_is_Zp(r)
217       || rField_is_GF(r)
218#ifdef HAVE_RING2TOM
219       || rField_is_Ring_2toM(r)
220#endif
221#ifdef HAVE_RINGMODN
222       || rField_is_Ring_ModN(r)
223#endif
224       || rField_is_R(r)); }
225
226/* Z/p, GF(p,n), R: nCopy, nNew, nDelete are dummies*/
227inline BOOLEAN rField_is_Extension(ring r=currRing)
228{ return (rField_is_Q_a(r)) || (rField_is_Zp_a(r)); } /* Z/p(a) and Q(a)*/
229
230n_coeffType rFieldType(ring r);
231
232// this needs to be called whenever a new ring is created: new fields
233// in ring are created (like VarOffset), unless they already exist
234// with force == 1, new fields are _always_ created (overwritten),
235// even if they exist
236BOOLEAN rComplete(ring r, int force = 0);
237// use this to free fields created by rComplete
238
239BOOLEAN nc_rComplete(ring src, ring dest);
240
241void rUnComplete(ring r);
242inline int rBlocks(ring r)
243{
244  int i=0;
245  while (r->order[i]!=0) i++;
246  return i+1;
247}
248
249// misc things
250inline char* rRingVar(short i)
251{
252  return currRing->names[i];
253}
254inline char* rRingVar(short i, ring r)
255{
256  return r->names[i];
257}
258inline BOOLEAN rShortOut(ring r)
259{
260  return (r->ShortOut);
261}
262
263// order stuff
264typedef enum rRingOrder_t
265{
266  ringorder_no = 0,
267  ringorder_a,
268  ringorder_a64, // for int64 weights
269  ringorder_c,
270  ringorder_C,
271  ringorder_M,
272  ringorder_S,
273  ringorder_s,
274  ringorder_lp,
275  ringorder_dp,
276  ringorder_rp,
277  ringorder_Dp,
278  ringorder_wp,
279  ringorder_Wp,
280  ringorder_ls,
281  ringorder_ds,
282  ringorder_Ds,
283  ringorder_ws,
284  ringorder_Ws,
285  ringorder_L,
286  // the following are only used internally
287  ringorder_aa, // for idElimination, like a, except pFDeg, pWeigths ignore it
288  ringorder_unspec
289} rRingOrder_t;
290
291typedef enum rOrderType_t
292{
293  rOrderType_General = 0, // non-simple ordering as specified by currRing
294  rOrderType_CompExp,     // simple ordering, component has priority
295  rOrderType_ExpComp,     // simple ordering, exponent vector has priority
296                          // component not compatible with exp-vector order
297  rOrderType_Exp,         // simple ordering, exponent vector has priority
298                          // component is compatible with exp-vector order
299  rOrderType_Syz,         // syzygy ordering
300  rOrderType_Schreyer,    // Schreyer ordering
301  rOrderType_Syz2dpc,     // syzcomp2dpc
302  rOrderType_ExpNoComp    // simple ordering, differences in component are
303                          // not considered
304} rOrderType_t;
305
306inline BOOLEAN rIsSyzIndexRing(ring r)
307{ return r->order[0] == ringorder_s;}
308
309inline int rGetCurrSyzLimit(ring r = currRing)
310{ return (r->order[0] == ringorder_s ?
311          r->typ[0].data.syz.limit : 0);}
312
313// Ring Manipulations
314ring   rCurrRingAssure_SyzComp();
315void   rSetSyzComp(int k);
316ring   rCurrRingAssure_dp_S();
317ring   rCurrRingAssure_dp_C();
318ring   rCurrRingAssure_C_dp();
319// makes sure that c/C ordering is last ordering
320ring   rCurrRingAssure_CompLastBlock();
321// makes sure that c/C ordering is last ordering and SyzIndex is first
322ring   rCurrRingAssure_SyzComp_CompLastBlock();
323
324// return the max-comonent wchich has syzIndex i
325// Assume: i<= syzIndex_limit
326int rGetMaxSyzComp(int i);
327
328BOOLEAN rHasSimpleOrder(ring r);
329// returns TRUE, if simple lp or ls ordering
330BOOLEAN rHasSimpleLexOrder(ring r);
331// return TRUE if p->exp[r->pOrdIndex] holds total degree of p */
332BOOLEAN rOrd_is_Totaldegree_Ordering(ring r =currRing);
333// return TRUE if p_SetComp requires p_Setm
334BOOLEAN rOrd_SetCompRequiresSetm(ring r);
335rOrderType_t    rGetOrderType(ring r);
336/* returns TRUE if var(i) belongs to p-block */
337BOOLEAN rIsPolyVar(int i, ring r = currRing);
338
339inline BOOLEAN rOrd_is_Comp_dp(ring r)
340{
341  return ((r->order[0] == ringorder_c || r->order[0] == ringorder_C) &&
342          r->order[1] == ringorder_dp &&
343          r->order[2] == 0);
344}
345
346#ifdef RDEBUG
347#define rTest(r)    rDBTest(r, __FILE__, __LINE__)
348extern BOOLEAN rDBTest(ring r, char* fn, int l);
349#else
350#define rTest(r)
351#endif
352
353ring rModifyRing(ring r, BOOLEAN omit_degree,
354                         BOOLEAN omit_comp,
355                         unsigned long exp_limit);
356// construct Wp, C ring
357ring rModifyRing_Wp(ring r, int* weights);
358void rModify_a_to_A(ring r);
359
360void rKillModifiedRing(ring r);
361// also frees weights
362void rKillModified_Wp_Ring(ring r);
363
364ring rModifyRing_Simple(ring r, BOOLEAN omit_degree, BOOLEAN omit_comp, unsigned long exp_limit, BOOLEAN &simple);
365void rKillModifiedRing_Simple(ring r);
366
367void rDebugPrint(ring r);
368void pDebugPrint(poly p);
369
370int64 * rGetWeightVec(ring r);
371void rSetWeightVec(ring r, int64 *wv);
372
373lists rDecompose(const ring r);
374ring rCompose(const lists  L);
375/////////////////////////////
376// Auxillary functions
377//
378
379BOOLEAN rCheckIV(intvec *iv);
380int rTypeOfMatrixOrder(intvec * order);
381void rDelete(ring r);
382
383#endif
Note: See TracBrowser for help on using the repository browser.