source: git/kernel/ring.h @ 171950

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