source: git/kernel/ring.h @ fec53d

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