source: git/kernel/ring.h @ 9be65c

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