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

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