source: git/libpolys/polys/monomials/ring.h @ 014b65

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