source: git/kernel/ring.h @ 454cb0

spielwiese
Last change on this file since 454cb0 was 454cb0, checked in by Hans Schönemann <hannes@…>, 15 years ago
*hannes: rIsRatGRing git-svn-id: file:///usr/local/Singular/svn/trunk@11434 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 11.8 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.39 2009-02-22 11:22:08 Singular 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(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_RING2TOM
106inline BOOLEAN rField_is_Ring_2toM(ring r=currRing)
107{ return (r->ringtype == 1); }
108#endif
109
110#ifdef HAVE_RINGMODN
111inline BOOLEAN rField_is_Ring_ModN(ring r=currRing)
112{ return (r->ringtype == 2); }
113
114inline BOOLEAN rField_is_Ring_PtoM(ring r=currRing)
115{ return (r->ringtype == 3); }
116#endif
117
118#ifdef HAVE_RINGZ
119inline BOOLEAN rField_is_Ring_Z(ring r=currRing)
120{ return (r->ringtype == 4); }
121#endif
122
123#ifdef HAVE_RINGS
124inline BOOLEAN rField_is_Ring(ring r=currRing)
125{ return (r->ringtype != 0); }
126
127inline BOOLEAN rField_is_Domain(ring r=currRing)
128{ return (r->ringtype == 4 || r->ringtype == 0); }
129
130inline BOOLEAN rField_has_Units(ring r=currRing)
131{ return ((r->ringtype == 1) || (r->ringtype == 2) || (r->ringtype == 3)); }
132#else
133#define rField_is_Ring(A) (0)
134#endif
135
136#ifdef HAVE_RINGS
137inline BOOLEAN rField_is_Zp(ring r=currRing)
138{ return (r->ringtype == 0) && (r->ch > 1) && (r->parameter==NULL); }
139
140inline BOOLEAN rField_is_Zp(ring r, int p)
141{ return (r->ringtype == 0) && (r->ch > 1 && r->ch == ABS(p) && r->parameter==NULL); }
142
143inline BOOLEAN rField_is_Q(ring r=currRing)
144{ return (r->ringtype == 0) && (r->ch == 0) && (r->parameter==NULL); }
145
146inline BOOLEAN rField_is_numeric(ring r=currRing) /* R, long R, long C */
147{ return (r->ringtype == 0) && (r->ch ==  -1); }
148
149inline BOOLEAN rField_is_R(ring r=currRing)
150{
151  if (rField_is_numeric(r) && (r->float_len <= (short)SHORT_REAL_LENGTH))
152    return (r->ringtype == 0) && (r->parameter==NULL);
153  return FALSE;
154}
155
156inline BOOLEAN rField_is_GF(ring r=currRing)
157{ return (r->ringtype == 0) && (r->ch > 1) && (r->parameter!=NULL); }
158
159inline BOOLEAN rField_is_GF(ring r, int q)
160{ return (r->ringtype == 0) && (r->ch == q); }
161
162inline BOOLEAN rField_is_Zp_a(ring r=currRing)
163{ return (r->ringtype == 0) && (r->ch < -1); }
164
165inline BOOLEAN rField_is_Zp_a(ring r, int p)
166{ return (r->ringtype == 0) && (r->ch < -1 ) && (-(r->ch) == ABS(p)); }
167
168inline BOOLEAN rField_is_Q_a(ring r=currRing)
169{ return (r->ringtype == 0) && (r->ch == 1); }
170
171inline BOOLEAN rField_is_long_R(ring r=currRing)
172{
173  if (rField_is_numeric(r) && (r->float_len >(short)SHORT_REAL_LENGTH))
174    return (r->ringtype == 0) && (r->parameter==NULL);
175  return FALSE;
176}
177
178inline BOOLEAN rField_is_long_C(ring r=currRing)
179{
180  if (rField_is_numeric(r))
181    return (r->ringtype == 0) && (r->parameter!=NULL);
182  return FALSE;
183}
184#else
185inline BOOLEAN rField_is_Zp(ring r=currRing)
186{ return (r->ch > 1) && (r->parameter==NULL); }
187
188inline BOOLEAN rField_is_Zp(ring r, int p)
189{ return (r->ch > 1 && r->ch == ABS(p) && r->parameter==NULL); }
190
191inline BOOLEAN rField_is_Q(ring r=currRing)
192{ return (r->ch == 0) && (r->parameter==NULL); }
193
194inline BOOLEAN rField_is_numeric(ring r=currRing) /* R, long R, long C */
195{ return (r->ch ==  -1); }
196
197inline BOOLEAN rField_is_R(ring r=currRing)
198{
199  if (rField_is_numeric(r) && (r->float_len <= (short)SHORT_REAL_LENGTH))
200    return (r->parameter==NULL);
201  return FALSE;
202}
203
204inline BOOLEAN rField_is_GF(ring r=currRing)
205{ return (r->ch > 1) && (r->parameter!=NULL); }
206
207inline BOOLEAN rField_is_GF(ring r, int q)
208{ return (r->ch == q); }
209
210inline BOOLEAN rField_is_Zp_a(ring r=currRing)
211{ return (r->ch < -1); }
212
213inline BOOLEAN rField_is_Zp_a(ring r, int p)
214{ return (r->ch < -1 ) && (-(r->ch) == ABS(p)); }
215
216inline BOOLEAN rField_is_Q_a(ring r=currRing)
217{ return (r->ch == 1); }
218
219inline BOOLEAN rField_is_long_R(ring r=currRing)
220{
221  if (rField_is_numeric(r) && (r->float_len >(short)SHORT_REAL_LENGTH))
222    return (r->parameter==NULL);
223  return FALSE;
224}
225
226inline BOOLEAN rField_is_long_C(ring r=currRing)
227{
228  if (rField_is_numeric(r))
229    return (r->parameter!=NULL);
230  return FALSE;
231}
232#endif
233
234inline BOOLEAN rField_has_simple_inverse(ring r=currRing)
235/* { return (r->ch>1) || (r->ch== -1); } *//* Z/p, GF(p,n), R, long_R, long_C*/
236#ifdef HAVE_RINGS
237{ 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*/
238#else
239{ return (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/p, GF(p,n), R, long_R, long_C*/
240#endif
241
242inline BOOLEAN rField_has_simple_Alloc(ring r=currRing)
243{ return (rField_is_Zp(r)
244       || rField_is_GF(r)
245#ifdef HAVE_RING2TOM
246       || rField_is_Ring_2toM(r)
247#endif
248       || rField_is_R(r)); }
249
250/* Z/p, GF(p,n), R: nCopy, nNew, nDelete are dummies*/
251inline BOOLEAN rField_is_Extension(ring r=currRing)
252{ return (rField_is_Q_a(r)) || (rField_is_Zp_a(r)); } /* Z/p(a) and Q(a)*/
253
254n_coeffType rFieldType(ring r);
255
256// this needs to be called whenever a new ring is created: new fields
257// in ring are created (like VarOffset), unless they already exist
258// with force == 1, new fields are _always_ created (overwritten),
259// even if they exist
260BOOLEAN rComplete(ring r, int force = 0);
261// use this to free fields created by rComplete
262
263inline int rBlocks(ring r)
264{
265  int i=0;
266  while (r->order[i]!=0) i++;
267  return i+1;
268}
269
270// misc things
271inline char* rRingVar(short i)
272{
273  return currRing->names[i];
274}
275inline char* rRingVar(short i, ring r)
276{
277  return r->names[i];
278}
279inline BOOLEAN rShortOut(ring r)
280{
281  return (r->ShortOut);
282}
283
284// order stuff
285typedef enum rRingOrder_t
286{
287  ringorder_no = 0,
288  ringorder_a,
289  ringorder_a64, // for int64 weights
290  ringorder_c,
291  ringorder_C,
292  ringorder_M,
293  ringorder_S,
294  ringorder_s,
295  ringorder_lp,
296  ringorder_dp,
297  ringorder_rp,
298  ringorder_Dp,
299  ringorder_wp,
300  ringorder_Wp,
301  ringorder_ls,
302  ringorder_ds,
303  ringorder_Ds,
304  ringorder_ws,
305  ringorder_Ws,
306  ringorder_L,
307  // the following are only used internally
308  ringorder_aa, // for idElimination, like a, except pFDeg, pWeigths ignore it
309  ringorder_rs,
310  ringorder_unspec
311} rRingOrder_t;
312
313typedef enum rOrderType_t
314{
315  rOrderType_General = 0, // non-simple ordering as specified by currRing
316  rOrderType_CompExp,     // simple ordering, component has priority
317  rOrderType_ExpComp,     // simple ordering, exponent vector has priority
318                          // component not compatible with exp-vector order
319  rOrderType_Exp,         // simple ordering, exponent vector has priority
320                          // component is compatible with exp-vector order
321  rOrderType_Syz,         // syzygy ordering
322  rOrderType_Schreyer,    // Schreyer ordering
323  rOrderType_Syz2dpc,     // syzcomp2dpc
324  rOrderType_ExpNoComp    // simple ordering, differences in component are
325                          // not considered
326} rOrderType_t;
327
328inline BOOLEAN rIsSyzIndexRing(ring r)
329{ return r->order[0] == ringorder_s;}
330
331inline int rGetCurrSyzLimit(ring r = currRing)
332{ return (r->order[0] == ringorder_s ?
333          r->typ[0].data.syz.limit : 0);}
334
335// Ring Manipulations
336ring   rAssure_HasComp(ring r);
337ring   rCurrRingAssure_SyzComp();
338void   rSetSyzComp(int k);
339ring   rCurrRingAssure_dp_S();
340ring   rCurrRingAssure_dp_C();
341ring   rCurrRingAssure_C_dp();
342// makes sure that c/C ordering is last ordering
343ring   rCurrRingAssure_CompLastBlock();
344// makes sure that c/C ordering is last ordering and SyzIndex is first
345ring   rCurrRingAssure_SyzComp_CompLastBlock();
346ring rAssure_TDeg(ring r, int start_var, int end_var, int &pos);
347
348// return the max-comonent wchich has syzIndex i
349// Assume: i<= syzIndex_limit
350int rGetMaxSyzComp(int i);
351
352BOOLEAN rHasSimpleOrder(const ring r);
353// returns TRUE, if simple lp or ls ordering
354BOOLEAN rHasSimpleLexOrder(const ring r);
355// return TRUE if p->exp[r->pOrdIndex] holds total degree of p */
356//inline BOOLEAN rHasGlobalOrdering(const ring r=currRing)
357//{ return (r->OrdSgn==1); }
358#define rHasGlobalOrdering(R) ((R)->OrdSgn==1)
359#define rHasGlobalOrdering_currRing() (pOrdSgn==1)
360//inline BOOLEAN rHasLocalOrMixedOrdering(const ring r=currRing)
361//{ return (r->OrdSgn==-1); }
362#define rHasLocalOrMixedOrdering(R) ((R)->OrdSgn==-1)
363#define rHasLocalOrMixedOrdering_currRing() (pOrdSgn==-1)
364BOOLEAN rOrd_is_Totaldegree_Ordering(ring r =currRing);
365// return TRUE if p_SetComp requires p_Setm
366BOOLEAN rOrd_SetCompRequiresSetm(ring r);
367rOrderType_t    rGetOrderType(ring r);
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// construct Wp, C ring
389ring rModifyRing_Wp(ring r, int* weights);
390void rModify_a_to_A(ring r);
391
392void rKillModifiedRing(ring r);
393// also frees weights
394void rKillModified_Wp_Ring(ring r);
395
396ring rModifyRing_Simple(ring r, BOOLEAN omit_degree, BOOLEAN omit_comp, unsigned long exp_limit, BOOLEAN &simple);
397void rKillModifiedRing_Simple(ring r);
398
399void rDebugPrint(ring r);
400void pDebugPrint(poly p);
401void p_DebugPrint(poly p, const ring r);
402
403int64 * rGetWeightVec(ring r);
404void rSetWeightVec(ring r, int64 *wv);
405
406lists rDecompose(const ring r);
407ring rCompose(const lists  L);
408/////////////////////////////
409// Auxillary functions
410//
411
412BOOLEAN rCheckIV(intvec *iv);
413int rTypeOfMatrixOrder(intvec * order);
414void rDelete(ring r);
415
416#endif
Note: See TracBrowser for help on using the repository browser.