source: git/kernel/polys.h @ 1a20e5

spielwiese
Last change on this file since 1a20e5 was 1a20e5, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
FIX: p[_]?TakeOutComp*
  • Property mode set to 100644
File size: 14.5 KB
Line 
1#ifndef POLYS_H
2#define POLYS_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id$ */
7/*
8* ABSTRACT - compatiblity layer for all operations with polys
9*/
10
11#include <polys/monomials/ring.h>
12#include <polys/monomials/p_polys.h>
13
14extern ring currRing;
15extern void rChangeCurrRing(ring r);
16
17#include <coeffs/numbers.h>
18inline number nGcd(number a, number b, const ring r = currRing) { return n_Gcd(a, b, r->cf); }
19
20/***************************************************************
21 *
22 * Primitives for accessing and setting fields of a poly
23 * poly must be != NULL
24 *
25 ***************************************************************/
26
27// deletes old coeff before setting the new one
28#define pSetCoeff(p,n)      p_SetCoeff(p,n,currRing)
29
30// Order
31#define pGetOrder(p)        p_GetOrder(p, currRing)
32
33// Component
34#define pGetComp(p)         __p_GetComp(p, currRing)
35#define pSetComp(p,v)       p_SetComp(p,v, currRing)
36
37// Exponent
38#define pGetExp(p,i)        p_GetExp(p, i, currRing)
39#define pSetExp(p,i,v)      p_SetExp(p, i, v, currRing)
40#define pIncrExp(p,i)       p_IncrExp(p,i, currRing)
41#define pDecrExp(p,i)       p_DecrExp(p,i, currRing)
42#define pAddExp(p,i,v)      p_AddExp(p,i,v, currRing)
43#define pSubExp(p,i,v)      p_SubExp(p,i,v, currRing)
44#define pMultExp(p,i,v)     p_MultExp(p,i,v, currRing)
45#define pGetExpSum(p1, p2, i)    p_GetExpSum(p1, p2, i, currRing)
46#define pGetExpDiff(p1, p2, i)   p_GetExpDiff(p1, p2, i, currRing)
47
48
49/***************************************************************
50 *
51 * Allocation/Initalization/Deletion
52 * except for pHead, all polys must be != NULL
53 *
54 ***************************************************************/
55// allocates the space for a new monomial -- no initialization !!!
56#define pNew()          p_New(currRing)
57// allocates a new monomial and initializes everything to 0
58#define pInit()         p_Init(currRing)
59// like pInit, except that expvector is initialized to that of p,
60// p must be != NULL
61#define pLmInit(p)  p_LmInit(p, currRing)
62// returns newly allocated copy of Lm(p), coef is copied, next=NULL,
63// p might be NULL
64#define pHead(p)        p_Head(p, currRing)
65// frees the space of the monomial m, assumes m != NULL
66// coef is not freed, m is not advanced
67static inline void pLmFree(poly p)    {p_LmFree(p, currRing);}
68// like pLmFree, but advances p
69static inline void pLmFree(poly *p)   {p_LmFree(p, currRing);}
70// assumes p != NULL, deletes p, returns pNext(p)
71#define pLmFreeAndNext(p) p_LmFreeAndNext(p, currRing)
72// assume p != NULL, deletes Lm(p)->coef and Lm(p)
73#define pLmDelete(p)    p_LmDelete(p, currRing)
74// like pLmDelete, returns pNext(p)
75#define pLmDeleteAndNext(p) p_LmDeleteAndNext(p, currRing)
76
77/***************************************************************
78 *
79 * Operation on ExpVectors: assumes polys != NULL
80 *
81 ***************************************************************/
82
83#define pExpVectorCopy(d_p, s_p)    p_ExpVectorCopy(d_p, s_p, currRing)
84#define pExpVectorAdd(p1, p2)       p_ExpVectorAdd(p1, p2, currRing)
85#define pExpVectorSub(p1, p2)       p_ExpVectorSub(p1, p2, currRing)
86#define pExpVectorAddSub(p1, p2, p3)p_ExpVectorAddSub(p1, p2, p3, currRing)
87#define pExpVectorSum(pr, p1, p2)   p_ExpVectorSum(pr, p1, p2, currRing)
88#define pExpVectorDiff(pr, p1, p2)  p_ExpVectorDiff(pr, p1, p2, currRing)
89
90// Gets a copy of (resp. set) the exponent vector, where e is assumed
91// to point to (r->N +1)*sizeof(long) memory. Exponents are
92// filled in as follows: comp, e_1, .., e_n
93#define pGetExpV(p, e)      p_GetExpV(p, e, currRing)
94#define pSetExpV(p, e)      p_SetExpV(p, e, currRing)
95
96/***************************************************************
97 *
98 * Comparisons: they are all done without regarding coeffs
99 *
100 ***************************************************************/
101// returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
102#define pLmCmp(p,q)         p_LmCmp(p,q,currRing)
103// executes axtionE|actionG|actionS if p=q|p>q|p<q w.r.t monomial ordering
104// action should be a "goto ..."
105#define pLmCmpAction(p,q, actionE, actionG, actionS)  \
106  _p_LmCmpAction(p,q,currRing, actionE, actionG,actionS)
107
108#define pLmEqual(p1, p2)     p_ExpVectorEqual(p1, p2, currRing)
109
110// pCmp: args may be NULL
111// returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
112#define pCmp(p1, p2)    p_Cmp(p1, p2, currRing)
113
114
115/***************************************************************
116 *
117 * Divisiblity tests, args must be != NULL, except for
118 * pDivisbleBy
119 *
120 ***************************************************************/
121// returns TRUE, if leading monom of a divides leading monom of b
122// i.e., if there exists a expvector c > 0, s.t. b = a + c;
123#define pDivisibleBy(a, b)  p_DivisibleBy(a,b,currRing)
124// like pDivisibleBy, except that it is assumed that a!=NULL, b!=NULL
125#define pLmDivisibleBy(a,b)  p_LmDivisibleBy(a,b,currRing)
126// like pLmDivisibleBy, does not check components
127#define pLmDivisibleByNoComp(a, b) p_LmDivisibleByNoComp(a,b,currRing)
128// Divisibility tests based on Short Exponent vectors
129// sev_a     == pGetShortExpVector(a)
130// not_sev_b == ~ pGetShortExpVector(b)
131#define pLmShortDivisibleBy(a, sev_a, b, not_sev_b) \
132  p_LmShortDivisibleBy(a, sev_a, b, not_sev_b, currRing)
133#define pLmRingShortDivisibleBy(a, sev_a, b, not_sev_b) \
134  p_LmRingShortDivisibleBy(a, sev_a, b, not_sev_b, currRing)
135// returns the "Short Exponent Vector" -- used to speed up divisibility
136// tests (see polys-impl.cc )
137#define pGetShortExpVector(a)   p_GetShortExpVector(a, currRing)
138#ifdef HAVE_RINGS
139/* divisibility check over ground ring (which may contain zero divisors);
140   TRUE iff LT(f) divides LT(g), i.e., LT(f)*c*m = LT(g), for some
141   coefficient c and some monomial m;
142   does not take components into account */
143#define  pDivisibleByRingCase(f,g) p_DivisibleByRingCase(f,g,currRing)
144#endif
145
146/***************************************************************
147 *
148 * Copying/Deleteion of polys: args may be NULL
149 *
150 ***************************************************************/
151// return a copy of the poly
152#define pCopy(p) p_Copy(p, currRing)
153#define pDelete(p_ptr)  p_Delete(p_ptr, currRing)
154
155/***************************************************************
156 *
157 * Copying/Deletion of polys: args may be NULL
158 *  - p/q as arg mean a poly
159 *  - m a monomial
160 *  - n a number
161 *  - pp (resp. qq, mm, nn) means arg is constant
162 *  - p (resp, q, m, n)     means arg is destroyed
163 *
164 ***************************************************************/
165#define pNeg(p)                     p_Neg(p, currRing)
166#define ppMult_nn(p, n)             pp_Mult_nn(p, n, currRing)
167#define pMult_nn(p, n)              p_Mult_nn(p, n, currRing)
168#define ppMult_mm(p, m)             pp_Mult_mm(p, m, currRing)
169#define pMult_mm(p, m)              p_Mult_mm(p, m, currRing)
170#define pAdd(p, q)                  p_Add_q(p, q, currRing)
171#define pPower(p, q)                p_Power(p, q, currRing)
172#define pMinus_mm_Mult_qq(p, m, q)  p_Minus_mm_Mult_qq(p, m, q, currRing)
173#define pPlus_mm_Mult_qq(p, m, q)   p_Plus_mm_Mult_qq(p, m, q, currRing)
174#define pMult(p, q)                 p_Mult_q(p, q, currRing)
175#define ppMult_qq(p, q)             pp_Mult_qq(p, q, currRing)
176// p*Coeff(m) for such monomials pm of p, for which m is divisble by pm
177#define ppMult_Coeff_mm_DivSelect(p, m)   pp_Mult_Coeff_mm_DivSelect(p, m, currRing)
178/*************************************************************************
179 *
180 * Sort routines
181 *
182 *************************************************************************/
183// sorts p, assumes all monomials in p are different
184#define pSortMerger(p)          p_SortMerge(p, currRing)
185#define pSort(p)                p_SortMerge(p, currRing)
186
187// sorts p, p may have equal monomials
188#define pSortAdd(p)             p_SortAdd(p, currRing)
189
190
191// Assume: If considerd only as poly in any component of p
192// (say, monomials of other components of p are set to 0),
193// then p is already sorted correctly
194#define pSortCompCorrect(p) pSort(p)
195
196/***************************************************************
197 *
198 * Predicates on polys/Lm's
199 *
200 ***************************************************************/
201// return true if all p is eihter NULL, or if all exponents
202// of p are 0 and Comp of p is zero
203#define   pIsConstantComp(p)        p_IsConstantComp(p, currRing)
204// like above, except that Comp might be != 0
205#define   pIsConstant(p)            p_IsConstant(p,currRing)
206// return true if the Lm is a constant <>0
207#define   pIsUnit(p)            p_IsUnit(p,currRing)
208// like above, except that p must be != NULL
209#define   pLmIsConstantComp(p)      p_LmIsConstantComp(p, currRing)
210#define   pLmIsConstant(p)          p_LmIsConstant(p,currRing)
211
212// return TRUE if all monomials of p are constant
213#define   pIsConstantPoly(p)        p_IsConstantPoly(p, currRing)
214
215#define   pIsPurePower(p)   p_IsPurePower(p, currRing)
216#define   pIsUnivariate(p)  p_IsUnivariate(p, currRing)
217#define   pIsVector(p)      (pGetComp(p)>0)
218#define   pGetVariables(p,e)  p_GetVariables(p, e, currRing)
219
220/***************************************************************
221 *
222 * Old stuff
223 *
224 ***************************************************************/
225
226typedef poly*   polyset;
227// // // extern poly     ppNoether; // use currRing -> ppNoether!!!
228extern BOOLEAN  pVectorOut;
229
230/*-------------predicate on polys ----------------------*/
231#define  pHasNotCF(p1,p2)   p_HasNotCF(p1,p2,currRing)
232                                /*has no common factor ?*/
233#define  pSplit(p,r)        p_Split(p,r)
234                                /*p => IN(p), r => REST(p) */
235
236
237
238/*-----------the ordering of monomials:-------------*/
239#define pSetm(p)    p_Setm(p, currRing)
240// TODO:
241#define pSetmComp(p)   p_Setm(p, currRing)
242
243/***************************************************************
244 *
245 * Degree stuff -- see p_polys.cc for explainations
246 *
247 ***************************************************************/
248inline int pWeight(int i, const ring R = currRing){ return p_Weight(i, R); }
249inline long pDeg(poly p, const ring R = currRing) { return p_Deg(p, R); }
250 
251
252static inline long pTotaldegree(poly p) { return p_Totaldegree(p,currRing); }
253#define pWTotaldegree(p) p_WTotaldegree(p,currRing)
254#define pWDegree(p) p_WDegree(p,currRing)
255
256/*-------------operations on polynomials:------------*/
257#define   pSub(a,b) p_Sub(a,b,currRing)
258
259#define pmInit(a,b) p_mInit(a,b,currRing)
260
261// ----------------- define to enable new p_procs -----*/
262
263#define pDivide(a,b) p_Divide(a,b,currRing)
264#define pDivideM(a,b) p_DivideM(a,b,currRing)
265#define pLcm(a,b,m) p_Lcm(a,b,m,currRing)
266#define pDiff(a,b)  p_Diff(a,b,currRing)
267#define pDiffOp(a,b,m) p_DiffOp(a,b,m,currRing)
268
269#define   pMaxComp(p)   p_MaxComp(p, currRing)
270#define   pMinComp(p)   p_MinComp(p, currRing)
271
272#define   pOneComp(p)       p_OneComp(p, currRing)
273#define   pSetCompP(a,i)    p_SetCompP(a, i, currRing)
274
275// let's inline those, so that we can call them from the debugger
276inline char*   pString(poly p)    {return p_String(p, currRing, currRing);}
277inline char*   pString0(poly p)   {return p_String0(p, currRing, currRing);}
278inline void    pWrite(poly p)     {p_Write(p, currRing, currRing);}
279inline void    pWrite0(poly p)    {p_Write0(p, currRing, currRing);}
280inline void    wrp(poly p)        {p_wrp(p, currRing, currRing);}
281
282#define   pISet(i) p_ISet(i,currRing)
283#define   pNSet(n) p_NSet(n,currRing)
284
285#define   pOne()   p_One(currRing)
286
287#define   pNormalize(p) p_Normalize(p,currRing)
288#define   pSize(p)      p_Size(p,currRing)
289
290
291// homogenizes p by multiplying certain powers of the varnum-th variable
292#define  pHomogen(p,varnum) p_Homogen(p,varnum,currRing)
293
294BOOLEAN   pIsHomogeneous (poly p);
295// // replaces the maximal powers of the leading monomial of p2 in p1 by
296// // the same powers of n, utility for dehomogenization
297// #define   pDehomogen(p1,p2,n) p_Dehomgen(p1,p2,n,currRing)
298// #define   pIsHomogen(p)       p_IsHomggen(p,currRing)
299#define   pIsHomogen(p)       p_IsHomogen(p,currRing)
300
301/*BOOLEAN   pVectorHasUnitM(poly p, int * k);*/
302#define   pVectorHasUnitB(p,k) p_VectorHasUnitB(p,k,currRing)
303#define   pVectorHasUnit(p,k,l) p_VectorHasUnit(p,k,l,currRing)
304#define   pTakeOutComp1(p,k)    p_TakeOutComp1(p,k,currRing)
305
306// Splits *p into two polys: *q which consists of all monoms with
307// component == comp and *p of all other monoms *lq == pLength(*q)
308// On return all components pf *q == 0
309inline void pTakeOutComp(poly *p, long comp, poly *q, int *lq, const ring R = currRing)
310{ 
311  return p_TakeOutComp(p, comp, q, lq, R);
312}
313
314
315// This is something weird -- Don't use it, unless you know what you are doing
316inline poly      pTakeOutComp(poly * p, int k, const ring R = currRing)
317{
318  return p_TakeOutComp(p, k, R);
319}
320
321/* old spielwiese
322#define   pTakeOutComp(p,k,q,lq)    p_TakeOutComp(p,k,q,lq,currRing)
323
324// Similar to pTakeOutComp, except that only those components are
325// taken out whose Order == order
326// ASSUME: monomial ordering is Order compatible, i.e., if m1, m2 Monoms then
327//         m1 >= m2 ==> pGetOrder(m1) >= pGetOrder(m2)
328#define   pDecrOrdTakeOutComp(p,c,o,q,lq) p_DecrOrdTakeOutComp(p,c,o,q,lq,currRing)
329*/
330void      pSetPolyComp(poly p, int comp);
331#define   pDeleteComp(p,k) p_DeleteComp(p,k,currRing)
332
333inline void pNorm(poly p, const ring R = currRing){ p_Norm(p, R); }
334
335
336#define   pSubst(p,n,e) p_Subst(p,n,e,currRing)
337#define   ppJet(p,m) pp_Jet(p,m,currRing)
338#define   pJet(p,m)  p_Jet(p,m,currRing)
339#define   ppJetW(p,m,iv) pp_JetW(p,m,iv,currRing)
340#define   pJetW(p,m,iv) p_JetW(p,m,iv,currRing)
341#define   pMinDeg(p,w) p_MinDeg(p,w,currRing)
342#define   pSeries(n,p,u,w) p_Series(n,p,u,w,currRing)
343#define   pInvers(n,p,w) p_Invers(n,p,w,currRing)
344// maximum weigthed degree of all monomials of p, w is indexed from
345// 1..pVariables
346#define    pDegW(p,w) p_DegW(p,w,currRing)
347
348/*-----------type conversions ----------------------------*/
349void  pVec2Polys(poly v, polyset *p, int *len);
350#define   pVar(m) p_Var(m,currRing)
351
352/*-----------specials for spoly-computations--------------*/
353BOOLEAN pCompareChain (poly p,poly p1,poly p2,poly lcm);
354BOOLEAN pCompareChainPart (poly p,poly p1,poly p2,poly lcm);
355#define  pEqualPolys(p1,p2) p_EqualPolys(p1,p2,currRing)
356
357
358// returns the length of a polynomial (numbers of monomials)
359// respect syzComp
360static inline poly pLast(poly a, int &length) { return p_Last (a, length, currRing); }
361static inline poly pLast(poly a) { int l; return pLast(a, l); }
362
363/***************************************************************
364 *
365 * PDEBUG stuff
366 *
367 ***************************************************************/
368#ifdef PDEBUG
369#define pTest(p)        _p_Test(p, currRing, PDEBUG)
370#define pLmTest(p)      _p_LmTest(p, currRing, PDEBUG)
371
372#else // ! PDEBUG
373
374#define pTest(p)        ((void)0)
375#define pLmTest(p)      ((void)0)
376#endif
377
378#endif // POLYS_H
Note: See TracBrowser for help on using the repository browser.