source: git/kernel/ring.h @ b07ba77

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