source: git/kernel/ring.h @ 7c5dd1

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